summaryrefslogtreecommitdiffstats
path: root/modules.d/95virtfs/mount-virtfs.sh
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/95virtfs/mount-virtfs.sh
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/95virtfs/mount-virtfs.sh')
-rwxr-xr-xmodules.d/95virtfs/mount-virtfs.sh74
1 files changed, 74 insertions, 0 deletions
diff --git a/modules.d/95virtfs/mount-virtfs.sh b/modules.d/95virtfs/mount-virtfs.sh
new file mode 100755
index 0000000..e52c752
--- /dev/null
+++ b/modules.d/95virtfs/mount-virtfs.sh
@@ -0,0 +1,74 @@
+#!/bin/sh
+
+type getarg > /dev/null 2>&1 || . /lib/dracut-lib.sh
+
+filter_rootopts() {
+ rootopts=$1
+ # strip ro and rw options
+ local OLDIFS="$IFS"
+ IFS=,
+ # shellcheck disable=SC2086
+ set -- $rootopts
+ IFS="$OLDIFS"
+ local v
+ while [ $# -gt 0 ]; do
+ case $1 in
+ rw | ro) ;;
+ defaults) ;;
+ *)
+ v="$v,${1}"
+ ;;
+ esac
+ shift
+ done
+ rootopts=${v#,}
+ echo "$rootopts"
+}
+
+mount_root() {
+ rootfs="9p"
+ rflags="trans=virtio,version=9p2000.L"
+
+ modprobe 9pnet_virtio
+
+ mount -t ${rootfs} -o "$rflags",ro "${root#virtfs:}" "$NEWROOT"
+
+ rootopts=
+ if getargbool 1 rd.fstab -n rd_NO_FSTAB \
+ && ! getarg rootflags \
+ && [ -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 _ opts rest || [ -n "$dev" ]; do
+ # skip comments
+ [ "${dev%%#*}" != "$dev" ] && continue
+
+ if [ "$mp" = "/" ]; then
+ rootopts=$opts
+ break
+ fi
+ done < "$NEWROOT/etc/fstab"
+
+ rootopts=$(filter_rootopts "$rootopts")
+ fi
+
+ # we want rootflags (rflags) to take precedence so prepend rootopts to
+ # them; rflags is guaranteed to not be empty
+ rflags="${rootopts:+${rootopts},}${rflags}"
+
+ umount "$NEWROOT"
+
+ info "Remounting ${root#virtfs:} with -o ${rflags}"
+ mount -t ${rootfs} -o "$rflags" "${root#virtfs:}" "$NEWROOT" 2>&1 | vinfo
+
+ [ -f "$NEWROOT"/forcefsck ] && rm -f -- "$NEWROOT"/forcefsck 2> /dev/null
+ [ -f "$NEWROOT"/.autofsck ] && rm -f -- "$NEWROOT"/.autofsck 2> /dev/null
+}
+
+if [ -n "$root" -a -z "${root%%virtfs:*}" ]; then
+ mount_root
+fi
+: