Release
[nbd.git] / debian / nbd-client.initrd
blob0fd9e368e9b32bba16d720be598b93a2151bc696
1 #!/bin/sh
3 # We don't have any prerequisites
4 case $1 in
5 prereqs)
6 exit 0
7 ;;
8 esac
10 for x in $(cat /proc/cmdline); do
11 case "$x" in
12 nbddev=*)
13 nbddev="${x#nbddev=}"
15 nbdroot=*)
16 nbdroot="${x#nbdroot=}"
18 root=/dev/nbd*)
19 nbddev="${x#root=}"
21 esac
22 done
24 # if nbd root is not requested exit early and silently
25 if [ -z "$nbdroot" ] && [ -z "$nbddev" ]
26 then
27 exit 0
30 . /scripts/functions
32 log_begin_msg "Setting up nbd-client"
34 modprobe nbd
35 wait_for_udev
36 configure_networking
38 # Support setting stuff using DHCP by overloading 'option root-path'
39 case "$nbdroot" in
40 ''|dhcp)
41 nbdroot=$ROOTPATH
43 esac
45 nbdrootdev="$nbddev"
46 nbdbasedev="${nbddev#/dev/}"
48 case "$nbdroot" in
49 *,*,*)
50 nbdsrv="${nbdroot%%,*}"
51 nbdpath="${nbdroot%,*}"
52 nbdpath="${nbdpath##*,}"
53 # root= parameter overrides three-option nbdroot= parameter
54 if [ -z "$nbdrootdev" ]
55 then
56 nbdbasedev="${nbdroot##*,}"
57 nbdrootdev=/dev/$nbdbasedev
60 *,*)
61 nbdsrv="${nbdroot%,*}"
62 nbdport="${nbdroot#*,}"
64 \[*\]:/*)
65 # [ipv6]:/path
66 # Note: this is specifically written to be compatible with NFS
67 # URLs
68 nbdsrv=${nbdroot%\]*}
69 nbdsrv=${nbdsrv#\[}
70 nbdpath=${nbdroot#\[$nbdsrv\]}
71 nbdpath=${nbdpath#:}
73 \[*\]*)
74 # [ipv6]:port/path
75 nbdsrv=${nbdroot%\]*}
76 nbdsrv=${nbdsrv#\[}
77 nbdportpath=${nbdroot#\[$nbdsrv\]}
78 nbdportpath=${nbdportpath#:}
79 nbdport=${nbdportpath%%/*}
80 nbdpath=${nbdportpath#$nbdport/}
82 /*|*:/*)
83 # ipv4:/path
84 # Note: this is specifically written to be compatible with NFS
85 # URLs
86 nbdsrv=${nbdroot%%[:/]*}
87 nbdpath=${nbdroot#$nbdsrv}
88 nbdpath=${nbdpath#:}
91 # ipv4:port/path
92 nbdsrv=${nbdroot%%[:/]*}
93 nbdportpath=${nbdroot#$nbdsrv}
94 nbdportpath=${nbdportpath#:}
95 nbdport=${nbdportpath%%/*}
96 nbdpath=${nbdportpath#$nbdport/}
98 esac
100 nbdrootdev=${nbdrootdev%p*}
101 nbdbasedev=${nbdbasedev%p*}
102 # If host is omitted, use ROOTSERVER from DHCP.
103 case "$nbdsrv" in
104 ''|dhcp)
105 nbdsrv=$ROOTSERVER
107 esac
109 if [ -z "$nbdsrv" ] || [ -z "$nbdrootdev" ] || [ -z "$nbdpath" ]
110 then
111 log_failure_msg "Insufficient information to set up nbd, quitting (nbdroot=$nbdroot, host=$nbdsrv, name=$nbdpath, port=$nbdport, nbd-device=$nbdrootdev)"
112 exit 0
115 # Support defining an alternate launch script with env variable NBDCLIENT.
116 NBDCLIENT=${NBDCLIENT:-/sbin/nbd-client}
117 $NBDCLIENT $nbdsrv -N $nbdpath $nbdport $nbdrootdev -swap -persist -systemd-mark
119 # This should be removed once the cfq scheduler no longer deadlocks nbd
120 # devices
121 if grep -q '\[cfq\]' /sys/block/$nbdbasedev/queue/scheduler
122 then
123 echo deadline > /sys/block/$nbdbasedev/queue/scheduler