You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

97 lines
2.1 KiB

#!/bin/sh
. /lib/dracut-lib
PATH=$PATH:/sbin:/usr/sbin
# XXX needs error handling like ifup/dhclient-script
if getarg rdnetdebug; then
exec > /tmp/nbdroot.$1.$$.out
exec 2>> /tmp/nbdroot.$1.$$.out
set -x
fi
# root is in the form root=nbd:server:port:fstype:fsopts:nbdopts
netif="$1"
root="$2"
root=${root#nbd:}
nbdserver=${root%%:*}; root=${root#*:}
nbdport=${root%%:*}; root=${root#*:}
nbdfstype=${root%%:*}; root=${root#*:}
nbdflags=${root%%:*}
nbdopts=${root#*:}
if [ "$nbdopts" = "$nbdflags" ]; then
unset nbdopts
fi
if [ "$nbdflags" = "$nbdfstype" ]; then
unset nbdflags
fi
if [ "$nbdfstype" = "$nbdport" ]; then
unset nbdfstype
fi
if [ -z "$nbdfstype" ]; then
nbdfstype=auto
fi
# look through the NBD options and pull out the ones that need to
# go before the host etc. Append a ',' so we know we terminate the loop
nbdopts=${nbdopts},
while [ -n "$nbdopts" ]; do
f=${nbdopts%%,*}
nbdopts=${nbdopts#*,}
if [ -z "$f" ]; then
break
fi
if [ -z "${f%bs=*}" -o -z "${f%timeout=*}" ]; then
preopts="$preopts $f"
continue
fi
opts="$opts $f"
done
# look through the flags and see if any are overridden by the command line
nbdflags=${nbdflags},
while [ -n "$nbdflags" ]; do
f=${nbdflags%%,*}
nbdflags=${nbdflags#*,}
if [ -z "$f" ]; then
break
fi
if [ "$f" = "ro" -o "$f" = "rw" ]; then
nbdrw=$f
continue
fi
fsopts=${fsopts+$fsopts,}$f
done
getarg ro && nbdrw=ro
getarg rw && nbdrw=rw
fsopts=${fsopts+$fsopts,}${nbdrw}
incol2 /proc/devices nbd || modprobe nbd || exit 1
# XXX better way to wait for the device to be made?
i=0
while [ ! -b /dev/nbd0 ]; do
[ $i -ge 20 ] && exit 1
sleep 0.1
i=$(( $i + 1))
done
# XXX netroot expects to have the handler mount things, but we should
# XXX allow LVM, LUKS, etc over nbd
nbd-client $preopts "$nbdserver" "$nbdport" /dev/nbd0 $opts || exit 1
if ! mount -t $nbdfstype -o$fsopts /dev/nbd0 $NEWROOT; then
# Mount failed, clean up after ourselves so if we try a different
# interface it can succeed
nbd-client -d /dev/nbd0
exit 1
fi
exit 0