6 # If our prerequisites are not met, fail anyways.
7 require_binaries hostname 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 ||
return 255
33 local iface_mac iface_mod
34 # Return the iSCSI offload module for a given MAC address
35 for iface_desc
in $
(iscsiadm
-m iface | cut
-f 2 -d ' '); do
36 iface_mod
=${iface_desc%%,*}
37 iface_mac
=${iface_desc#*,}
38 iface_mac
=${iface_mac%%,*}
39 if [ "$ibft_mac" = "$iface_mac" ] ; then
47 # When iBFT / iscsi_boot is detected:
48 # - Use 'ip=ibft' to set up iBFT network interface
49 # Note: bnx2i is using a different MAC address of iSCSI offloading
50 # so the 'ip=ibft' parameter must not be set
51 # - specify firmware booting cmdline parameter
53 for d
in /sys
/firmware
/* ; do
54 if [ -d ${d}/ethernet0
] ; then
55 read ibft_mac
< ${d}/ethernet
0/mac
56 ibft_mod
=$
(get_ibft_mod
$ibft_mac)
58 if [ -z "$ibft_mod" ] && [ -d ${d}/ethernet1
] ; then
59 read ibft_mac
< ${d}/ethernet
1/mac
60 ibft_mod
=$
(get_ibft_mod
$ibft_mac)
62 if [ -d ${d}/initiator
] ; then
63 if [ ${d##*/} = "ibft" ] && [ "$ibft_mod" != "bnx2i" ] ; then
64 echo -n "rd.iscsi.ibft=1 "
66 echo -n "rd.iscsi.firmware=1"
73 local scsi_path iscsi_lun session c d conn
host flash
74 local iscsi_session iscsi_address iscsi_port iscsi_targetname iscsi_tpgt
76 scsi_path
=${devpath%%/block*}
77 [ "$scsi_path" = "$devpath" ] && return 1
78 iscsi_lun
=${scsi_path##*:}
79 [ "$iscsi_lun" = "$scsi_path" ] && return 1
80 session
=${devpath%%/target*}
81 [ "$session" = "$devpath" ] && return 1
82 iscsi_session
=${session##*/}
83 [ "$iscsi_session" = "$session" ] && return 1
84 host=${session%%/session*}
85 [ "$host" = "$session" ] && return 1
86 iscsi_host
=${host##*/}
88 for flash
in ${host}/flashnode_sess-
* ; do
89 is_boot
=$
(cat $flash/is_boot_target
)
90 if [ $is_boot -eq 1 ] ; then
91 # qla4xxx flashnode session; skip iBFT discovery
92 iscsi_initiator
=$
(cat /sys
/class
/iscsi_host
/${iscsi_host}/initiatorname
)
93 echo "rd.iscsi.initiator=${iscsi_initiator}"
98 for d
in ${session}/* ; do
102 conn
=${d}/iscsi_connection
/${c}
103 if [ -d ${conn} ] ; then
104 iscsi_address
=$
(cat ${conn}/persistent_address
)
105 iscsi_port
=$
(cat ${conn}/persistent_port
)
109 if [ -d ${d}/${iscsi_session} ] ; then
110 iscsi_initiator
=$
(cat ${d}/${iscsi_session}/initiatorname
)
111 iscsi_targetname
=$
(cat ${d}/${iscsi_session}/targetname
)
117 [ -z "$iscsi_address" ] && return
118 local_address
=$
(ip
-o route get to
$iscsi_address |
sed -n 's/.*src \([0-9a-f.:]*\).*/\1/p')
119 ifname
=$
(ip
-o route get to
$iscsi_address |
sed -n 's/.*dev \([^ ]*\).*/\1/p')
121 #follow ifcfg settings for boot protocol
122 bootproto
=$
(sed -n "/BOOTPROTO/s/BOOTPROTO='\([[:alpha:]]*6\?\)4\?'/\1/p" /etc
/sysconfig
/network
/ifcfg-
$ifname)
123 if [ $bootproto ]; then
124 printf 'ip=%s:%s ' ${ifname} ${bootproto}
126 printf 'ip=%s:static ' ${ifname}
129 if [ -e /sys
/class
/net
/$ifname/address
] ; then
130 ifmac
=$
(cat /sys
/class
/net
/$ifname/address
)
131 printf 'ifname=%s:%s ' ${ifname} ${ifmac}
134 if [ -n "$iscsi_address" -a -n "$iscsi_targetname" ] ; then
135 if [ -n "$iscsi_port" -a "$iscsi_port" -eq 3260 ] ; then
138 if [ -n "$iscsi_lun" -a "$iscsi_lun" -eq 0 ] ; then
141 # In IPv6 case rd.iscsi.initatior= must pass address in [] brackets
142 case "$iscsi_address" in
144 iscsi_address
="[$iscsi_address]"
147 # Must be two separate lines, so that "sort | uniq" commands later
148 # can sort out rd.iscsi.initiator= duplicates
149 echo "rd.iscsi.initiator=${iscsi_initiator}"
150 echo "netroot=iscsi:${iscsi_address}::${iscsi_port}:${iscsi_lun}:${iscsi_targetname}"
157 install_softiscsi
() {
158 [ -d /sys
/firmware
/ibft
] && return 0
164 [[ -L "/sys/dev/block/$_dev" ]] ||
return
165 iscsi_dev
=$
(cd -P /sys
/dev
/block
/$_dev; echo $PWD)
166 install_iscsiroot
$iscsi_dev
169 for_each_host_dev_and_slaves_all is_softiscsi ||
return 255
175 echo network rootfs-block
180 local _arch
=$
(uname
-m)
181 local _funcs
='iscsi_register_transport'
183 instmods bnx2i qla4xxx cxgb3i cxgb4i be2iscsi qedi
184 hostonly
="" instmods iscsi_tcp iscsi_ibft crc32c iscsi_boot_sysfs
186 if [ "$_arch" = "s390" -o "$_arch" = "s390x" ]; then
187 _s390drivers
="=drivers/s390/scsi"
190 dracut_instmods
-o -s ${_funcs} =drivers
/scsi
${_s390drivers:+"$_s390drivers"}
195 local _iscsiconf
=$
(install_ibft
)
197 if [ "$_iscsiconf" ] ; then
207 inst_multiple
-o iscsiuio
208 inst_libdir_file
'libgcc_s.so*'
209 inst_multiple umount hostname iscsi-iname iscsiadm iscsid
212 $systemdsystemunitdir/iscsid.socket \
213 $systemdsystemunitdir/iscsid.service \
214 $systemdsystemunitdir/iscsiuio.service \
215 $systemdsystemunitdir/iscsiuio.socket \
216 $systemdsystemunitdir/sockets.target.wants
/iscsid.socket \
217 $systemdsystemunitdir/sockets.target.wants
/iscsiuio.socket
219 [[ -d /etc
/iscsi
]] && inst_dir $
(/usr
/bin
/find /etc
/iscsi
)
221 # Detect iBFT and perform mandatory steps
222 if [[ $hostonly_cmdline == "yes" ]] ; then
223 local _iscsiconf
=$
(cmdline
)
224 [[ $_iscsiconf ]] && printf "%s\n" "$_iscsiconf" >> "${initdir}/etc/cmdline.d/95iscsi.conf"
227 inst_hook cmdline
90 "$moddir/parse-iscsiroot.sh"
228 inst_hook cleanup
90 "$moddir/cleanup-iscsi.sh"
229 inst
"$moddir/iscsiroot.sh" "/sbin/iscsiroot"
230 if ! dracut_module_included
"systemd"; then
231 inst
"$moddir/mount-lun.sh" "/bin/mount-lun.sh"
234 $systemdsystemunitdir/iscsi.service \
235 $systemdsystemunitdir/iscsid.service \
236 $systemdsystemunitdir/iscsid.socket \
237 $systemdsystemunitdir/iscsiuio.service \
238 $systemdsystemunitdir/iscsiuio.socket \
241 mkdir
-p "${initdir}/$systemdsystemunitdir/sockets.target.wants"
246 ln_r
"$systemdsystemunitdir/${i}" "$systemdsystemunitdir/sockets.target.wants/${i}"
249 mkdir
-p "${initdir}/$systemdsystemunitdir/basic.target.wants"
254 ln_r
"$systemdsystemunitdir/${i}" "$systemdsystemunitdir/basic.target.wants/${i}"
257 # Make sure iscsid is started after dracut-cmdline and ready for the initqueue
258 mkdir
-p "${initdir}/$systemdsystemunitdir/iscsid.service.d"
261 echo "After=dracut-cmdline.service"
262 echo "Before=dracut-initqueue.service"
263 ) > "${initdir}/$systemdsystemunitdir/iscsid.service.d/dracut.conf"
265 inst_dir
/var
/lib
/iscsi
266 dracut_need_initqueue