From: Fabian Vogt Subject: Use /etc/fstab for /sysroot instead of custom sysroot.mount systemd-fstab-generator is capable of mounting /sysroot itself, looking at /proc/cmdline if root= is set. Index: dracut-043/modules.d/00systemd/module-setup.sh =================================================================== --- dracut-043.orig/modules.d/00systemd/module-setup.sh +++ dracut-043/modules.d/00systemd/module-setup.sh @@ -14,7 +14,7 @@ check() { # called by dracut depends() { - return 0 + echo fs-lib } installkernel() { @@ -22,6 +22,23 @@ installkernel() { instmods -s efivarfs } +fstab_sysroot() { + local _dev=/dev/block/$(find_root_block_device) + local _fstype _flags _subvol + if [ -e $_dev ]; then + _dev=$(shorten_persistent_dev "$(get_persistent_dev "$_dev")") + _fstype="$(find_mp_fstype /)" + _flags="$(find_mp_fsopts /)" + + if [[ $use_fstab != yes ]] && [[ $_fstype = btrfs ]]; then + _subvol=$(findmnt -e -v -n -o FSROOT --target /) \ + && _subvol=${_subvol#/} + _flags="$_flags,${_subvol:+subvol=$_subvol}" + fi + printf "%s /sysroot %s %s 1 1\n" "$_dev" "$_fstype" "${_flags#,}" + fi +} + # called by dracut install() { local _mods @@ -216,5 +233,8 @@ install() { } >> "$initdir/etc/systemd/journald.conf" ln_r "${systemdsystemunitdir}/multi-user.target" "${systemdsystemunitdir}/default.target" + + # Add entry for /sysroot to /etc/fstab + fstab_sysroot >> "$initdir/etc/fstab" } Index: dracut-043/modules.d/95rootfs-block/module-setup.sh =================================================================== --- dracut-043.orig/modules.d/95rootfs-block/module-setup.sh +++ dracut-043/modules.d/95rootfs-block/module-setup.sh @@ -48,22 +48,25 @@ cmdline_rootfs() { # called by dracut cmdline() { - cmdline_rootfs - cmdline_journal + # When using systemd, we're storing the root device in /etc/fstab instead. + if ! dracut_module_included "systemd"; then + cmdline_rootfs + cmdline_journal + fi } # called by dracut install() { - if [[ $hostonly_cmdline == "yes" ]]; then - local _journaldev=$(cmdline_journal) - [[ $_journaldev ]] && printf "%s\n" "$_journaldev" >> "${initdir}/etc/cmdline.d/95root-journaldev.conf" - local _rootdev=$(cmdline_rootfs) - [[ $_rootdev ]] && printf "%s\n" "$_rootdev" >> "${initdir}/etc/cmdline.d/95root-dev.conf" - fi - inst_multiple umount inst_multiple tr if ! dracut_module_included "systemd"; then + if [[ $hostonly_cmdline == "yes" ]]; then + local _journaldev=$(cmdline_journal) + [[ $_journaldev ]] && printf "%s\n" "$_journaldev" >> "${initdir}/etc/cmdline.d/95root-journaldev.conf" + local _rootdev=$(cmdline_rootfs) + [[ $_rootdev ]] && printf "%s\n" "$_rootdev" >> "${initdir}/etc/cmdline.d/95root-dev.conf" + fi + inst_hook cmdline 95 "$moddir/parse-block.sh" inst_hook pre-udev 30 "$moddir/block-genrules.sh" inst_hook mount 99 "$moddir/mount-root.sh" Index: dracut-043/modules.d/98dracut-systemd/dracut-cmdline.sh =================================================================== --- dracut-043.orig/modules.d/98dracut-systemd/dracut-cmdline.sh +++ dracut-043/modules.d/98dracut-systemd/dracut-cmdline.sh @@ -68,8 +68,12 @@ case "$root" in rootok=1 ;; esac -[ -z "$root" ] && die "No or empty root= argument" -[ -z "$rootok" ] && die "Don't know how to handle 'root=$root'" +if [ -z "$root" ]; then + root=$(findmnt --fstab -n --output source --target /sysroot) + [ -z "$root" ] && die "No or empty root= argument and not in fstab" +elif [ -z "$rootok" ]; then + die "Don't know how to handle 'root=$root'" +fi export root rflags fstype netroot NEWROOT Index: dracut-043/modules.d/98dracut-systemd/rootfs-generator.sh =================================================================== --- dracut-043.orig/modules.d/98dracut-systemd/rootfs-generator.sh +++ dracut-043/modules.d/98dracut-systemd/rootfs-generator.sh @@ -36,35 +36,6 @@ generator_wait_for_dev() fi } -generator_mount_rootfs() -{ - local _type=$2 - local _flags=$3 - local _name - - [ -z "$1" ] && return 0 - - _name=$(dev_unit_name "$1") - [ -d "$GENERATOR_DIR" ] || mkdir -p "$GENERATOR_DIR" - if ! [ -f "$GENERATOR_DIR"/sysroot.mount ]; then - { - echo "[Unit]" - echo "Before=initrd-root-fs.target" - echo "RequiresOverridable=systemd-fsck@${_name}.service" - echo "After=systemd-fsck@${_name}.service" - echo "[Mount]" - echo "Where=/sysroot" - echo "What=$1" - echo "Options=${_flags}" - echo "Type=${_type}" - } > "$GENERATOR_DIR"/sysroot.mount - fi - if ! [ -L "$GENERATOR_DIR"/initrd-root-fs.target.requires/sysroot.mount ]; then - [ -d "$GENERATOR_DIR"/initrd-root-fs.target.requires ] || mkdir -p "$GENERATOR_DIR"/initrd-root-fs.target.requires - ln -s ../sysroot.mount "$GENERATOR_DIR"/initrd-root-fs.target.requires/sysroot.mount - fi -} - generator_fsck_after_pre_mount() { local _name @@ -111,9 +82,12 @@ esac GENERATOR_DIR="$1" if [ "${root%%:*}" = "block" ]; then - generator_wait_for_dev "${root#block:}" "$RDRETRY" - generator_fsck_after_pre_mount "${root#block:}" - strstr "$(cat /proc/cmdline)" 'root=' || generator_mount_rootfs "${root#block:}" "$(getarg rootfstype=)" "$(getarg rootflags=)" + generator_wait_for_dev "${root#block:}" "$RDRETRY" + generator_fsck_after_pre_mount "${root#block:}" + if ! [ -L "$GENERATOR_DIR"/initrd-root-fs.target.requires/sysroot.mount ]; then + [ -d "$GENERATOR_DIR"/initrd-root-fs.target.requires ] || mkdir -p "$GENERATOR_DIR"/initrd-root-fs.target.requires + ln -s ../sysroot.mount "$GENERATOR_DIR"/initrd-root-fs.target.requires/sysroot.mount + fi fi exit 0 Index: dracut-043/modules.d/99base/init.sh =================================================================== --- dracut-043.orig/modules.d/99base/init.sh +++ dracut-043/modules.d/99base/init.sh @@ -128,8 +128,12 @@ make_trace_mem "hook cmdline" '1+:mem' ' getarg 'rd.break=cmdline' -d 'rdbreak=cmdline' && emergency_shell -n cmdline "Break before cmdline" source_hook cmdline -[ -z "$root" ] && die "No or empty root= argument" -[ -z "$rootok" ] && die "Don't know how to handle 'root=$root'" +if [ -z "$root" ]; then + root=$(findmnt --fstab -n --output source --target /sysroot) + [ -z "$root" ] && die "No or empty root= argument and not in fstab" +elif [ -z "$rootok" ]; then + die "Don't know how to handle 'root=$root'" +fi export root rflags fstype netroot NEWROOT