From 16cd09633edb80d587548ce3cd2296b4b803f210 Mon Sep 17 00:00:00 2001 From: Bruce Dubbs Date: Tue, 20 Sep 2022 12:20:58 -0500 Subject: [PATCH] Adjust instructions for /dev/shm when creating virtual filesystems. 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. --- bootscripts/ChangeLog | 3 +++ bootscripts/lfs/init.d/mountvirtfs | 8 +++++--- chapter01/changelog.xml | 11 +++++++++++ chapter07/cleanup.xml | 3 ++- chapter07/kernfs.xml | 7 +++++++ chapter10/fstab.xml | 1 + chapter11/afterlfs.xml | 7 ++++++- packages.ent | 2 +- 8 files changed, 36 insertions(+), 6 deletions(-) diff --git a/bootscripts/ChangeLog b/bootscripts/ChangeLog index c1b590568..1fca16a65 100644 --- a/bootscripts/ChangeLog +++ b/bootscripts/ChangeLog @@ -1,3 +1,6 @@ +2022-09-30 Bruce Dubbs + * Mount /dev/shm as a tmpfs. + 2022-07-23 Thomas Trepl * Mark an raid array clean when root (/) has been remounted r/o when system goes down. Otherwise, array does remain diff --git a/bootscripts/lfs/init.d/mountvirtfs b/bootscripts/lfs/init.d/mountvirtfs index 639634377..21d98a05d 100644 --- a/bootscripts/lfs/init.d/mountvirtfs +++ b/bootscripts/lfs/init.d/mountvirtfs @@ -38,8 +38,8 @@ case "${1}" in mount /run || failed=1 fi - mkdir -p /run/lock /run/shm - chmod 1777 /run/shm /run/lock + mkdir -p /run/lock + chmod 1777 /run/lock log_info_msg "Mounting virtual file systems: ${INFO}/run" @@ -58,7 +58,9 @@ case "${1}" in mount -o mode=0755,nosuid /dev || failed=1 fi - ln -sfn /run/shm /dev/shm + mkdir -p /dev/shm + log_info_msg2 " ${INFO}/dev/shm" + mount -o nosuid,nodev /dev/shm || failed=1 (exit ${failed}) evaluate_retval diff --git a/chapter01/changelog.xml b/chapter01/changelog.xml index 3b0651f16..c3569d0a6 100644 --- a/chapter01/changelog.xml +++ b/chapter01/changelog.xml @@ -40,6 +40,17 @@ appropriate for the entry or if needed the entire day's listitem. --> + + 2022-09-20 + + + [bdubbs] - Adappt instructions depending on + host setup of /dev/shm when creating virtual filesystems + for chroot. + + + + 2022-09-15 diff --git a/chapter07/cleanup.xml b/chapter07/cleanup.xml index 7946d84eb..d5396208c 100644 --- a/chapter07/cleanup.xml +++ b/chapter07/cleanup.xml @@ -95,7 +95,8 @@ Before making a backup, unmount the virtual file systems: -umount $LFS/dev/pts +[ mountpoint -q $LFS/dev/shm ] && umount $LFS/dev/shm +umount $LFS/dev/pts umount $LFS/{sys,proc,run,dev} diff --git a/chapter07/kernfs.xml b/chapter07/kernfs.xml index 64db54c24..c9721113d 100644 --- a/chapter07/kernfs.xml +++ b/chapter07/kernfs.xml @@ -89,8 +89,15 @@ mount -vt tmpfs tmpfs $LFS/run The /run tmpfs was mounted above so in this case only a directory needs to be created. + In other cases /dev/shm is a mountpoint + for a tmpfs. In that case the mount of /dev above will only create + /dev/shm in the chroot environment as a directory. In this situation + we explicitly mount a tmpfs, + if [ -h $LFS/dev/shm ]; then mkdir -pv $LFS/$(readlink $LFS/dev/shm) +else + mount -t tmpfs -o nosuid,nodev tmpfs $LFS/dev/shm fi diff --git a/chapter10/fstab.xml b/chapter10/fstab.xml index ebfae3aaf..f78b234db 100644 --- a/chapter10/fstab.xml +++ b/chapter10/fstab.xml @@ -32,6 +32,7 @@ sysfs /sys sysfs nosuid,noexec,nodev 0 0 devpts /dev/pts devpts gid=5,mode=620 0 0 tmpfs /run tmpfs defaults 0 0 devtmpfs /dev devtmpfs mode=0755,nosuid 0 0 +tmpfs /dev/shm tmpfs nosuid,nodev 0 0 # End /etc/fstab EOF diff --git a/chapter11/afterlfs.xml b/chapter11/afterlfs.xml index 4afc8ecf7..279cc1108 100644 --- a/chapter11/afterlfs.xml +++ b/chapter11/afterlfs.xml @@ -129,7 +129,12 @@ mounttype dev/pts devpts devpts -o gid=5,mode=620 mounttype proc proc proc mounttype sys sysfs sysfs mounttype run tmpfs run -mkdir $LFS/run/shm +if [ -h $LFS/dev/shm ]; then + mkdir -pv $LFS/$(readlink $LFS/dev/shm) +else + mounttype dev/shm tmpfs tmpfs -o nosuid,nodev +fi + #mountbind usr/src #mountbind boot #mountbind home diff --git a/packages.ent b/packages.ent index 0fc7361a0..372603934 100644 --- a/packages.ent +++ b/packages.ent @@ -382,7 +382,7 @@ - +