7.2. Preparing Virtual Kernel File Systems

Applications running in userspace utilize various file systems created by the kernel to communicate with the kernel itself. These file systems are virtual: no disk space is used for them. The content of these file systems resides in memory.

Begin by creating the directories on which these virtual 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 file systems:

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

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

Now with the proc filesystem 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). And, create another symlink recommended by the kernel documentation. These are 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
ln -sv  /proc/self/fd   /dev