]>
git.ipfire.org Git - thirdparty/dracut.git/blob - modules.d/95nbd/nbdroot
2 # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
3 # ex: ts=8 sw=4 sts=4 et filetype=sh
5 type getarg
>/dev
/null
2>&1 || .
/lib
/dracut-lib.sh
7 PATH
=/usr
/sbin
:/usr
/bin
:/sbin
:/bin
18 # root is in the form root=nbd:srv:port[:fstype[:rootflags[:nbdopts]]]
23 # If it's not nbd we don't continue
24 [ "${root%%:*}" = "nbd" ] ||
return
27 nbdserver
=${root%%:*}; root
=${root#*:}
28 nbdport
=${root%%:*}; root
=${root#*:}
29 nbdfstype
=${root%%:*}; root
=${root#*:}
33 if [ "$nbdopts" = "$nbdflags" ]; then
36 if [ "$nbdflags" = "$nbdfstype" ]; then
39 if [ "$nbdfstype" = "$nbdport" ]; then
42 if [ -z "$nbdfstype" ]; then
46 # look through the NBD options and pull out the ones that need to
47 # go before the host etc. Append a ',' so we know we terminate the loop
49 while [ -n "$nbdopts" ]; do
55 if [ -z "${f%bs=*}" -o -z "${f%timeout=*}" ]; then
62 # look through the flags and see if any are overridden by the command line
64 while [ -n "$nbdflags" ]; do
66 nbdflags
=${nbdflags#*,}
70 if [ "$f" = "ro" -o "$f" = "rw" ]; then
74 fsopts
=${fsopts+$fsopts,}$f
79 fsopts
=${fsopts+$fsopts,}${nbdrw}
81 # XXX better way to wait for the device to be made?
83 while [ ! -b /dev
/nbd0
]; do
84 [ $i -ge 20 ] && exit 1
85 if [ $UDEVVERSION -ge 143 ]; then
86 udevadm settle
--exit-if-exists=/dev
/nbd0
93 nbd-client
$preopts "$nbdserver" "$nbdport" /dev
/nbd0
$opts ||
exit 1
95 # If we didn't get a root= on the command line, then we need to
96 # add the udev rules for mounting the nbd0 device
98 if [ -z "$root" ] || strstr
"$root" "nbd:" || strstr
"$root" "dhcp"; then
99 echo '[ -e /dev/root ] || { info=$(udevadm info --query=env --name=/dev/nbd0); [ -z "${info%%*ID_FS_TYPE*}" ] && { ln -s /dev/nbd0 /dev/root 2>/dev/null; :; };} && rm $job;' \
100 > $hookdir/initqueue
/settled
/nbd.sh
102 printf '/bin/mount -t %s -o %s %s %s\n' \
103 "$nbdfstype" "$fsopts" /dev
/nbd0
"$NEWROOT" \
104 > $hookdir/mount
/01-$$
-nbd.sh
107 # NBD doesn't emit uevents when it gets connected, so kick it
108 echo change
> /sys
/block
/nbd
0/uevent