]>
git.ipfire.org Git - thirdparty/dracut.git/blob - modules.d/95nbd/nbdroot.sh
3 type getarg
> /dev
/null
2>&1 || .
/lib
/dracut-lib.sh
5 PATH
=/usr
/sbin
:/usr
/bin
:/sbin
:/bin
16 # root is in the form root=nbd:srv:port[:fstype[:rootflags[:nbdopts]]]
17 # shellcheck disable=SC2034
22 # If it's not nbd we don't continue
23 [ "${nroot%%:*}" = "nbd" ] ||
return
26 nbdserver
=${nroot%%:*}
27 if [ "${nbdserver%"${nbdserver#?}"}" = "[" ]; then
29 nbdserver
=${nbdserver%%]:*}
36 nbdfstype
=${nroot%%:*}
41 if [ "$nbdopts" = "$nbdflags" ]; then
44 if [ "$nbdflags" = "$nbdfstype" ]; then
47 if [ "$nbdfstype" = "$nbdport" ]; then
50 if [ -z "$nbdfstype" ]; then
54 # look through the NBD options and pull out the ones that need to
55 # go before the host etc. Append a ',' so we know we terminate the loop
57 while [ -n "$nbdopts" ]; do
63 if [ -z "${f%bs=*}" -o -z "${f%timeout=*}" ]; then
70 # look through the flags and see if any are overridden by the command line
72 while [ -n "$nbdflags" ]; do
74 nbdflags
=${nbdflags#*,}
78 if [ "$f" = "ro" -o "$f" = "rw" ]; then
82 fsopts
=${fsopts:+$fsopts,}$f
87 fsopts
=${fsopts:+$fsopts,}${nbdrw}
89 # XXX better way to wait for the device to be made?
91 while [ ! -b /dev
/nbd0
]; do
92 [ $i -ge 20 ] && exit 1
93 if [ "$UDEVVERSION" -ge 143 ]; then
94 udevadm settle
--exit-if-exists=/dev
/nbd0
101 # If we didn't get a root= on the command line, then we need to
102 # add the udev rules for mounting the nbd0 device
103 if [ "$root" = "block:/dev/root" -o "$root" = "dhcp" ]; then
104 printf 'KERNEL=="nbd0", ENV{DEVTYPE}!="partition", ENV{ID_FS_TYPE}=="?*", SYMLINK+="root"\n' > /etc
/udev
/rules.d
/99-nbd-root.rules
105 udevadm control
--reload
106 wait_for_dev
-n /dev
/root
108 if [ -z "$DRACUT_SYSTEMD" ]; then
109 type write_fs_tab
> /dev
/null
2>&1 || .
/lib
/fs-lib.sh
111 write_fs_tab
/dev
/root
"$nbdfstype" "$fsopts"
113 printf '/bin/mount %s\n' \
115 > "$hookdir"/mount
/01-$$
-nbd.sh
117 # if we're on systemd, use the nbd-generator script
118 # to create the /sysroot mount.
121 # supported since nbd 3.8 via 77e97612
122 if strstr
"$(nbd-client --help 2>&1)" "systemd-mark"; then
123 preopts
="-systemd-mark $preopts"
126 if [ "$nbdport" -gt 0 ] 2> /dev
/null
; then
129 nbdport
="-name $nbdport"
132 if ! nbd-client
-check /dev
/nbd0
> /dev
/null
; then
133 # shellcheck disable=SC2086
134 nbd-client
"$nbdserver" $nbdport /dev
/nbd0
$preopts $opts ||
exit 1
137 # NBD doesn't emit uevents when it gets connected, so kick it
138 echo change
> /sys
/block
/nbd
0/uevent