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