Skip to content

Commit c29325a

Browse files
committed
feat(virtiofs): virtiofs root filesystem support
Currently dracut can't mount virtiofs as root filesystem. Make possible to boot virtual machines off virtiofs, passing "root=virtiofs:<mtag>", using the mount tag <mtag> as root filesystem. Alternatively this module also supports "rootfstype=virtiofs root=<mtag>" Signed-off-by: German Maglione <[email protected]>
1 parent 79f9d9e commit c29325a

File tree

5 files changed

+79
-0
lines changed

5 files changed

+79
-0
lines changed

man/dracut.cmdline.7.asc

+19
Original file line numberDiff line numberDiff line change
@@ -928,6 +928,25 @@ NOTE:
928928
If "exportname" instead of "port" is given the standard port is used.
929929
Newer versions of nbd are only supported with "exportname".
930930
931+
VIRTIOFS
932+
~~~~~~~~
933+
**root=**virtiofs:__<mount-tag>__::
934+
mount virtiofs share using the tag <mount-tag>.
935+
The tag name is arbitrary and must match the tag given in the qemu '-device' command.
936+
937+
**rootfstype=**virtiofs **root=**__<mount-tag>__::
938+
mount virtiofs share using the tag <mount-tag>.
939+
The tag name is arbitrary and must match the tag given in the qemu '-device' command.
940+
941+
Both formats are supported by the 'virtiofs' dracut module.
942+
See https://gitlab.com/virtio-fs/virtiofsd for more information.
943+
944+
[listing]
945+
.Example
946+
--
947+
root=virtiofs:host rw
948+
--
949+
931950
DASD
932951
~~~~
933952
**rd.dasd=**....::

modules.d/95virtiofs/module-setup.sh

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/bash
2+
3+
# called by dracut
4+
check() {
5+
[[ $hostonly ]] || [[ $mount_needs ]] && {
6+
is_qemu_virtualized && return 0
7+
8+
for fs in "${host_fs_types[@]}"; do
9+
[[ $fs == "virtiofs" ]] && return 0
10+
done
11+
return 255
12+
}
13+
14+
return 0
15+
}
16+
17+
# called by dracut
18+
depends() {
19+
return 0
20+
}
21+
22+
# called by dracut
23+
installkernel() {
24+
instmods virtiofs
25+
}
26+
27+
# called by dracut
28+
install() {
29+
inst_hook cmdline 95 "$moddir/parse-virtiofs.sh"
30+
inst_hook pre-mount 99 "$moddir/mount-virtiofs.sh"
31+
}
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/sh
2+
3+
if [ "${fstype}" = "virtiofs" -o "${root%%:*}" = "virtiofs" ]; then
4+
if ! { modprobe virtiofs || strstr "$(cat /proc/filesystems)" virtiofs; }; then
5+
die "virtiofs is required but not available."
6+
fi
7+
8+
mount -t virtiofs -o "$rflags" "${root#virtiofs:}" "$NEWROOT" 2>&1 | vinfo
9+
if ! ismounted "$NEWROOT"; then
10+
die "virtiofs: failed to mount root fs"
11+
exit 1
12+
fi
13+
14+
info "virtiofs: root fs mounted (options: '${rflags}')"
15+
16+
[ -f "$NEWROOT"/forcefsck ] && rm -f -- "$NEWROOT"/forcefsck 2> /dev/null
17+
[ -f "$NEWROOT"/.autofsck ] && rm -f -- "$NEWROOT"/.autofsck 2> /dev/null
18+
fi
19+
:
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/sh
2+
# Accepted formats:
3+
# rootfstype=virtiofs root=<tag>
4+
# root=virtiofs:<tag>
5+
6+
if [ "${fstype}" = "virtiofs" -o "${root%%:*}" = "virtiofs" ]; then
7+
# shellcheck disable=SC2034
8+
rootok=1
9+
fi

pkgbuild/dracut.spec

+1
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,7 @@ echo 'dracut_rescue_image="yes"' > $RPM_BUILD_ROOT%{dracutlibdir}/dracut.conf.d/
386386
%{dracutlibdir}/modules.d/95terminfo
387387
%{dracutlibdir}/modules.d/95udev-rules
388388
%{dracutlibdir}/modules.d/95virtfs
389+
%{dracutlibdir}/modules.d/95virtiofs
389390
%ifarch s390 s390x
390391
%{dracutlibdir}/modules.d/80cms
391392
%{dracutlibdir}/modules.d/81cio_ignore

0 commit comments

Comments
 (0)