]> git.ipfire.org Git - thirdparty/dracut.git/blob - modules.d/95virtfs/mount-virtfs.sh
7c07b46284f485c46c9793f533db3b97daf21948
[thirdparty/dracut.git] / modules.d / 95virtfs / mount-virtfs.sh
1 #!/bin/sh
2 # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
3 # ex: ts=8 sw=4 sts=4 et filetype=sh
4
5 type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh
6
7 filter_rootopts() {
8 rootopts=$1
9 # strip ro and rw options
10 local OLDIFS="$IFS"
11 IFS=,
12 set -- $rootopts
13 IFS="$OLDIFS"
14 local v
15 while [ $# -gt 0 ]; do
16 case $1 in
17 rw|ro);;
18 defaults);;
19 *)
20 v="$v,${1}";;
21 esac
22 shift
23 done
24 rootopts=${v#,}
25 echo $rootopts
26 }
27
28 mount_root() {
29 local _ret
30
31 rootfs="9p"
32 rflags="trans=virtio,version=9p2000.L"
33
34 modprobe 9pnet_virtio
35
36 mount -t ${rootfs} -o "$rflags",ro "${root#virtfs:}" "$NEWROOT"
37
38 rootopts=
39 if getargbool 1 rd.fstab -n rd_NO_FSTAB \
40 && ! getarg rootflags \
41 && [ -f "$NEWROOT/etc/fstab" ] \
42 && ! [ -L "$NEWROOT/etc/fstab" ]; then
43 # if $NEWROOT/etc/fstab contains special mount options for
44 # the root filesystem,
45 # remount it with the proper options
46 rootopts="defaults"
47 while read dev mp fs opts rest; do
48 # skip comments
49 [ "${dev%%#*}" != "$dev" ] && continue
50
51 if [ "$mp" = "/" ]; then
52 rootopts=$opts
53 break
54 fi
55 done < "$NEWROOT/etc/fstab"
56
57 rootopts=$(filter_rootopts $rootopts)
58 fi
59
60 # we want rootflags (rflags) to take precedence so prepend rootopts to
61 # them; rflags is guaranteed to not be empty
62 rflags="${rootopts:+"${rootopts},"}${rflags}"
63
64 umount "$NEWROOT"
65
66 info "Remounting ${root#virtfs:} with -o ${rflags}"
67 mount -t ${rootfs} -o "$rflags" "${root#virtfs:}" "$NEWROOT" 2>&1 | vinfo
68
69 [ -f "$NEWROOT"/forcefsck ] && rm -f "$NEWROOT"/forcefsck 2>/dev/null
70 [ -f "$NEWROOT"/.autofsck ] && rm -f "$NEWROOT"/.autofsck 2>/dev/null
71 }
72
73 if [ -n "$root" -a -z "${root%%virtfs:*}" ]; then
74 mount_root
75 fi
76 :