]> git.ipfire.org Git - thirdparty/dracut.git/blob - modules.d/95iscsi/iscsiroot
7439af380079d62d6acda59e89b22efbb294152f
[thirdparty/dracut.git] / modules.d / 95iscsi / iscsiroot
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
41 [ -e /tmp/root.info ] && . /tmp/root.info
42
43 if getargbool 0 rd.iscsi.firmware -y iscsi_firmware ; then
44 if [ -n "${root%%block:*}" ]; then
45 # if root is not specified try to mount the whole iSCSI LUN
46 printf 'ENV{DEVTYPE}!="partition", SYMLINK=="disk/by-path/*-iscsi-*-*", SYMLINK+="root"\n' >> /etc/udev/rules.d/99-iscsi-root.rules
47 fi
48 iscsistart -b
49 exit 0
50 fi
51
52 # override conf settings by command line options
53 arg=$(getargs rd.iscsi.initiator iscsi_initiator=)
54 [ -n "$arg" ] && iscsi_initiator=$arg
55 arg=$(getargs rd.iscsi.target.name iscsi_target_name=)
56 [ -n "$arg" ] && iscsi_target_name=$arg
57 arg=$(getargs rd.iscsi.target.ip iscsi_target_ip)
58 [ -n "$arg" ] && iscsi_target_ip=$arg
59 arg=$(getargs rd.iscsi.target.port iscsi_target_port=)
60 [ -n "$arg" ] && iscsi_target_port=$arg
61 arg=$(getargs rd.iscsi.target.group iscsi_target_group=)
62 [ -n "$arg" ] && iscsi_target_group=$arg
63 arg=$(getargs rd.iscsi.username iscsi_username=)
64 [ -n "$arg" ] && iscsi_username=$arg
65 arg=$(getargs rd.iscsi.password iscsi_password)
66 [ -n "$arg" ] && iscsi_password=$arg
67 arg=$(getargs rd.iscsi.in.username iscsi_in_username=)
68 [ -n "$arg" ] && iscsi_in_username=$arg
69 arg=$(getargs rd.iscsi.in.password iscsi_in_password=)
70 [ -n "$arg" ] && iscsi_in_password=$arg
71
72 handle_netroot()
73 {
74 iroot=$1
75 # override conf/commandline options by dhcp root_path
76 # FIXME this assumes that all values have been provided
77 OLDIFS="$IFS"
78 IFS=@
79 set $iroot
80 if [ $# -gt 1 ]; then
81 authinfo=$1; shift
82 iroot=$*
83 # allow empty authinfo to allow having an @ in iscsi_target_name like this:
84 # netroot=iscsi:@192.168.1.100::3260::iqn.2009-01.com.example:testdi@sk
85 if [ -n "$authinfo" ]; then
86 IFS=:
87 set $authinfo
88 iscsi_username=$1
89 iscsi_password=$2
90 if [ $# -gt 2 ]; then
91 iscsi_in_username=$3
92 iscsi_in_password=$4
93 fi
94 fi
95 fi
96
97 IFS="$OLDIFS"
98
99 local v=${iroot}:
100 local i
101 set --
102 while [ -n "$v" ]; do
103 if [ "${v#\[*:*:*\]:}" != "$v" ]; then
104 # handle IPv6 address
105 i="${v%%\]:*}"
106 i="${i##\[}"
107 set -- "$@" "$i"
108 v=${v#\[$i\]:}
109 else
110 set -- "$@" "${v%%:*}"
111 v=${v#*:}
112 fi
113 done
114 iscsi_target_ip=$1; shift
115 iscsi_protocol=$1; shift # ignored
116 iscsi_target_port=$1; shift
117 iscsi_lun=$1; shift
118 IFS=:
119 iscsi_target_name=$*
120 IFS="$OLDIFS"
121 # XXX is this needed?
122 getarg ro && iscsirw=ro
123 getarg rw && iscsirw=rw
124 fsopts=${fsopts+$fsopts,}${iscsirw}
125
126 if [ -z $iscsi_initiator ]; then
127 # XXX Where are these from?
128 [ -f /etc/initiatorname.iscsi ] && . /etc/initiatorname.iscsi
129 [ -f /etc/iscsi/initiatorname.iscsi ] && . /etc/iscsi/initiatorname.iscsi
130 iscsi_initiator=$InitiatorName
131
132 # XXX rfc3720 says 'SCSI Initiator Name: The iSCSI Initiator Name specifies
133 # the worldwide unique name of the initiator.' Could we use hostname/ip
134 # if missing?
135 fi
136
137 if [ -z $iscsi_target_port ]; then
138 iscsi_target_port=3260
139 fi
140
141 if [ -z $iscsi_target_group ]; then
142 iscsi_target_group=1
143 fi
144
145 if [ -z $iscsi_initiator ]; then
146 # XXX is this correct?
147 iscsi_initiator=$(iscsi-iname)
148 fi
149
150 if [ -z $iscsi_lun ]; then
151 iscsi_lun=0
152 fi
153
154 echo "InitiatorName='$iscsi_initiator'" > /run/initiatorname.iscsi
155 ln -s /run/initiatorname.iscsi /dev/.initiatorname.iscsi
156
157 # FIXME $iscsi_protocol??
158
159 if [ -n "${root%%block:*}" ]; then
160 # if root is not specified try to mount the whole iSCSI LUN
161 printf 'SYMLINK=="disk/by-path/*-iscsi-*-%s", SYMLINK+="root"\n' $iscsi_lun >> /etc/udev/rules.d/99-iscsi-root.rules
162 fi
163
164 # inject new exit_if_exists
165 echo 'settle_exit_if_exists="--exit-if-exists=/dev/root"; rm "$job"' > $hookdir/initqueue/iscsi-settle.sh
166
167 # force udevsettle to break
168 > $hookdir/initqueue/work
169
170 iscsistart -i $iscsi_initiator -t $iscsi_target_name \
171 -g $iscsi_target_group -a $iscsi_target_ip \
172 -p $iscsi_target_port \
173 ${iscsi_username+-u $iscsi_username} \
174 ${iscsi_password+-w $iscsi_password} \
175 ${iscsi_in_username+-U $iscsi_in_username} \
176 ${iscsi_in_password+-W $iscsi_in_password} || :
177
178 # install mount script
179 if [ -n "${root%%block:*}" ]; then
180 # if root is not specified try to mount the whole iSCSI LUN
181 echo "iscsi_lun=$iscsi_lun . /bin/mount-lun.sh " > $hookdir/mount/01-$$-iscsi.sh
182 fi
183 }
184
185 # loop over all netroot parameter
186 if getarg netroot; then
187 for nroot in $(getargs netroot); do
188 [ "${netroot%%:*}" = "iscsi" ] || continue
189 handle_netroot ${nroot##iscsi:}
190 done
191 else
192 handle_netroot $iroot
193 fi
194
195 # now we have a root filesystem somewhere in /dev/sda*
196 # let the normal block handler handle root=
197 exit 0