Release 2.9.23-4
[nbd.git] / debian / nbd-client.initrd
blob81b8780c412ca9fd8db1adfbfb32772828b1e14d
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 nbdroot*)
13 nbdroot="${x}"
15 root=/dev/nbd*)
16 nbdrootdev="${x#root=}"
17 nbdbasedev="${x#root=/dev/}"
19 esac
20 done
22 # if nbd root is not requested exit early and silently
23 if [ -z "${nbdroot}" ]; then
24 exit 0
27 . /scripts/functions
29 log_begin_msg "Setting up nbd-client"
31 configure_networking
33 x="$nbdroot"
34 # Support setting stuff using DHCP by overloading 'option root-path'
35 case $x in
36 nbdroot=dhcp)
37 x="$ROOTPATH"
39 esac
41 case $x in
42 nbdroot=*,*,*)
43 nbdroot="${x#nbdroot=}"
44 nbdsrv="${nbdroot%%,*}"
45 nbdport="${nbdroot%,*}"
46 nbdport="${nbdport##*,}"
47 # root= parameter overrides three-option nbdroot= parameter
48 if [ -z "$nbdrootdev" ]
49 then
50 nbdbasedev="${nbdroot##*,}"
51 nbdrootdev=/dev/$nbdbasedev
54 nbdroot=*,*)
55 nbdroot="${x#nbdroot=}"
56 nbdsrv="${nbdroot%,*}"
57 nbdport="${nbdroot#*,}"
59 esac
61 nbdrootdev=${nbdrootdev%p*}
62 nbdbasedev=${nbdbasedev%p*}
64 if [ -z "$nbdport" -o -z "$nbdrootdev" ]
65 then
66 log_failure_msg "Insufficient information to set up nbd, quitting (nbdsrv=$nbdsrv nbdport=$nbdport nbdroot=$nbdroot root=$nbdrootdev)"
67 exit 0
70 nondigits=$(echo $nbdport | sed -e 's/[0-9]//g')
71 if [ ! -z "$nondigits" ]
72 then
73 # non-numeric characters, assume a name rather than a port
74 nbdport="-N $nbdport"
77 # Support setting the server's IP address by overloading 'option
78 # root-server'. This is separate from the "ROOTPATH" grabbing above, in
79 # that here we only specify the server's IP address through DHCP, but
80 # expect everything else to be set through the kernel's command line.
81 # Netbooting is a can of worms.
82 if [ "$nbdsrv" = "dhcp" ]
83 then
84 nbdsrv=$ROOTSERVER
87 if [ -z "$nbdsrv" ]
88 then
89 log_failure_msg "Insufficient information to set up nbd, quitting (nbdsrv=$nbdsrv nbdport=$nbdport nbdroot=$nbdroot root=$nbdrootdev)"
90 exit 0
93 /sbin/nbd-client $nbdsrv $nbdport $nbdrootdev -persist
94 # This should be removed once the cfq scheduler no longer deadlocks nbd
95 # devices
96 if grep '\[cfq\]' /sys/block/$nbdbasedev/queue/scheduler >/dev/null
97 then
98 echo deadline > /sys/block/$nbdbasedev/queue/scheduler