Blame 0013-virtfs-root-filesystem-support.patch

Harald Hoyer 953eb6
From a7c9cbe1a21ecc306fce3127be0a4ad75c5fcfcb Mon Sep 17 00:00:00 2001
Harald Hoyer 953eb6
From: Lennert Buytenhek <buytenh@wantstofly.org>
Harald Hoyer 953eb6
Date: Sun, 15 Apr 2012 02:40:17 +0200
Harald Hoyer 953eb6
Subject: [PATCH] virtfs root filesystem support
Harald Hoyer 953eb6
Harald Hoyer 953eb6
Qemu/KVM provides virtfs, a paravirtualised filesystem that is
Harald Hoyer 953eb6
implemented by running the Plan 9 folder sharing protocol over
Harald Hoyer 953eb6
virtio.
Harald Hoyer 953eb6
Harald Hoyer 953eb6
Make booting with root=virtfs:foobar use the virtfs filesystem
Harald Hoyer 953eb6
with mount tag 'foobar' as root filesystem, to allow booting
Harald Hoyer 953eb6
virtual machines off virtfs.
Harald Hoyer 953eb6
Harald Hoyer 953eb6
Note that this only handles 9p over virtio (i.e. virtfs), and
Harald Hoyer 953eb6
doesn't attempt to handle mounting 9p filesystems over TCP/IP,
Harald Hoyer 953eb6
for example.
Harald Hoyer 953eb6
Harald Hoyer 953eb6
Signed-off-by: Lennert Buytenhek <buytenh@wantstofly.org>
Harald Hoyer 953eb6
---
Harald Hoyer 953eb6
 dracut.spec                        |    1 +
Harald Hoyer 953eb6
 modules.d/95virtfs/module-setup.sh |   27 +++++++++++++
Harald Hoyer 953eb6
 modules.d/95virtfs/mount-virtfs.sh |   75 ++++++++++++++++++++++++++++++++++++
Harald Hoyer 953eb6
 modules.d/95virtfs/parse-virtfs.sh |    9 +++++
Harald Hoyer 0c26bf
 4 Dateien geändert, 112 Zeilen hinzugefügt(+)
Harald Hoyer 953eb6
 create mode 100755 modules.d/95virtfs/module-setup.sh
Harald Hoyer 953eb6
 create mode 100755 modules.d/95virtfs/mount-virtfs.sh
Harald Hoyer 953eb6
 create mode 100755 modules.d/95virtfs/parse-virtfs.sh
Harald Hoyer 953eb6
Harald Hoyer 953eb6
diff --git a/dracut.spec b/dracut.spec
Harald Hoyer 953eb6
index 074cb10..9cd08b7 100644
Harald Hoyer 953eb6
--- a/dracut.spec
Harald Hoyer 953eb6
+++ b/dracut.spec
Harald Hoyer 953eb6
@@ -270,6 +270,7 @@ rm -rf $RPM_BUILD_ROOT
Harald Hoyer 953eb6
 %{dracutlibdir}/modules.d/95zfcp
Harald Hoyer 953eb6
 %{dracutlibdir}/modules.d/95terminfo
Harald Hoyer 953eb6
 %{dracutlibdir}/modules.d/95udev-rules
Harald Hoyer 953eb6
+%{dracutlibdir}/modules.d/95virtfs
Harald Hoyer 953eb6
 %{dracutlibdir}/modules.d/96securityfs
Harald Hoyer 953eb6
 %{dracutlibdir}/modules.d/97biosdevname
Harald Hoyer 953eb6
 %{dracutlibdir}/modules.d/97masterkey
