From 75471fe3b7d5ea78fe465fdfe3eb64ae4ee363c8 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Sun, 11 Sep 2016 16:41:12 +0200 Subject: scripts/restore-etc: do not mount a tmpfs on /etc if / is a ramfs When booting an initramfs, it's pointless to mount some tmpfs everywhere since we can already extract /etc into the / FS. We now detect that / is a ramfs and avoid mounting the tmpfs in this case. At unmount time, we remove the whole /etc entries if we're on a ramfs. Note that we use stat to detect the filesystem type on /, and the script ensures the tmpfs is still used if the "stat" binary is not present. --- scripts/restore-etc | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/scripts/restore-etc b/scripts/restore-etc index 2e55690..1d00fca 100755 --- a/scripts/restore-etc +++ b/scripts/restore-etc @@ -125,16 +125,22 @@ list_changes() { fi } -# tries to unmount /etc +# tries to unmount /etc and to delete everything there if / is a ramfs unmount_etc() { while umount "$ROOTDIR/etc" >/dev/null 2>&1; do : ; done + if [ "$(stat -fc "%T" "$ROOTDIR/" 2>/dev/null)" = "ramfs" ]; then + rm -rf "$ROOTDIR/etc/." >/dev/null 2>&1 + fi } -# mount /etc unless config.rc already exists +# mount /etc unless config.rc already exists or / is a ramfs mount_etc() { if [ ! -e "$ROOTDIR/etc/config.rc" ]; then - mount -n -t $FSTYPE ${MOUNTOPT:+-o $MOUNTOPT} "$ROOTDIR/etc" "$ROOTDIR/etc" || \ - mount -n -t $FSTYPE "$ROOTDIR/etc" "$ROOTDIR/etc" + mkdir -p "$ROOTDIR/etc" >/dev/null 2>&1 + if [ "$(stat -fc "%T" "$ROOTDIR/" 2>/dev/null)" != "ramfs" ]; then + mount -n -t $FSTYPE ${MOUNTOPT:+-o $MOUNTOPT} "$ROOTDIR/etc" "$ROOTDIR/etc" || \ + mount -n -t $FSTYPE "$ROOTDIR/etc" "$ROOTDIR/etc" + fi fi } -- 1.7.12.1