]> git.ipfire.org Git - thirdparty/dracut.git/blob - modules.d/95iscsi/parse-iscsiroot.sh
7a64d888339e8f0e4c0a8d6d03a85a9a6da31748
[thirdparty/dracut.git] / modules.d / 95iscsi / parse-iscsiroot.sh
1 #!/bin/sh
2 #
3 # Preferred format:
4 # root=iscsi:[<servername>]:[<protocol>]:[<port>]:[<LUN>]:<targetname>
5 # [root=*] netroot=iscsi:[<servername>]:[<protocol>]:[<port>]:[<LUN>]:<targetname>
6 #
7 # Legacy formats:
8 # [net]root=[iscsi] iscsiroot=[<servername>]:[<protocol>]:[<port>]:[<LUN>]:<targetname>
9 # [net]root=[iscsi] iscsi_firmware
10 #
11 # root= takes precedence over netroot= if root=iscsi[...]
12 #
13
14 # This script is sourced, so root should be set. But let's be paranoid
15 [ -z "$root" ] && root=$(getarg root=)
16 if [ -z "$netroot" ]; then
17 for nroot in $(getargs netroot=); do
18 [ "${nroot%%:*}" = "iscsi" ] && break
19 done
20 if [ "${nroot%%:*}" = "iscsi" ]; then
21 netroot="$nroot"
22 else
23 for nroot in $(getargs netroot=); do
24 [ "${nroot%%:*}" = "dhcp" ] && break
25 done
26 netroot="$nroot"
27 fi
28 fi
29 [ -z "$iscsiroot" ] && iscsiroot=$(getarg iscsiroot=)
30 [ -z "$iscsi_firmware" ] && getargbool 0 rd.iscsi.firmware -y iscsi_firmware && iscsi_firmware="1"
31
32 [ -n "$iscsiroot" ] && [ -n "$iscsi_firmware" ] && die "Mixing iscsiroot and iscsi_firmware is dangerous"
33
34 type write_fs_tab >/dev/null 2>&1 || . /lib/fs-lib.sh
35
36 # Root takes precedence over netroot
37 if [ "${root%%:*}" = "iscsi" ] ; then
38 if [ -n "$netroot" ] ; then
39 echo "Warning: root takes precedence over netroot. Ignoring netroot"
40 fi
41 netroot=$root
42 # if root is not specified try to mount the whole iSCSI LUN
43 printf 'ENV{DEVTYPE}!="partition", SYMLINK=="disk/by-path/*-iscsi-*-*", SYMLINK+="root"\n' >> /etc/udev/rules.d/99-iscsi-root.rules
44 [ -n "$DRACUT_SYSTEMD" ] && systemctl is-active systemd-udevd && udevadm control --reload-rules
45 root=/dev/root
46
47 write_fs_tab /dev/root
48 fi
49
50 # If it's not empty or iscsi we don't continue
51 for nroot in $(getargs netroot); do
52 [ "${nroot%%:*}" = "iscsi" ] || continue
53 netroot="$nroot"
54 break
55 done
56
57 # Root takes precedence over netroot
58 if [ "${root}" = "/dev/root" ] && getarg "netroot=dhcp" ; then
59 # if root is not specified try to mount the whole iSCSI LUN
60 printf 'ENV{DEVTYPE}!="partition", SYMLINK=="disk/by-path/*-iscsi-*-*", SYMLINK+="root"\n' >> /etc/udev/rules.d/99-iscsi-root.rules
61 [ -n "$DRACUT_SYSTEMD" ] && systemctl is-active systemd-udevd && udevadm control --reload-rules
62 fi
63
64 if [ -n "$iscsiroot" ] ; then
65 [ -z "$netroot" ] && netroot=$root
66
67 # @deprecated
68 echo "Warning: Argument iscsiroot is deprecated and might be removed in a future"
69 echo "release. See 'man dracut.kernel' for more information."
70
71 # Accept iscsiroot argument?
72 [ -z "$netroot" ] || [ "$netroot" = "iscsi" ] || \
73 die "Argument iscsiroot only accepted for empty root= or [net]root=iscsi"
74
75 # Override root with iscsiroot content?
76 [ -z "$netroot" ] || [ "$netroot" = "iscsi" ] && netroot=iscsi:$iscsiroot
77 fi
78
79 # iscsi_firmware does not need argument checking
80 if [ -n "$iscsi_firmware" ]; then
81 if [ "$root" != "dhcp" ] && [ "$netroot" != "dhcp" ]; then
82 [ -z "$netroot" ] && netroot=iscsi:
83 fi
84 modprobe -b -q iscsi_boot_sysfs 2>/dev/null
85 modprobe -b -q iscsi_ibft
86 # if no ip= is given, but firmware
87 echo "[ -f '/tmp/iscsistarted-firmware' ]" > $hookdir/initqueue/finished/iscsi_started.sh
88 initqueue --unique --online /sbin/iscsiroot online "iscsi:" "$NEWROOT"
89 initqueue --unique --onetime --timeout /sbin/iscsiroot timeout "iscsi:" "$NEWROOT"
90 initqueue --unique --onetime --settled /sbin/iscsiroot online "iscsi:" "'$NEWROOT'"
91 fi
92
93 # ISCSI actually supported?
94 if ! [ -e /sys/module/iscsi_tcp ]; then
95 modprobe -b -q iscsi_tcp || die "iscsiroot requested but kernel/initrd does not support iscsi"
96 fi
97
98 modprobe --all -b -q qla4xxx cxgb3i cxgb4i bnx2i be2iscsi
99
100 if [ -n "$netroot" ] && [ "$root" != "/dev/root" ] && [ "$root" != "dhcp" ]; then
101 if ! getargbool 1 rd.neednet >/dev/null || ! getarg "ip="; then
102 initqueue --unique --onetime --settled /sbin/iscsiroot dummy "'$netroot'" "'$NEWROOT'"
103 fi
104 fi
105
106 if arg=$(getarg rd.iscsi.initiator -d iscsi_initiator=) && [ -n "$arg" ] && ! [ -f /run/initiatorname.iscsi ] ; then
107 iscsi_initiator=$arg
108 echo "InitiatorName=$iscsi_initiator" > /run/initiatorname.iscsi
109 ln -fs /run/initiatorname.iscsi /dev/.initiatorname.iscsi
110 if ! [ -e /etc/iscsi/initiatorname.iscsi ]; then
111 mkdir -p /etc/iscsi
112 ln -fs /run/initiatorname.iscsi /etc/iscsi/initiatorname.iscsi
113 if [ -n "$DRACUT_SYSTEMD" ]; then
114 systemctl try-restart iscsid
115 # FIXME: iscsid is not yet ready, when the service is :-/
116 sleep 1
117 fi
118 fi
119 fi
120
121 # If not given on the cmdline and initiator-name available via iBFT
122 if [ -z $iscsi_initiator ] && [ -f /sys/firmware/ibft/initiator/initiator-name ] && ! [ -f /tmp/iscsi_set_initiator ]; then
123 iscsi_initiator=$(while read line || [ -n "$line" ]; do echo $line;done < /sys/firmware/ibft/initiator/initiator-name)
124 if [ -n "$iscsi_initiator" ]; then
125 echo "InitiatorName=$iscsi_initiator" > /run/initiatorname.iscsi
126 rm -f /etc/iscsi/initiatorname.iscsi
127 mkdir -p /etc/iscsi
128 ln -fs /run/initiatorname.iscsi /etc/iscsi/initiatorname.iscsi
129 > /tmp/iscsi_set_initiator
130 if [ -n "$DRACUT_SYSTEMD" ]; then
131 systemctl try-restart iscsid
132 # FIXME: iscsid is not yet ready, when the service is :-/
133 sleep 1
134 fi
135 fi
136 fi
137
138 if [ -z "$netroot" ] || ! [ "${netroot%%:*}" = "iscsi" ]; then
139 return 1
140 fi
141
142 initqueue --unique --onetime --timeout /sbin/iscsiroot timeout "$netroot" "$NEWROOT"
143
144 for nroot in $(getargs netroot); do
145 [ "${nroot%%:*}" = "iscsi" ] || continue
146 type parse_iscsi_root >/dev/null 2>&1 || . /lib/net-lib.sh
147 parse_iscsi_root "$nroot" || return 1
148 netroot_enc=$(str_replace "$nroot" '/' '\2f')
149 echo "[ -f '/tmp/iscsistarted-$netroot_enc' ]" > $hookdir/initqueue/finished/iscsi_started.sh
150 done
151
152 # Done, all good!
153 rootok=1
154
155 # Shut up init error check
156 [ -z "$root" ] && root="iscsi"