Harald Hoyer 953eb6
diff --git a/modules.d/95virtfs/module-setup.sh b/modules.d/95virtfs/module-setup.sh
Harald Hoyer 953eb6
new file mode 100755
Harald Hoyer 953eb6
index 0000000..a6081c2
Harald Hoyer 953eb6
--- /dev/null
Harald Hoyer 953eb6
+++ b/modules.d/95virtfs/module-setup.sh
Harald Hoyer 953eb6
@@ -0,0 +1,27 @@
Harald Hoyer 953eb6
+#!/bin/bash
Harald Hoyer 953eb6
+# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
Harald Hoyer 953eb6
+# ex: ts=8 sw=4 sts=4 et filetype=sh
Harald Hoyer 953eb6
+
Harald Hoyer 953eb6
+check() {
Harald Hoyer 953eb6
+    [[ $hostonly ]] || [[ $mount_needs ]] && {
Harald Hoyer 953eb6
+        for fs in ${host_fs_types[@]}; do
Harald Hoyer 953eb6
+            strstr "$fs" "\|9p" && return 0
Harald Hoyer 953eb6
+        done
Harald Hoyer 953eb6
+        return 1
Harald Hoyer 953eb6
+    }
Harald Hoyer 953eb6
+
Harald Hoyer 953eb6
+    return 0
Harald Hoyer 953eb6
+}
Harald Hoyer 953eb6
+
Harald Hoyer 953eb6
+depends() {
Harald Hoyer 953eb6
+    return 0
Harald Hoyer 953eb6
+}
Harald Hoyer 953eb6
+
Harald Hoyer 953eb6
+installkernel() {
Harald Hoyer 953eb6
+    instmods 9p 9pnet_virtio
Harald Hoyer 953eb6
+}
Harald Hoyer 953eb6
+
Harald Hoyer 953eb6
+install() {
Harald Hoyer 953eb6
+    inst_hook cmdline 95 "$moddir/parse-virtfs.sh"
Harald Hoyer 953eb6
+    inst_hook mount 99 "$moddir/mount-virtfs.sh"
Harald Hoyer 953eb6
+}
Harald Hoyer 953eb6
diff --git a/modules.d/95virtfs/mount-virtfs.sh b/modules.d/95virtfs/mount-virtfs.sh
Harald Hoyer 953eb6
new file mode 100755
Harald Hoyer 953eb6
index 0000000..dfebf38
Harald Hoyer 953eb6
--- /dev/null
Harald Hoyer 953eb6
+++ b/modules.d/95virtfs/mount-virtfs.sh
Harald Hoyer 953eb6
@@ -0,0 +1,75 @@
Harald Hoyer 953eb6
+#!/bin/sh
Harald Hoyer 953eb6
+# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
Harald Hoyer 953eb6
+# ex: ts=8 sw=4 sts=4 et filetype=sh
Harald Hoyer 953eb6
+
Harald Hoyer 953eb6
+type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh
Harald Hoyer 953eb6
+
Harald Hoyer 953eb6
+filter_rootopts() {
Harald Hoyer 953eb6
+    rootopts=$1
Harald Hoyer 953eb6
+    # strip ro and rw options
Harald Hoyer 953eb6
+    local OLDIFS="$IFS"
Harald Hoyer 953eb6
+    IFS=,
Harald Hoyer 953eb6
+    set -- $rootopts
Harald Hoyer 953eb6
+    IFS="$OLDIFS"
Harald Hoyer 953eb6
+    local v
Harald Hoyer 953eb6
+    while [ $# -gt 0 ]; do
Harald Hoyer 953eb6
+        case $1 in
Harald Hoyer 953eb6
+            rw|ro);;
Harald Hoyer 953eb6
+            defaults);;
Harald Hoyer 953eb6
+            *)
Harald Hoyer 953eb6
+                v="$v,${1}";;
Harald Hoyer 953eb6
+        esac
Harald Hoyer 953eb6
+        shift
Harald Hoyer 953eb6
+    done
Harald Hoyer 953eb6
+    rootopts=${v#,}
Harald Hoyer 953eb6
+    echo $rootopts
Harald Hoyer 953eb6
+}
Harald Hoyer 953eb6
+
Harald Hoyer 953eb6
+mount_root() {
Harald Hoyer 953eb6
+    local _ret
Harald Hoyer 953eb6
+
Harald Hoyer 953eb6
+    rootfs="9p"
Harald Hoyer 953eb6
+    rflags="trans=virtio,version=9p2000.L"
Harald Hoyer 953eb6
+
Harald Hoyer 953eb6
+    modprobe 9pnet_virtio
Harald Hoyer 953eb6
+
Harald Hoyer 953eb6
+    mount -t ${rootfs} -o "$rflags",ro "${root#virtfs:}" "$NEWROOT"
Harald Hoyer 953eb6
+
Harald Hoyer 953eb6
+    rootopts=
Harald Hoyer 953eb6
+    if getargbool 1 rd.fstab -n rd_NO_FSTAB \
Harald Hoyer 953eb6
+        && ! getarg rootflags \
Harald Hoyer 953eb6
+        && [ -f "$NEWROOT/etc/fstab" ] \
Harald Hoyer 953eb6
+        && ! [ -L "$NEWROOT/etc/fstab" ]; then
Harald Hoyer 953eb6
+        # if $NEWROOT/etc/fstab contains special mount options for
Harald Hoyer 953eb6
+        # the root filesystem,
Harald Hoyer 953eb6
+        # remount it with the proper options
Harald Hoyer 953eb6
+        rootopts="defaults"
Harald Hoyer 953eb6
+        while read dev mp fs opts rest; do
Harald Hoyer 953eb6
+            # skip comments
Harald Hoyer 953eb6
+            [ "${dev%%#*}" != "$dev" ] && continue
Harald Hoyer 953eb6
+
Harald Hoyer 953eb6
+            if [ "$mp" = "/" ]; then
Harald Hoyer 953eb6
+                rootopts=$opts
Harald Hoyer 953eb6
+                break
Harald Hoyer 953eb6
+            fi
Harald Hoyer 953eb6
+        done < "$NEWROOT/etc/fstab"
Harald Hoyer 953eb6
+
Harald Hoyer 953eb6
+        rootopts=$(filter_rootopts $rootopts)
Harald Hoyer 953eb6
+    fi
Harald Hoyer 953eb6
+
Harald Hoyer 953eb6
+    # we want rootflags (rflags) to take precedence so prepend rootopts to
Harald Hoyer 953eb6
+    # them; rflags is guaranteed to not be empty
Harald Hoyer 953eb6
+    rflags="${rootopts:+"${rootopts},"}${rflags}"
Harald Hoyer 953eb6
+
Harald Hoyer 953eb6
+    umount "$NEWROOT"
Harald Hoyer 953eb6
+
Harald Hoyer 953eb6
+    info "Remounting ${root#virtfs:} with -o ${rflags}"
Harald Hoyer 953eb6
+    mount -t ${rootfs} -o "$rflags" "${root#virtfs:}" "$NEWROOT" 2>&1 | vinfo
Harald Hoyer 953eb6
+
Harald Hoyer 953eb6
+    [ -f "$NEWROOT"/forcefsck ] && rm -f "$NEWROOT"/forcefsck 2>/dev/null
Harald Hoyer 953eb6
+    [ -f "$NEWROOT"/.autofsck ] && rm -f "$NEWROOT"/.autofsck 2>/dev/null
Harald Hoyer 953eb6
+}
Harald Hoyer 953eb6
+
Harald Hoyer 953eb6
+if [ -n "$root" -a -z "${root%%virtfs:*}" ]; then
Harald Hoyer 953eb6
+    mount_root
Harald Hoyer 953eb6
+fi
Harald Hoyer 953eb6
diff --git a/modules.d/95virtfs/parse-virtfs.sh b/modules.d/95virtfs/parse-virtfs.sh
Harald Hoyer 953eb6
new file mode 100755
Harald Hoyer 953eb6
index 0000000..ce6de6d
Harald Hoyer 953eb6
--- /dev/null
Harald Hoyer 953eb6
+++ b/modules.d/95virtfs/parse-virtfs.sh
Harald Hoyer 953eb6
@@ -0,0 +1,9 @@
Harald Hoyer 953eb6
+#!/bin/sh
Harald Hoyer 953eb6
+# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
Harald Hoyer 953eb6
+# ex: ts=8 sw=4 sts=4 et filetype=sh
Harald Hoyer 953eb6
+
Harald Hoyer 953eb6
+if [ "${root%%:*}" = "virtfs" ] ; then
Harald Hoyer 953eb6
+    modprobe 9pnet_virtio
Harald Hoyer 953eb6
+
Harald Hoyer 953eb6
+    rootok=1
Harald Hoyer 953eb6
+fi