From 8fa61e098dee086900846fc1e9e414e6de410ba0 Mon Sep 17 00:00:00 2001 From: Fabio Erculiani Date: Tue, 6 Aug 2013 13:32:50 +0200 Subject: [PATCH] linuxrc: move /etc/initramfs.mounts handling to a separate function --- defaults/initrd.scripts | 42 +++++++++++++++++++++++++++++++++++++++++ defaults/linuxrc | 30 +---------------------------- 2 files changed, 43 insertions(+), 29 deletions(-) diff --git a/defaults/initrd.scripts b/defaults/initrd.scripts index b737e1b..9937ff4 100644 --- a/defaults/initrd.scripts +++ b/defaults/initrd.scripts @@ -1646,3 +1646,45 @@ get_mount_device() { strip_mount_options() { sed -r 's/(,|^)(no)?auto(,|$)/,/g' } + +# Read /etc/initramfs.mounts from ${NEW_ROOT} and mount the +# listed filesystem mountpoints. For instance, /usr, which is +# required by udev & systemd. +ensure_initramfs_mounts() { + local fslist= + + if [ -f "${NEW_ROOT}/etc/initramfs.mounts" ]; then + fslist="$(get_mounts_list)" + else + fslist="/usr" + fi + + local dev= fstype= opts= mnt= cmd= + for fs in ${fslist}; do + dev=$(get_mount_device "${fs}") + [ -z "${dev}" ] && continue + # Resolve it like util-linux mount does + [ -L "${dev}" ] && dev=$(readlink "${dev}") + # In this case, it's probably part of the filesystem + # and not a mountpoint + [ -z "${dev}" ] && continue + + fstype=$(get_mount_fstype "${fs}") + if get_mount_options "${fs}" | fgrep -q bind; then + opts="bind" + dev="${NEW_ROOT}${dev}" + else + # ro must be trailing, and the options will always + # contain at least 'defaults' + opts="$(get_mount_options ${fs} | strip_mount_options)" + opts="${opts},ro" + fi + + mnt="${NEW_ROOT}${fs}" + cmd="mount -t ${fstype} -o ${opts} ${dev} ${mnt}" + good_msg "Mounting ${dev} as ${fs}: ${cmd}" + if ! ${cmd}; then + bad_msg "Unable to mount ${dev} for ${fs}" + fi + done +} diff --git a/defaults/linuxrc b/defaults/linuxrc index 2d9864f..cdf120c 100644 --- a/defaults/linuxrc +++ b/defaults/linuxrc @@ -649,35 +649,7 @@ then fi # Mount the additional things as required by udev & systemd -if [ -f ${NEW_ROOT}/etc/initramfs.mounts ]; then - fslist=$(get_mounts_list) -else - fslist="/usr" -fi - -for fs in $fslist; do - dev=$(get_mount_device $fs) - [ -z "${dev}" ] && continue - # Resolve it like util-linux mount does - [ -L ${dev} ] && dev=$(readlink ${dev}) - # In this case, it's probably part of the filesystem - # and not a mountpoint - [ -z "$dev" ] && continue - fstype=$(get_mount_fstype $fs) - if get_mount_options $fs | fgrep -q bind ; then - opts='bind' - dev=${NEW_ROOT}${dev} - else - # ro must be trailing, and the options will always contain at least 'defaults' - opts="$(get_mount_options $fs | strip_mount_options),ro" - fi - mnt=${NEW_ROOT}${fs} - cmd="mount -t $fstype -o $opts $dev $mnt" - good_msg "Mounting $dev as ${fs}: $cmd" - if ! $cmd; then - bad_msg "Unable to mount $dev for $fs" - fi -done +ensure_initramfs_mounts splashcmd hasroot "${NEW_ROOT}"