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