7.2. 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 /{proc,sys,run}

7.2.1. Mounting Virtual Kernel File Systems

The kernel has already mounted devtmpfs. Mount the remaining virtual kernel filesystems:

mkdir -pv /dev/{pts,shm}
mount -vt devpts /dev/pts /dev/pts -o gid=5,mode=620
mount -vt proc  proc  /proc
mount -vt sysfs sysfs /sys
mount -vt tmpfs tmpfs /run
mount -vt tmpfs tmpfs /dev/shm

The meaning of the mount options for devpts:

gid=5

This ensures that all devpts-created device nodes are owned by group ID 5. This is the ID we will use later on for the tty group. We use the group ID instead of a name, since the host system might use a different ID for its tty group.

mode=0620

This ensures that all devpts-created device nodes have mode 0620 (user readable and writable, group writable). Together with the option above, this ensures that devpts will create device nodes that meet the requirements of grantpt(), meaning the Glibc pt_chown helper binary (which is not installed by default) is not necessary.

7.2.2. Adjusting devtmpfs and Setting Controlling Terminal

Now proc filesystem is mounted, we can replace the device nodes for standard I/O streams with symlinks to pseudo files in /proc/self/fd (which are symlinks to the files connected to the standard I/O streams for the current process). This is necessary for I/O redirection in the building system of some packages to function properly:

ln -sfv /proc/self/fd/0 /dev/stdin
ln -sfv /proc/self/fd/1 /dev/stdout
ln -sfv /proc/self/fd/2 /dev/stderr