IIRC we switched from separate devpts to bind mount, and matched the UID
of tester with the host UID owning the TTY, to satisify the Bash test
suite. But now we are always using UID 101 for tester and expect to
spawn a PTY for Bash test suite (so when building LFS in a TTY owned by
the root user of the host tester won't be UID 0). Thus we can switch
back to a separate devpts mount which is cleaner and safer.
And we are already using a separate devpts mount in Chapter 11.
$(realpath /dev/shm) will return the absolute path of the target of
/dev/shm, thus the command will work for both absolute symlink and
relative symlink.
When /dev/shm is a symlink we need to create its target or some tests
will fail and Python 3 will be misconfigured. We wrote it as:
mkdir -pv $LFS/$(readlink $LFS/dev/shm)
But if $LFS/dev/shm is a relative symlink (say ../run/shm), we end up:
mkdir -pv /mnt/lfs/../run/shm
This command will create /mnt/run/shm, not $LFS/mnt/shm as we expected.
Twist it a little to make it work for both absolute symlinks and
relative symlinks.
"Duplicated copy" is wrong IMO. If you copy A to B, B won't be changed
when you modify A. But if you bind mount A to B, B will reflect any
change made to A.
Again copy something from mount(2):
A bind mount makes a file or a directory subtree visible at another
point within the single directory hierarchy.
Things are a little tricky:
1. If the host is "modern" (any desktop distro after 2013), the kernel
supports devtmpfs and the host udev will do adjustments to the
devtmpfs. All instances of devtmpfs shares the same content so we'll
see the work of both the kernel and the host udev in chroot.
2. If the host is old but the kernel supports devtmpfs (i. e. the host
is not using devtmpfs for its /dev), when we mount devtmpfs on
$LFS/dev we'll see the work of the kernel in chroot, but not the work
of udev. **Building LFS does not need any work of udev.**
3. If the host is very old and the kernel does not support devtmpfs at
all, we can't mount devtmpfs.
Mounting a devtmpfs will work for 1 and 2, while bind mounting will work
for 1, 2, and 3. So we use bind mounting here.
I don't want to squash all these details into the book, so just remove
the false statement here.
If you are using a "modern" distro (with devtmpfs and a modern udev
implementation), a bind mounting is actually not needed because you can
mount devtmpfs anyway. The only reason for bind mounting is to be
compatible with old host distros where /dev is a directory containing
many static device nodes, or is a tmpfs (not same as devtmpfs) popluated
by bootscript or an old udev (modern udev implementations, including
eudev and systemd-udev used by LFS, strictly requires a devtmpfs on
/dev).
So update the explanation to match the status quo.
Chroot command itself does not require kernel VFS mounted. You can mount
/proc, /sys, and /run after entering chroot with
"mount -v -t proc proc /proc" etc. For /dev, if the host kernel
supports devtmpfs, you can also mount /dev in chroot with
"mount -v -t devtmpfs devtmpfs /dev". Even if the host does not support
devtmpfs, it's still possible to mount /proc in chroot, then use
"mount --bind /proc/1/dev /dev".
It's just LFS editors decide to mount them before chroot. So reword
some untrue assertions.
Some host create /dev/shm as a tmpfs. Some have is as
a symlink to a location in another directory. This
change handles both cases.
The change to the sysV bootscripts now creates /dev/shm
as a separate tmpfs from /run. This makes LFS sysV and
systemd versions treat /dev/shm the same.
This is to match the "new" way of device handling with devtmpfs (already
widely used in recent ten years).
In a normal booting process, the kernel mounts devtmpfs at very early
stage. So the static nodes won't be used at all. The only situation
where the kernel can't mount devtmpfs is "/dev is missing", but it means
those two static nodes can't exist anyway, and a normal LFS system
(without initramfs) won't boot in such a bad situation.
Removing static /dev/console and /dev/null may cause trouble for those
people or scripts chroot into LFS tree without mounting devtmpfs. But
entering a chroot with only console and null in /dev is already
problematic. For a reference, If a systemd service is started with
PrivateDevices=true, systemd will create 18 nodes and symlinks to form a
"minimal" /dev.