7.3. Create virtual filesystem link targets
Create target-side directories and top-level links for runtime virtual filesystems, then mount them before entering chroot.
Goal: create
$LBI_ROOT/system/devices, $LBI_ROOT/system/processes, $LBI_ROOT/system/system, and $LBI_ROOT/system/run, link top-level paths to them, and mount the runtime virtual filesystems.
This step prepares mount targets for runtime virtual filesystems in the custom tree layout before entering chroot.
All commands in this section should be run as root.
Create the target directories
mkdir -p "$LBI_ROOT/system/devices"
mkdir -p "$LBI_ROOT/system/processes"
mkdir -p "$LBI_ROOT/system/system"
mkdir -p "$LBI_ROOT/system/run"
mkdir -p "$LBI_ROOT/system/devices/pts"
mkdir -p "$LBI_ROOT/system/devices/shm"
Create top-level compatibility links
rm -f "$LBI_ROOT/dev"
rm -f "$LBI_ROOT/proc"
rm -f "$LBI_ROOT/sys"
rm -f "$LBI_ROOT/run"
ln -sf system/devices "$LBI_ROOT/dev"
ln -sf system/processes "$LBI_ROOT/proc"
ln -sf system/system "$LBI_ROOT/sys"
ln -sf system/run "$LBI_ROOT/run"
Mount virtual filesystems
mount -o bind /dev "$LBI_ROOT/dev"
mount -t devpts devpts "$LBI_ROOT/dev/pts" -o gid=5,mode=0620
mount -t proc proc "$LBI_ROOT/proc"
mount -t sysfs sysfs "$LBI_ROOT/sys"
mount -t tmpfs tmpfs "$LBI_ROOT/run"
if [ -h "$LBI_ROOT/dev/shm" ]; then
install -d -m 1777 "$LBI_ROOT/system/run/shm"
else
mount -t tmpfs -o nosuid,nodev tmpfs "$LBI_ROOT/dev/shm"
fi
POSIX sh helper script
A ready-to-run helper script is provided here:
Run it as root with LBI_ROOT exported in your environment.
Quick verification
ls -ld "$LBI_ROOT/dev" "$LBI_ROOT/proc" "$LBI_ROOT/sys" "$LBI_ROOT/run"
Command Explanations
mkdir -p "$LBI_ROOT/system/...": Creates the target-side mount points used for device, process, sysfs, runtime, pts, and shared-memory filesystems.rm -f "$LBI_ROOT/dev"and the matching commands: Remove stale top-level placeholders before recreating the compatibility links.ln -sf system/devices "$LBI_ROOT/dev": Maps the conventional/devpath to the book's/system/deviceslayout.ln -sf system/processes,system/system, andsystem/run: Provide/proc,/sys, and/runcompatibility paths for tools that expect standard Linux locations.mount -o bind /dev "$LBI_ROOT/dev": Makes the host device tree visible inside the target tree for chroot work.mount -t devpts,mount -t proc,mount -t sysfs, andmount -t tmpfs: Mount the virtual filesystems needed by shells, process tools, kernel interfaces, and runtime state.install -d -m 1777 "$LBI_ROOT/system/run/shm": Creates a world-writable sticky shared-memory directory when/dev/shmis a symlink.ls -ld ...: Verifies that the top-level compatibility paths resolve to the intended targets.