]>
Commit | Line | Data |
---|---|---|
2b117123 | 1 | #!/bin/sh |
cc02093d HH |
2 | # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- |
3 | # ex: ts=8 sw=4 sts=4 et filetype=sh | |
2b117123 | 4 | |
c9f1e3d1 | 5 | type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh |
2b117123 | 6 | |
fb59f4c9 | 7 | PATH=/usr/sbin:/usr/bin:/sbin:/bin |
2b117123 | 8 | |
268de90f PS |
9 | # Huh? Empty $1? |
10 | [ -z "$1" ] && exit 1 | |
11 | ||
12 | # Huh? Empty $2? | |
13 | [ -z "$2" ] && exit 1 | |
14 | ||
15 | # Huh? Empty $3? | |
16 | [ -z "$3" ] && exit 1 | |
17 | ||
50e7ff76 | 18 | # root is in the form root=nbd:srv:port[:fstype[:rootflags[:nbdopts]]] |
2b117123 DD |
19 | netif="$1" |
20 | root="$2" | |
9cdfd735 | 21 | NEWROOT="$3" |
2b117123 | 22 | |
50e7ff76 PS |
23 | # If it's not nbd we don't continue |
24 | [ "${root%%:*}" = "nbd" ] || return | |
25 | ||
2b117123 DD |
26 | root=${root#nbd:} |
27 | nbdserver=${root%%:*}; root=${root#*:} | |
28 | nbdport=${root%%:*}; root=${root#*:} | |
29 | nbdfstype=${root%%:*}; root=${root#*:} | |
30 | nbdflags=${root%%:*} | |
31 | nbdopts=${root#*:} | |
32 | ||
33 | if [ "$nbdopts" = "$nbdflags" ]; then | |
34 | unset nbdopts | |
35 | fi | |
36 | if [ "$nbdflags" = "$nbdfstype" ]; then | |
37 | unset nbdflags | |
38 | fi | |
39 | if [ "$nbdfstype" = "$nbdport" ]; then | |
40 | unset nbdfstype | |
41 | fi | |
42 | if [ -z "$nbdfstype" ]; then | |
43 | nbdfstype=auto | |
44 | fi | |
45 | ||
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 | |
48 | nbdopts=${nbdopts}, | |
49 | while [ -n "$nbdopts" ]; do | |
50 | f=${nbdopts%%,*} | |
51 | nbdopts=${nbdopts#*,} | |
52 | if [ -z "$f" ]; then | |
53 | break | |
54 | fi | |
55 | if [ -z "${f%bs=*}" -o -z "${f%timeout=*}" ]; then | |
56 | preopts="$preopts $f" | |
57 | continue | |
58 | fi | |
59 | opts="$opts $f" | |
60 | done | |
61 | ||
62 | # look through the flags and see if any are overridden by the command line | |
63 | nbdflags=${nbdflags}, | |
64 | while [ -n "$nbdflags" ]; do | |
65 | f=${nbdflags%%,*} | |
66 | nbdflags=${nbdflags#*,} | |
67 | if [ -z "$f" ]; then | |
68 | break | |
69 | fi | |
70 | if [ "$f" = "ro" -o "$f" = "rw" ]; then | |
71 | nbdrw=$f | |
72 | continue | |
73 | fi | |
74 | fsopts=${fsopts+$fsopts,}$f | |
75 | done | |
76 | ||
77 | getarg ro && nbdrw=ro | |
78 | getarg rw && nbdrw=rw | |
79 | fsopts=${fsopts+$fsopts,}${nbdrw} | |
80 | ||
2b117123 DD |
81 | # XXX better way to wait for the device to be made? |
82 | i=0 | |
83 | while [ ! -b /dev/nbd0 ]; do | |
84 | [ $i -ge 20 ] && exit 1 | |
cf476dbc HH |
85 | if [ $UDEVVERSION -ge 143 ]; then |
86 | udevadm settle --exit-if-exists=/dev/nbd0 | |
87 | else | |
88 | sleep 0.1 | |
89 | fi | |
2b117123 DD |
90 | i=$(( $i + 1)) |
91 | done | |
92 | ||
00c5ab3e HH |
93 | nbd-client $preopts "$nbdserver" "$nbdport" /dev/nbd0 $opts || exit 1 |
94 | ||
8bd5873f DD |
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 | |
cee3b896 HH |
97 | root=$(getarg root=) |
98 | if [ -z "$root" ] || strstr "$root" "nbd:" || strstr "$root" "dhcp"; then | |
d84c1df9 | 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;' \ |
0b53ca70 | 100 | > $hookdir/initqueue/settled/nbd.sh |
5a8d8dfb | 101 | |
97190241 | 102 | printf '/bin/mount -t %s -o %s %s %s\n' \ |
cc02093d | 103 | "$nbdfstype" "$fsopts" /dev/nbd0 "$NEWROOT" \ |
0b53ca70 | 104 | > $hookdir/mount/01-$$-nbd.sh |
8bd5873f | 105 | fi |
2b117123 | 106 | |
8bd5873f DD |
107 | # NBD doesn't emit uevents when it gets connected, so kick it |
108 | echo change > /sys/block/nbd0/uevent | |
cee3b896 | 109 | udevadm settle |
fb67e4aa | 110 | need_shutdown |
2b117123 | 111 | exit 0 |