]>
Commit | Line | Data |
---|---|---|
ac4ded91 | 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 | |
580bb541 PS |
4 | # |
5 | # This implementation is incomplete: Discovery mode is not implemented and | |
6 | # the argument handling doesn't follow currently agreed formats. This is mainly | |
3b403b32 | 7 | # because rfc4173 does not say anything about iscsi_initiator but open-iscsi's |
580bb541 PS |
8 | # iscsistart needs this. |
9 | # | |
ac4ded91 | 10 | |
c9f1e3d1 | 11 | type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh |
ac4ded91 | 12 | |
fb59f4c9 | 13 | PATH=/usr/sbin:/usr/bin:/sbin:/bin |
ac4ded91 | 14 | |
268de90f PS |
15 | # Huh? Empty $1? |
16 | [ -z "$1" ] && exit 1 | |
17 | ||
18 | # Huh? Empty $2? | |
19 | [ -z "$2" ] && exit 1 | |
20 | ||
3b403b32 | 21 | # Huh? Empty $3? This isn't really necessary, since NEWROOT isn't |
268de90f PS |
22 | # used here. But let's be consistent |
23 | [ -z "$3" ] && exit 1 | |
24 | ||
ac4ded91 HH |
25 | # root is in the form root=iscsi:[<servername>]:[<protocol>]:[<port>]:[<LUN>]:<targetname> |
26 | netif="$1" | |
9babe97e | 27 | iroot="$2" |
ac4ded91 | 28 | |
0375106c | 29 | source_all /etc/conf.d |
580bb541 | 30 | |
50e7ff76 | 31 | # If it's not iscsi we don't continue |
9babe97e HH |
32 | [ "${iroot%%:*}" = "iscsi" ] || exit 1 |
33 | ||
34 | iroot=${iroot#iscsi:} | |
50e7ff76 PS |
35 | |
36 | # XXX modprobe crc32c should go in the cmdline parser, but I haven't yet | |
37 | # figured out a way how to check whether this is built-in or not | |
169f1671 | 38 | modprobe crc32c 2>/dev/null |
580bb541 | 39 | |
9babe97e HH |
40 | |
41 | [ -e /tmp/root.info ] && . /tmp/root.info | |
42 | ||
3fa9d4d7 HH |
43 | [ -e /sys/module/bnx2i ] && iscsiuio |
44 | ||
b43f4df5 | 45 | if getargbool 0 rd.iscsi.firmware -y iscsi_firmware ; then |
a3f4e770 HH |
46 | if [ -n "${root%%block:*}" ]; then |
47 | # if root is not specified try to mount the whole iSCSI LUN | |
cc02093d | 48 | printf 'ENV{DEVTYPE}!="partition", SYMLINK=="disk/by-path/*-iscsi-*-*", SYMLINK+="root"\n' >> /etc/udev/rules.d/99-iscsi-root.rules |
2a3faa2d | 49 | udevadm control --reload |
a3f4e770 HH |
50 | fi |
51 | iscsistart -b | |
52 | exit 0 | |
580bb541 PS |
53 | fi |
54 | ||
43f21852 HH |
55 | unset iscsi_initiator iscsi_target_name iscsi_target_ip iscsi_target_port |
56 | unset iscsi_target_group iscsi_protocol iscsirw iscsi_lun | |
57 | unset iscsi_username iscsi_password | |
58 | unset iscsi_in_username iscsi_in_password | |
59 | ||
580bb541 | 60 | # override conf settings by command line options |
b43f4df5 | 61 | arg=$(getargs rd.iscsi.initiator iscsi_initiator=) |
580bb541 | 62 | [ -n "$arg" ] && iscsi_initiator=$arg |
b43f4df5 | 63 | arg=$(getargs rd.iscsi.target.name iscsi_target_name=) |
580bb541 | 64 | [ -n "$arg" ] && iscsi_target_name=$arg |
b43f4df5 | 65 | arg=$(getargs rd.iscsi.target.ip iscsi_target_ip) |
580bb541 | 66 | [ -n "$arg" ] && iscsi_target_ip=$arg |
b43f4df5 | 67 | arg=$(getargs rd.iscsi.target.port iscsi_target_port=) |
580bb541 | 68 | [ -n "$arg" ] && iscsi_target_port=$arg |
b43f4df5 | 69 | arg=$(getargs rd.iscsi.target.group iscsi_target_group=) |
580bb541 | 70 | [ -n "$arg" ] && iscsi_target_group=$arg |
b43f4df5 | 71 | arg=$(getargs rd.iscsi.username iscsi_username=) |
580bb541 | 72 | [ -n "$arg" ] && iscsi_username=$arg |
b43f4df5 | 73 | arg=$(getargs rd.iscsi.password iscsi_password) |
580bb541 | 74 | [ -n "$arg" ] && iscsi_password=$arg |
b43f4df5 | 75 | arg=$(getargs rd.iscsi.in.username iscsi_in_username=) |
580bb541 | 76 | [ -n "$arg" ] && iscsi_in_username=$arg |
b43f4df5 | 77 | arg=$(getargs rd.iscsi.in.password iscsi_in_password=) |
580bb541 | 78 | [ -n "$arg" ] && iscsi_in_password=$arg |
ac4ded91 | 79 | |
3b403b32 | 80 | handle_netroot() |
169f1671 HH |
81 | { |
82 | iroot=$1 | |
83 | # override conf/commandline options by dhcp root_path | |
84 | # FIXME this assumes that all values have been provided | |
85 | OLDIFS="$IFS" | |
86 | IFS=@ | |
87 | set $iroot | |
88 | if [ $# -gt 1 ]; then | |
3b403b32 | 89 | authinfo=$1; shift |
cc02093d | 90 | iroot=$* |
766968bb HG |
91 | # allow empty authinfo to allow having an @ in iscsi_target_name like this: |
92 | # netroot=iscsi:@192.168.1.100::3260::iqn.2009-01.com.example:testdi@sk | |
cc02093d | 93 | if [ -n "$authinfo" ]; then |
169f1671 HH |
94 | IFS=: |
95 | set $authinfo | |
96 | iscsi_username=$1 | |
97 | iscsi_password=$2 | |
98 | if [ $# -gt 2 ]; then | |
cc02093d HH |
99 | iscsi_in_username=$3 |
100 | iscsi_in_password=$4 | |
169f1671 | 101 | fi |
cc02093d | 102 | fi |
3b403b32 | 103 | fi |
169f1671 HH |
104 | |
105 | IFS="$OLDIFS" | |
106 | ||
107 | local v=${iroot}: | |
108 | local i | |
3b403b32 | 109 | set -- |
169f1671 | 110 | while [ -n "$v" ]; do |
cc02093d HH |
111 | if [ "${v#\[*:*:*\]:}" != "$v" ]; then |
112 | # handle IPv6 address | |
113 | i="${v%%\]:*}" | |
114 | i="${i##\[}" | |
115 | set -- "$@" "$i" | |
116 | v=${v#\[$i\]:} | |
3b403b32 | 117 | else |
cc02093d HH |
118 | set -- "$@" "${v%%:*}" |
119 | v=${v#*:} | |
120 | fi | |
169f1671 HH |
121 | done |
122 | iscsi_target_ip=$1; shift | |
123 | iscsi_protocol=$1; shift # ignored | |
124 | iscsi_target_port=$1; shift | |
125 | iscsi_lun=$1; shift | |
126 | IFS=: | |
127 | iscsi_target_name=$* | |
128 | IFS="$OLDIFS" | |
580bb541 | 129 | # XXX is this needed? |
169f1671 HH |
130 | getarg ro && iscsirw=ro |
131 | getarg rw && iscsirw=rw | |
132 | fsopts=${fsopts+$fsopts,}${iscsirw} | |
580bb541 | 133 | |
169f1671 | 134 | if [ -z $iscsi_initiator ]; then |
580bb541 | 135 | # XXX Where are these from? |
cc02093d HH |
136 | [ -f /etc/initiatorname.iscsi ] && . /etc/initiatorname.iscsi |
137 | [ -f /etc/iscsi/initiatorname.iscsi ] && . /etc/iscsi/initiatorname.iscsi | |
138 | iscsi_initiator=$InitiatorName | |
580bb541 PS |
139 | |
140 | # XXX rfc3720 says 'SCSI Initiator Name: The iSCSI Initiator Name specifies | |
141 | # the worldwide unique name of the initiator.' Could we use hostname/ip | |
142 | # if missing? | |
169f1671 | 143 | fi |
580bb541 | 144 | |
50acb197 HH |
145 | if [ -z $iscsi_initiator ]; then |
146 | if [ -f /sys/firmware/ibft/initiator/initiator-name ]; then | |
147 | iscsi_initiator=$(while read line; do echo $line;done < /sys/firmware/ibft/initiator-name) | |
148 | fi | |
149 | fi | |
150 | ||
169f1671 | 151 | if [ -z $iscsi_target_port ]; then |
cc02093d | 152 | iscsi_target_port=3260 |
169f1671 | 153 | fi |
580bb541 | 154 | |
169f1671 | 155 | if [ -z $iscsi_target_group ]; then |
cc02093d | 156 | iscsi_target_group=1 |
169f1671 | 157 | fi |
ac4ded91 | 158 | |
169f1671 | 159 | if [ -z $iscsi_initiator ]; then |
580bb541 | 160 | # XXX is this correct? |
cc02093d | 161 | iscsi_initiator=$(iscsi-iname) |
169f1671 | 162 | fi |
580bb541 | 163 | |
169f1671 | 164 | if [ -z $iscsi_lun ]; then |
cc02093d | 165 | iscsi_lun=0 |
169f1671 | 166 | fi |
4ce19918 | 167 | |
19f3a804 HH |
168 | echo "InitiatorName='$iscsi_initiator'" > /run/initiatorname.iscsi |
169 | ln -s /run/initiatorname.iscsi /dev/.initiatorname.iscsi | |
580bb541 | 170 | |
4ce19918 | 171 | # FIXME $iscsi_protocol?? |
580bb541 | 172 | |
169f1671 | 173 | if [ -n "${root%%block:*}" ]; then |
c094baa0 | 174 | # if root is not specified try to mount the whole iSCSI LUN |
cc02093d | 175 | printf 'SYMLINK=="disk/by-path/*-iscsi-*-%s", SYMLINK+="root"\n' $iscsi_lun >> /etc/udev/rules.d/99-iscsi-root.rules |
169f1671 | 176 | fi |
064b6ea9 | 177 | |
169f1671 | 178 | # inject new exit_if_exists |
0b53ca70 | 179 | echo 'settle_exit_if_exists="--exit-if-exists=/dev/root"; rm "$job"' > $hookdir/initqueue/iscsi-settle.sh |
a52586e8 | 180 | |
169f1671 | 181 | # force udevsettle to break |
0b53ca70 | 182 | > $hookdir/initqueue/work |
a52586e8 | 183 | |
cc02093d HH |
184 | iscsistart -i $iscsi_initiator -t $iscsi_target_name \ |
185 | -g $iscsi_target_group -a $iscsi_target_ip \ | |
186 | -p $iscsi_target_port \ | |
187 | ${iscsi_username+-u $iscsi_username} \ | |
188 | ${iscsi_password+-w $iscsi_password} \ | |
189 | ${iscsi_in_username+-U $iscsi_in_username} \ | |
190 | ${iscsi_in_password+-W $iscsi_in_password} || : | |
580bb541 | 191 | |
c094baa0 | 192 | # install mount script |
169f1671 | 193 | if [ -n "${root%%block:*}" ]; then |
c094baa0 | 194 | # if root is not specified try to mount the whole iSCSI LUN |
0b53ca70 | 195 | echo "iscsi_lun=$iscsi_lun . /bin/mount-lun.sh " > $hookdir/mount/01-$$-iscsi.sh |
169f1671 HH |
196 | fi |
197 | } | |
198 | ||
199 | # loop over all netroot parameter | |
3b403b32 HH |
200 | if getarg netroot; then |
201 | for nroot in $(getargs netroot); do | |
169f1671 | 202 | [ "${netroot%%:*}" = "iscsi" ] || continue |
cc02093d | 203 | handle_netroot ${nroot##iscsi:} |
169f1671 HH |
204 | done |
205 | else | |
206 | handle_netroot $iroot | |
c094baa0 HH |
207 | fi |
208 | ||
fb67e4aa HH |
209 | need_shutdown |
210 | ||
580bb541 PS |
211 | # now we have a root filesystem somewhere in /dev/sda* |
212 | # let the normal block handler handle root= | |
ac4ded91 | 213 | exit 0 |