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
79 scsi_path
=${devpath%%/block*}
80 [ "$scsi_path" = "$devpath" ] && return 1
81 iscsi_lun
=${scsi_path##*:}
82 [ "$iscsi_lun" = "$scsi_path" ] && return 1
83 session
=${devpath%%/target*}
84 [ "$session" = "$devpath" ] && return 1
85 iscsi_session
=${session##*/}
86 [ "$iscsi_session" = "$session" ] && return 1
87 host=${session%%/session*}
88 [ "$host" = "$session" ] && return 1
89 iscsi_host
=${host##*/}
91 for flash
in ${host}/flashnode_sess-
* ; do
92 [ -f "$flash" ] ||
continue
93 [ ! -e "$flash/is_boot_target" ] && continue
94 is_boot
=$
(cat $flash/is_boot_target
)
95 if [ $is_boot -eq 1 ] ; then
96 # qla4xxx flashnode session; skip iBFT discovery
97 iscsi_initiator
=$
(cat /sys
/class
/iscsi_host
/${iscsi_host}/initiatorname
)
98 echo "rd.iscsi.initiator=${iscsi_initiator}"
103 for d
in ${session}/* ; do
107 conn
=${d}/iscsi_connection
/${c}
108 if [ -d ${conn} ] ; then
109 iscsi_address
=$
(cat ${conn}/persistent_address
)
110 iscsi_port
=$
(cat ${conn}/persistent_port
)
114 if [ -d ${d}/${iscsi_session} ] ; then
115 iscsi_initiator
=$
(cat ${d}/${iscsi_session}/initiatorname
)
116 iscsi_targetname
=$
(cat ${d}/${iscsi_session}/targetname
)
122 [ -z "$iscsi_address" ] && return
123 local_address
=$
(ip
-o route get to
$iscsi_address |
sed -n 's/.*src \([0-9a-f.:]*\).*/\1/p')
124 ifname
=$
(ip
-o route get to
$iscsi_address |
sed -n 's/.*dev \([^ ]*\).*/\1/p')
126 # follow ifcfg settings for boot protocol
128 "/etc/sysconfig/network-scripts/ifcfg-$ifname" \
129 "/etc/sysconfig/network/ifcfg-$ifname" \
131 [ -f "$_path" ] && bootproto
=$
(sed -n "s/BOOTPROTO='\?\([[:alpha:]]*6\?\)4\?/\1/p" "$_path")
134 if [ $bootproto ]; then
135 printf 'ip=%s:%s ' ${ifname} ${bootproto}
137 printf 'ip=%s:static ' ${ifname}
140 if [ -e /sys
/class
/net
/$ifname/address
] ; then
141 ifmac
=$
(cat /sys
/class
/net
/$ifname/address
)
142 printf 'ifname=%s:%s ' ${ifname} ${ifmac}
145 if [ -n "$iscsi_address" -a -n "$iscsi_targetname" ] ; then
146 if [ -n "$iscsi_port" -a "$iscsi_port" -eq 3260 ] ; then
149 if [ -n "$iscsi_lun" -a "$iscsi_lun" -eq 0 ] ; then
152 # In IPv6 case rd.iscsi.initatior= must pass address in [] brackets
153 case "$iscsi_address" in
155 iscsi_address
="[$iscsi_address]"
158 # Must be two separate lines, so that "sort | uniq" commands later
159 # can sort out rd.iscsi.initiator= duplicates
160 echo "rd.iscsi.initiator=${iscsi_initiator}"
161 echo "netroot=iscsi:${iscsi_address}::${iscsi_port}:${iscsi_lun}:${iscsi_targetname}"
168 install_softiscsi
() {
169 [ -d /sys
/firmware
/ibft
] && return 0
175 [[ -L "/sys/dev/block/$_dev" ]] ||
return
176 iscsi_dev
=$
(cd -P /sys
/dev
/block
/$_dev; echo $PWD)
177 install_iscsiroot
$iscsi_dev
180 for_each_host_dev_and_slaves_all is_softiscsi ||
return 255
186 echo network rootfs-block
191 local _arch
=$
(uname
-m)
192 local _funcs
='iscsi_register_transport'
194 instmods bnx2i qla4xxx cxgb3i cxgb4i be2iscsi qedi
195 hostonly
="" instmods iscsi_tcp iscsi_ibft crc32c iscsi_boot_sysfs
197 if [ "$_arch" = "s390" -o "$_arch" = "s390x" ]; then
198 _s390drivers
="=drivers/s390/scsi"
201 dracut_instmods
-o -s ${_funcs} =drivers
/scsi
${_s390drivers:+"$_s390drivers"}
206 local _iscsiconf
=$
(install_ibft
)
208 if [ "$_iscsiconf" ] ; then
218 inst_multiple
-o iscsiuio
219 inst_libdir_file
'libgcc_s.so*'
220 inst_multiple umount iscsi-iname iscsiadm iscsid
223 $systemdsystemunitdir/iscsid.socket \
224 $systemdsystemunitdir/iscsid.service \
225 $systemdsystemunitdir/iscsiuio.service \
226 $systemdsystemunitdir/iscsiuio.socket \
227 $systemdsystemunitdir/sockets.target.wants
/iscsid.socket \
228 $systemdsystemunitdir/sockets.target.wants
/iscsiuio.socket
230 if [[ $hostonly ]]; then
231 inst_dir $
(/usr
/bin
/find /etc
/iscsi
)
233 inst_simple
/etc
/iscsi
/iscsid.conf
236 # Detect iBFT and perform mandatory steps
237 if [[ $hostonly_cmdline == "yes" ]] ; then
238 local _iscsiconf
=$
(cmdline
)
239 [[ $_iscsiconf ]] && printf "%s\n" "$_iscsiconf" >> "${initdir}/etc/cmdline.d/95iscsi.conf"
242 inst_hook cmdline
90 "$moddir/parse-iscsiroot.sh"
243 inst_hook cleanup
90 "$moddir/cleanup-iscsi.sh"
244 inst
"$moddir/iscsiroot.sh" "/sbin/iscsiroot"
245 if ! dracut_module_included
"systemd"; then
246 inst
"$moddir/mount-lun.sh" "/bin/mount-lun.sh"
249 $systemdsystemunitdir/iscsi.service \
250 $systemdsystemunitdir/iscsid.service \
251 $systemdsystemunitdir/iscsid.socket \
252 $systemdsystemunitdir/iscsiuio.service \
253 $systemdsystemunitdir/iscsiuio.socket \
256 mkdir
-p "${initdir}/$systemdsystemunitdir/sockets.target.wants"
261 ln_r
"$systemdsystemunitdir/${i}" "$systemdsystemunitdir/sockets.target.wants/${i}"
264 mkdir
-p "${initdir}/$systemdsystemunitdir/basic.target.wants"
269 ln_r
"$systemdsystemunitdir/${i}" "$systemdsystemunitdir/basic.target.wants/${i}"
272 # Make sure iscsid is started after dracut-cmdline and ready for the initqueue
273 mkdir
-p "${initdir}/$systemdsystemunitdir/iscsid.service.d"
276 echo "After=dracut-cmdline.service"
277 echo "Before=dracut-initqueue.service"
278 ) > "${initdir}/$systemdsystemunitdir/iscsid.service.d/dracut.conf"
280 # The iscsi deamon does not need to wait for any storage inside initrd
281 mkdir
-p "${initdir}/$systemdsystemunitdir/iscsid.socket.d"
284 echo "DefaultDependencies=no"
285 echo "Conflicts=shutdown.target"
286 echo "Before=shutdown.target sockets.target"
287 ) > "${initdir}/$systemdsystemunitdir/iscsid.socket.d/dracut.conf"
288 mkdir
-p "${initdir}/$systemdsystemunitdir/iscsiuio.socket.d"
291 echo "DefaultDependencies=no"
292 echo "Conflicts=shutdown.target"
293 echo "Before=shutdown.target sockets.target"
294 ) > "${initdir}/$systemdsystemunitdir/iscsiuio.socket.d/dracut.conf"
297 inst_dir
/var
/lib
/iscsi
298 dracut_need_initqueue