summaryrefslogtreecommitdiffstats
path: root/modules.d/95rootfs-block
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-03 13:54:25 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-03 13:54:25 +0000
commit9cb1c4df7b9ce1a9ad1312621b0f2b16a94fba3a (patch)
tree2efb72864cc69e174c9c5ee33efb88a5f1553b48 /modules.d/95rootfs-block
parentInitial commit. (diff)
downloaddracut-9cb1c4df7b9ce1a9ad1312621b0f2b16a94fba3a.tar.xz
dracut-9cb1c4df7b9ce1a9ad1312621b0f2b16a94fba3a.zip
Adding upstream version 060+5.upstream/060+5
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'modules.d/95rootfs-block')
-rwxr-xr-xmodules.d/95rootfs-block/block-genrules.sh16
-rwxr-xr-xmodules.d/95rootfs-block/module-setup.sh92
-rwxr-xr-xmodules.d/95rootfs-block/mount-root.sh135
-rwxr-xr-xmodules.d/95rootfs-block/parse-block.sh15
-rwxr-xr-xmodules.d/95rootfs-block/rootfallback.sh22
5 files changed, 280 insertions, 0 deletions
diff --git a/modules.d/95rootfs-block/block-genrules.sh b/modules.d/95rootfs-block/block-genrules.sh
new file mode 100755
index 0000000..d5df0ee
--- /dev/null
+++ b/modules.d/95rootfs-block/block-genrules.sh
@@ -0,0 +1,16 @@
+#!/bin/sh
+
+if [ "${root%%:*}" = "block" ]; then
+ {
+ printf 'KERNEL=="%s", SYMLINK+="root"\n' \
+ "${root#block:/dev/}"
+ printf 'SYMLINK=="%s", SYMLINK+="root"\n' \
+ "${root#block:/dev/}"
+ } >> /etc/udev/rules.d/99-root.rules
+
+ # shellcheck disable=SC2016
+ printf '[ -e "%s" ] && { ln -s "%s" /dev/root 2>/dev/null; rm "$job"; }\n' \
+ "${root#block:}" "${root#block:}" > "$hookdir"/initqueue/settled/blocksymlink.sh
+
+ wait_for_dev "${root#block:}"
+fi
diff --git a/modules.d/95rootfs-block/module-setup.sh b/modules.d/95rootfs-block/module-setup.sh
new file mode 100755
index 0000000..396fb11
--- /dev/null
+++ b/modules.d/95rootfs-block/module-setup.sh
@@ -0,0 +1,92 @@
+#!/bin/bash
+
+# called by dracut
+check() {
+ return 0
+}
+
+# called by dracut
+depends() {
+ echo base fs-lib
+}
+
+cmdline_journal() {
+ if [[ $hostonly ]]; then
+ for dev in "${!host_fs_types[@]}"; do
+ [[ ${host_fs_types[$dev]} == "reiserfs" ]] || [[ ${host_fs_types[$dev]} == "xfs" ]] || continue
+ rootopts=$(find_dev_fsopts "$dev")
+ if [[ ${host_fs_types[$dev]} == "reiserfs" ]]; then
+ journaldev=$(fs_get_option "$rootopts" "jdev")
+ elif [[ ${host_fs_types[$dev]} == "xfs" ]]; then
+ journaldev=$(fs_get_option "$rootopts" "logdev")
+ fi
+
+ if [ -n "$journaldev" ]; then
+ printf " root.journaldev=%s" "$journaldev"
+ fi
+ done
+ fi
+ return 0
+}
+
+cmdline_rootfs() {
+ local _block
+ _block=$(find_root_block_device)
+ local _dev=/dev/block/$_block
+ local _fstype _flags _subvol
+
+ # "--no-hostonly-default-device" can result in empty root_devs
+ if [ "${#root_devs[@]}" -eq 0 ]; then
+ return
+ fi
+
+ if [ -n "$_block" -a -b "$_dev" ]; then
+ printf " root=%s" "$(shorten_persistent_dev "$(get_persistent_dev "$_dev")")"
+ fi
+ _fstype="$(find_mp_fstype /)"
+ if [[ ${_fstype} == "zfs" ]]; then
+ local _root_ds
+ _root_ds="$(findmnt -n -o SOURCE /)"
+ printf " root=zfs:%s" "${_root_ds// /+}"
+ fi
+ _flags="$(find_mp_fsopts /)"
+ if [ -n "$_fstype" ]; then
+ printf " rootfstype=%s" "$_fstype"
+ fi
+ if [[ $use_fstab != yes ]] && [[ $_fstype == btrfs ]]; then
+ _subvol=$(findmnt -e -v -n -o FSROOT --target /) \
+ && _subvol=${_subvol#/}
+ _flags="$_flags${_subvol:+,subvol=$_subvol}"
+ fi
+ if [ -n "$_flags" ]; then
+ printf " rootflags=%s" "$_flags"
+ fi
+}
+
+# called by dracut
+cmdline() {
+ cmdline_rootfs
+ cmdline_journal
+}
+
+# called by dracut
+install() {
+ if [[ $hostonly_cmdline == "yes" ]]; then
+ local _journaldev
+ _journaldev=$(cmdline_journal)
+ [[ $_journaldev ]] && printf "%s\n" "$_journaldev" >> "${initdir}/etc/cmdline.d/95root-journaldev.conf"
+ local _rootdev
+ _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
+ 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"
+ fi
+
+ inst_hook initqueue/timeout 99 "$moddir/rootfallback.sh"
+}
diff --git a/modules.d/95rootfs-block/mount-root.sh b/modules.d/95rootfs-block/mount-root.sh
new file mode 100755
index 0000000..c488b11
--- /dev/null
+++ b/modules.d/95rootfs-block/mount-root.sh
@@ -0,0 +1,135 @@
+#!/bin/sh
+
+type getarg > /dev/null 2>&1 || . /lib/dracut-lib.sh
+type det_fs > /dev/null 2>&1 || . /lib/fs-lib.sh
+
+mount_root() {
+ local _rflags_ro
+ # sanity - determine/fix fstype
+ rootfs=$(det_fs "${root#block:}" "$fstype")
+
+ journaldev=$(getarg "root.journaldev=")
+ if [ -n "$journaldev" ]; then
+ case "$rootfs" in
+ xfs)
+ rflags="${rflags:+${rflags},}logdev=$journaldev"
+ ;;
+ reiserfs)
+ fsckoptions="-j $journaldev $fsckoptions"
+ rflags="${rflags:+${rflags},}jdev=$journaldev"
+ ;;
+ *) ;;
+ esac
+ fi
+
+ _rflags_ro="$rflags,ro"
+ _rflags_ro="${_rflags_ro##,}"
+
+ while ! mount -t "${rootfs}" -o "$_rflags_ro" "${root#block:}" "$NEWROOT"; do
+ warn "Failed to mount -t ${rootfs} -o $_rflags_ro ${root#block:} $NEWROOT"
+ fsck_ask_err
+ done
+
+ READONLY=
+ fsckoptions=
+ if [ -f "$NEWROOT"/etc/sysconfig/readonly-root ]; then
+ # shellcheck disable=SC1090
+ . "$NEWROOT"/etc/sysconfig/readonly-root
+ fi
+
+ if getargbool 0 "readonlyroot=" -y readonlyroot; then
+ READONLY=yes
+ fi
+
+ if getarg noreadonlyroot; then
+ READONLY=no
+ fi
+
+ if [ -f "$NEWROOT"/fastboot ] || getargbool 0 fastboot; then
+ fastboot=yes
+ fi
+
+ if ! getargbool 0 rd.skipfsck; then
+ if [ -f "$NEWROOT"/fsckoptions ]; then
+ read -r fsckoptions < "$NEWROOT"/fsckoptions
+ fi
+
+ if [ -f "$NEWROOT"/forcefsck ] || getargbool 0 forcefsck; then
+ fsckoptions="-f $fsckoptions"
+ elif [ -f "$NEWROOT"/.autofsck ]; then
+ # shellcheck disable=SC1090
+ [ -f "$NEWROOT"/etc/sysconfig/autofsck ] \
+ && . "$NEWROOT"/etc/sysconfig/autofsck
+ if [ "$AUTOFSCK_DEF_CHECK" = "yes" ]; then
+ AUTOFSCK_OPT="$AUTOFSCK_OPT -f"
+ fi
+ if [ -n "$AUTOFSCK_SINGLEUSER" ]; then
+ warn "*** Warning -- the system did not shut down cleanly. "
+ warn "*** Dropping you to a shell; the system will continue"
+ warn "*** when you leave the shell."
+ emergency_shell
+ fi
+ fsckoptions="$AUTOFSCK_OPT $fsckoptions"
+ fi
+ fi
+
+ rootopts=
+ if getargbool 1 rd.fstab -d -n rd_NO_FSTAB \
+ && ! getarg rootflags > /dev/null \
+ && [ -f "$NEWROOT/etc/fstab" ] \
+ && ! [ -L "$NEWROOT/etc/fstab" ]; then
+ # if $NEWROOT/etc/fstab contains special mount options for
+ # the root filesystem,
+ # remount it with the proper options
+ rootopts="defaults"
+ while read -r dev mp fs opts _ fsck || [ -n "$dev" ]; do
+ # skip comments
+ [ "${dev%%#*}" != "$dev" ] && continue
+
+ if [ "$mp" = "/" ]; then
+ # sanity - determine/fix fstype
+ rootfs=$(det_fs "${root#block:}" "$fs")
+ rootopts=$opts
+ rootfsck=$fsck
+ break
+ fi
+ done < "$NEWROOT/etc/fstab"
+ fi
+
+ # we want rootflags (rflags) to take precedence so prepend rootopts to
+ # them
+ rflags="${rootopts},${rflags}"
+ rflags="${rflags#,}"
+ rflags="${rflags%,}"
+
+ # backslashes are treated as escape character in fstab
+ # esc_root=$(echo ${root#block:} | sed 's,\\,\\\\,g')
+ # printf '%s %s %s %s 1 1 \n' "$esc_root" "$NEWROOT" "$rootfs" "$rflags" >/etc/fstab
+
+ if fsck_able "$rootfs" \
+ && [ "$rootfsck" != "0" -a -z "$fastboot" -a "$READONLY" != "yes" ] \
+ && ! strstr "${rflags}" _netdev \
+ && ! getargbool 0 rd.skipfsck; then
+ umount "$NEWROOT"
+ fsck_single "${root#block:}" "$rootfs" "$rflags" "$fsckoptions"
+ fi
+
+ echo "${root#block:} $NEWROOT $rootfs ${rflags:-defaults} 0 ${rootfsck:-0}" >> /etc/fstab
+
+ if ! ismounted "$NEWROOT"; then
+ info "Mounting ${root#block:} with -o ${rflags}"
+ mount "$NEWROOT" 2>&1 | vinfo
+ elif ! are_lists_eq , "$rflags" "$_rflags_ro" defaults; then
+ info "Remounting ${root#block:} with -o ${rflags}"
+ mount -o remount "$NEWROOT" 2>&1 | vinfo
+ fi
+
+ if ! getargbool 0 rd.skipfsck; then
+ [ -f "$NEWROOT"/forcefsck ] && rm -f -- "$NEWROOT"/forcefsck 2> /dev/null
+ [ -f "$NEWROOT"/.autofsck ] && rm -f -- "$NEWROOT"/.autofsck 2> /dev/null
+ fi
+}
+
+if [ -n "$root" -a -z "${root%%block:*}" ]; then
+ mount_root
+fi
diff --git a/modules.d/95rootfs-block/parse-block.sh b/modules.d/95rootfs-block/parse-block.sh
new file mode 100755
index 0000000..9c4357e
--- /dev/null
+++ b/modules.d/95rootfs-block/parse-block.sh
@@ -0,0 +1,15 @@
+#!/bin/sh
+
+case "${root#block:}" in
+ LABEL=* | UUID=* | PARTUUID=* | PARTLABEL=*)
+ root="block:$(label_uuid_to_dev "$root")"
+ rootok=1
+ ;;
+ /dev/*)
+ root="block:${root#block:}"
+ # shellcheck disable=SC2034
+ rootok=1
+ ;;
+esac
+
+[ "${root%%:*}" = "block" ] && wait_for_dev "${root#block:}"
diff --git a/modules.d/95rootfs-block/rootfallback.sh b/modules.d/95rootfs-block/rootfallback.sh
new file mode 100755
index 0000000..ce4ee85
--- /dev/null
+++ b/modules.d/95rootfs-block/rootfallback.sh
@@ -0,0 +1,22 @@
+#!/bin/sh
+
+type getarg > /dev/null 2>&1 || . /lib/dracut-lib.sh
+
+for root in $(getargs rootfallback=); do
+ root=$(label_uuid_to_dev "$root")
+
+ if ! [ -b "$root" ]; then
+ warn "Could not find rootfallback $root"
+ continue
+ fi
+
+ if mount "$root" /sysroot; then
+ info "Mounted rootfallback $root"
+ exit 0
+ else
+ warn "Failed to mount rootfallback $root"
+ exit 1
+ fi
+done
+
+[ -e "$job" ] && rm -f "$job"