7.3. Preparing Virtual Kernel File Systems

Various file systems exported by the kernel are used to communicate to and from the kernel itself. These file systems are virtual in that no disk space is used for them. The content of the file systems resides in memory.

Begin by creating directories onto which the file systems will be mounted:

mkdir -pv $LFS/{dev,proc,sys,run}

7.3.1. Mounting and Populating /dev

During a normal boot, the kernel automatically mounts the devtmpfs filesystem on the /dev directory, and allow the devices to be created dynamically on that virtual filesystem as they are detected or accessed. Device creation is generally done during the boot process by the kernel and Udev. Since this new system does not yet have Udev and has not yet been booted, it is necessary to mount and populate /dev manually. This is accomplished by bind mounting the host system's /dev directory. A bind mount is a special type of mount that allows you to create a mirror of a directory or mount point to some other location. Use the following command to achieve this:

mount -v --bind /dev $LFS/dev

7.3.2. Mounting Virtual Kernel File Systems

Now mount the remaining virtual kernel filesystems:

mount -v --bind /dev/pts $LFS/dev/pts
mount -vt proc proc $LFS/proc
mount -vt sysfs sysfs $LFS/sys
mount -vt tmpfs tmpfs $LFS/run

In some host systems, /dev/shm is a symbolic link to /run/shm. The /run tmpfs was mounted above so in this case only a directory needs to be created.

if [ -h $LFS/dev/shm ]; then
  mkdir -pv $LFS/$(readlink $LFS/dev/shm)
fi