6 # If our prerequisites are not met, fail anyways.
7 require_binaries iscsi-iname iscsiadm iscsid ||
return 1
9 # If hostonly was requested, fail the check if we are not actually
15 [[ -L "/sys/dev/block/$_dev" ]] ||
return
16 cd "$(readlink -f "/sys
/dev
/block
/$_dev")"
17 until [[ -d sys ||
-d iscsi_session
]]; do
20 [[ -d iscsi_session
]]
23 [[ $hostonly ]] ||
[[ $mount_needs ]] && {
25 for_each_host_dev_and_slaves is_iscsi
28 [[ $_is_iscsi == 0 ]] ||
return 255
35 local iface_mac iface_mod
36 # Return the iSCSI offload module for a given MAC address
37 for iface_desc
in $
(iscsiadm
-m iface | cut
-f 2 -d ' '); do
38 iface_mod
=${iface_desc%%,*}
39 iface_mac
=${iface_desc#*,}
40 iface_mac
=${iface_mac%%,*}
41 if [ "$ibft_mac" = "$iface_mac" ] ; then
49 # When iBFT / iscsi_boot is detected:
50 # - Use 'ip=ibft' to set up iBFT network interface
51 # Note: bnx2i is using a different MAC address of iSCSI offloading
52 # so the 'ip=ibft' parameter must not be set
53 # - specify firmware booting cmdline parameter
55 for d
in /sys
/firmware
/* ; do
56 if [ -d ${d}/ethernet0
] ; then
57 read ibft_mac
< ${d}/ethernet
0/mac
58 ibft_mod
=$
(get_ibft_mod
$ibft_mac)
60 if [ -z "$ibft_mod" ] && [ -d ${d}/ethernet1
] ; then
61 read ibft_mac
< ${d}/ethernet
1/mac
62 ibft_mod
=$
(get_ibft_mod
$ibft_mac)
64 if [ -d ${d}/initiator
] ; then
65 if [ ${d##*/} = "ibft" ] && [ "$ibft_mod" != "bnx2i" ] ; then
66 echo -n "rd.iscsi.ibft=1 "
68 echo -n "rd.iscsi.firmware=1"
75 local scsi_path iscsi_lun session c d conn
host flash
76 local iscsi_session iscsi_address iscsi_port iscsi_targetname iscsi_tpgt
78 scsi_path
=${devpath%%/block*}
79 [ "$scsi_path" = "$devpath" ] && return 1
80 iscsi_lun
=${scsi_path##*:}
81 [ "$iscsi_lun" = "$scsi_path" ] && return 1
82 session
=${devpath%%/target*}
83 [ "$session" = "$devpath" ] && return 1
84 iscsi_session
=${session##*/}
85 [ "$iscsi_session" = "$session" ] && return 1
86 host=${session%%/session*}
87 [ "$host" = "$session" ] && return 1
88 iscsi_host
=${host##*/}
90 for flash
in ${host}/flashnode_sess-
* ; do
91 [ ! -e "$flash/is_boot_target" ] && continue
92 is_boot
=$
(cat $flash/is_boot_target
)
93 if [ $is_boot -eq 1 ] ; then
94 # qla4xxx flashnode session; skip iBFT discovery
95 iscsi_initiator
=$
(cat /sys
/class
/iscsi_host
/${iscsi_host}/initiatorname
)
96 echo "rd.iscsi.initiator=${iscsi_initiator}"
101 for d
in ${session}/* ; do
105 conn
=${d}/iscsi_connection
/${c}
106 if [ -d ${conn} ] ; then
107 iscsi_address
=$
(cat ${conn}/persistent_address
)
108 iscsi_port
=$
(cat ${conn}/persistent_port
)
112 if [ -d ${d}/${iscsi_session} ] ; then
113 iscsi_initiator
=$
(cat ${d}/${iscsi_session}/initiatorname
)
114 iscsi_targetname
=$
(cat ${d}/${iscsi_session}/targetname
)
120 [ -z "$iscsi_address" ] && return
121 local_address
=$
(ip
-o route get to
$iscsi_address |
sed -n 's/.*src \([0-9a-f.:]*\).*/\1/p')
122 ifname
=$
(ip
-o route get to
$iscsi_address |
sed -n 's/.*dev \([^ ]*\).*/\1/p')
124 #follow ifcfg settings for boot protocol
125 bootproto
=$
(sed -n "/BOOTPROTO/s/BOOTPROTO='\([[:alpha:]]*6\?\)4\?'/\1/p" /etc
/sysconfig
/network
/ifcfg-
$ifname)
126 if [ $bootproto ]; then
127 printf 'ip=%s:%s ' ${ifname} ${bootproto}
129 printf 'ip=%s:static ' ${ifname}
132 if [ -e /sys
/class
/net
/$ifname/address
] ; then
133 ifmac
=$
(cat /sys
/class
/net
/$ifname/address
)
134 printf 'ifname=%s:%s ' ${ifname} ${ifmac}
137 if [ -n "$iscsi_address" -a -n "$iscsi_targetname" ] ; then
138 if [ -n "$iscsi_port" -a "$iscsi_port" -eq 3260 ] ; then
141 if [ -n "$iscsi_lun" -a "$iscsi_lun" -eq 0 ] ; then
144 # In IPv6 case rd.iscsi.initatior= must pass address in [] brackets
145 case "$iscsi_address" in
147 iscsi_address
="[$iscsi_address]"
150 # Must be two separate lines, so that "sort | uniq" commands later
151 # can sort out rd.iscsi.initiator= duplicates
152 echo "rd.iscsi.initiator=${iscsi_initiator}"
153 echo "netroot=iscsi:${iscsi_address}::${iscsi_port}:${iscsi_lun}:${iscsi_targetname}"
160 install_softiscsi
() {
161 [ -d /sys
/firmware
/ibft
] && return 0
167 [[ -L "/sys/dev/block/$_dev" ]] ||
return
168 iscsi_dev
=$
(cd -P /sys
/dev
/block
/$_dev; echo $PWD)
169 install_iscsiroot
$iscsi_dev
172 for_each_host_dev_and_slaves_all is_softiscsi ||
return 255
178 echo network rootfs-block
183 local _arch
=$
(uname
-m)
184 local _funcs
='iscsi_register_transport'
186 instmods bnx2i qla4xxx cxgb3i cxgb4i be2iscsi qedi
187 hostonly
="" instmods iscsi_tcp iscsi_ibft crc32c iscsi_boot_sysfs
189 if [ "$_arch" = "s390" -o "$_arch" = "s390x" ]; then
190 _s390drivers
="=drivers/s390/scsi"
193 dracut_instmods
-o -s ${_funcs} =drivers
/scsi
${_s390drivers:+"$_s390drivers"}
198 local _iscsiconf
=$
(install_ibft
)
200 if [ "$_iscsiconf" ] ; then
210 inst_multiple
-o iscsiuio
211 inst_libdir_file
'libgcc_s.so*'
212 inst_multiple umount iscsi-iname iscsiadm iscsid
215 $systemdsystemunitdir/iscsid.socket \
216 $systemdsystemunitdir/iscsid.service \
217 $systemdsystemunitdir/iscsiuio.service \
218 $systemdsystemunitdir/iscsiuio.socket \
219 $systemdsystemunitdir/sockets.target.wants
/iscsid.socket \
220 $systemdsystemunitdir/sockets.target.wants
/iscsiuio.socket
222 if [[ $hostonly ]]; then
223 inst_dir $
(/usr
/bin
/find /etc
/iscsi
)
225 inst_simple
/etc
/iscsi
/iscsid.conf
228 # Detect iBFT and perform mandatory steps
229 if [[ $hostonly_cmdline == "yes" ]] ; then
230 local _iscsiconf
=$
(cmdline
)
231 [[ $_iscsiconf ]] && printf "%s\n" "$_iscsiconf" >> "${initdir}/etc/cmdline.d/95iscsi.conf"
234 inst_hook cmdline
90 "$moddir/parse-iscsiroot.sh"
235 inst_hook cleanup
90 "$moddir/cleanup-iscsi.sh"
236 inst
"$moddir/iscsiroot.sh" "/sbin/iscsiroot"
237 if ! dracut_module_included
"systemd"; then
238 inst
"$moddir/mount-lun.sh" "/bin/mount-lun.sh"
241 $systemdsystemunitdir/iscsi.service \
242 $systemdsystemunitdir/iscsid.service \
243 $systemdsystemunitdir/iscsid.socket \
244 $systemdsystemunitdir/iscsiuio.service \
245 $systemdsystemunitdir/iscsiuio.socket \
248 mkdir
-p "${initdir}/$systemdsystemunitdir/sockets.target.wants"
253 ln_r
"$systemdsystemunitdir/${i}" "$systemdsystemunitdir/sockets.target.wants/${i}"
256 mkdir
-p "${initdir}/$systemdsystemunitdir/basic.target.wants"
261 ln_r
"$systemdsystemunitdir/${i}" "$systemdsystemunitdir/basic.target.wants/${i}"
264 # Make sure iscsid is started after dracut-cmdline and ready for the initqueue
265 mkdir
-p "${initdir}/$systemdsystemunitdir/iscsid.service.d"
268 echo "After=dracut-cmdline.service"
269 echo "Before=dracut-initqueue.service"
270 ) > "${initdir}/$systemdsystemunitdir/iscsid.service.d/dracut.conf"
272 # The iscsi deamon does not need to wait for any storage inside initrd
273 mkdir
-p "${initdir}/$systemdsystemunitdir/iscsid.socket.d"
276 echo "DefaultDependencies=no"
277 echo "Conflicts=shutdown.target"
278 echo "Before=shutdown.target sockets.target"
279 ) > "${initdir}/$systemdsystemunitdir/iscsid.socket.d/dracut.conf"
280 mkdir
-p "${initdir}/$systemdsystemunitdir/iscsiuio.socket.d"
283 echo "DefaultDependencies=no"
284 echo "Conflicts=shutdown.target"
285 echo "Before=shutdown.target sockets.target"
286 ) > "${initdir}/$systemdsystemunitdir/iscsiuio.socket.d/dracut.conf"
289 inst_dir
/var
/lib
/iscsi
290 dracut_need_initqueue