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 [ ! -e "$flash/is_boot_target" ] && continue
93 is_boot
=$
(cat $flash/is_boot_target
)
94 if [ $is_boot -eq 1 ] ; then
95 # qla4xxx flashnode session; skip iBFT discovery
96 iscsi_initiator
=$
(cat /sys
/class
/iscsi_host
/${iscsi_host}/initiatorname
)
97 echo "rd.iscsi.initiator=${iscsi_initiator}"
102 for d
in ${session}/* ; do
106 conn
=${d}/iscsi_connection
/${c}
107 if [ -d ${conn} ] ; then
108 iscsi_address
=$
(cat ${conn}/persistent_address
)
109 iscsi_port
=$
(cat ${conn}/persistent_port
)
113 if [ -d ${d}/${iscsi_session} ] ; then
114 iscsi_initiator
=$
(cat ${d}/${iscsi_session}/initiatorname
)
115 iscsi_targetname
=$
(cat ${d}/${iscsi_session}/targetname
)
121 [ -z "$iscsi_address" ] && return
122 local_address
=$
(ip
-o route get to
$iscsi_address |
sed -n 's/.*src \([0-9a-f.:]*\).*/\1/p')
123 ifname
=$
(ip
-o route get to
$iscsi_address |
sed -n 's/.*dev \([^ ]*\).*/\1/p')
125 # follow ifcfg settings for boot protocol
127 "/etc/sysconfig/network-scripts/ifcfg-$ifname" \
128 "/etc/sysconfig/network/ifcfg-$ifname" \
130 [ -f "$_path" ] && bootproto
=$
(sed -n "s/BOOTPROTO='\?\([[:alpha:]]*6\?\)4\?/\1/p" "$_path")
133 if [ $bootproto ]; then
134 printf 'ip=%s:%s ' ${ifname} ${bootproto}
136 printf 'ip=%s:static ' ${ifname}
139 if [ -e /sys
/class
/net
/$ifname/address
] ; then
140 ifmac
=$
(cat /sys
/class
/net
/$ifname/address
)
141 printf 'ifname=%s:%s ' ${ifname} ${ifmac}
144 if [ -n "$iscsi_address" -a -n "$iscsi_targetname" ] ; then
145 if [ -n "$iscsi_port" -a "$iscsi_port" -eq 3260 ] ; then
148 if [ -n "$iscsi_lun" -a "$iscsi_lun" -eq 0 ] ; then
151 # In IPv6 case rd.iscsi.initatior= must pass address in [] brackets
152 case "$iscsi_address" in
154 iscsi_address
="[$iscsi_address]"
157 # Must be two separate lines, so that "sort | uniq" commands later
158 # can sort out rd.iscsi.initiator= duplicates
159 echo "rd.iscsi.initiator=${iscsi_initiator}"
160 echo "netroot=iscsi:${iscsi_address}::${iscsi_port}:${iscsi_lun}:${iscsi_targetname}"
167 install_softiscsi
() {
168 [ -d /sys
/firmware
/ibft
] && return 0
174 [[ -L "/sys/dev/block/$_dev" ]] ||
return
175 iscsi_dev
=$
(cd -P /sys
/dev
/block
/$_dev; echo $PWD)
176 install_iscsiroot
$iscsi_dev
179 for_each_host_dev_and_slaves_all is_softiscsi ||
return 255
185 echo network rootfs-block
190 local _arch
=$
(uname
-m)
191 local _funcs
='iscsi_register_transport'
193 instmods bnx2i qla4xxx cxgb3i cxgb4i be2iscsi qedi
194 hostonly
="" instmods iscsi_tcp iscsi_ibft crc32c iscsi_boot_sysfs
196 if [ "$_arch" = "s390" -o "$_arch" = "s390x" ]; then
197 _s390drivers
="=drivers/s390/scsi"
200 dracut_instmods
-o -s ${_funcs} =drivers
/scsi
${_s390drivers:+"$_s390drivers"}
205 local _iscsiconf
=$
(install_ibft
)
207 if [ "$_iscsiconf" ] ; then
217 inst_multiple
-o iscsiuio
218 inst_libdir_file
'libgcc_s.so*'
219 inst_multiple umount iscsi-iname iscsiadm iscsid
222 $systemdsystemunitdir/iscsid.socket \
223 $systemdsystemunitdir/iscsid.service \
224 $systemdsystemunitdir/iscsiuio.service \
225 $systemdsystemunitdir/iscsiuio.socket \
226 $systemdsystemunitdir/sockets.target.wants
/iscsid.socket \
227 $systemdsystemunitdir/sockets.target.wants
/iscsiuio.socket
229 if [[ $hostonly ]]; then
230 inst_dir $
(/usr
/bin
/find /etc
/iscsi
)
232 inst_simple
/etc
/iscsi
/iscsid.conf
235 # Detect iBFT and perform mandatory steps
236 if [[ $hostonly_cmdline == "yes" ]] ; then
237 local _iscsiconf
=$
(cmdline
)
238 [[ $_iscsiconf ]] && printf "%s\n" "$_iscsiconf" >> "${initdir}/etc/cmdline.d/95iscsi.conf"
241 inst_hook cmdline
90 "$moddir/parse-iscsiroot.sh"
242 inst_hook cleanup
90 "$moddir/cleanup-iscsi.sh"
243 inst
"$moddir/iscsiroot.sh" "/sbin/iscsiroot"
244 if ! dracut_module_included
"systemd"; then
245 inst
"$moddir/mount-lun.sh" "/bin/mount-lun.sh"
248 $systemdsystemunitdir/iscsi.service \
249 $systemdsystemunitdir/iscsid.service \
250 $systemdsystemunitdir/iscsid.socket \
251 $systemdsystemunitdir/iscsiuio.service \
252 $systemdsystemunitdir/iscsiuio.socket \
255 mkdir
-p "${initdir}/$systemdsystemunitdir/sockets.target.wants"
260 ln_r
"$systemdsystemunitdir/${i}" "$systemdsystemunitdir/sockets.target.wants/${i}"
263 mkdir
-p "${initdir}/$systemdsystemunitdir/basic.target.wants"
268 ln_r
"$systemdsystemunitdir/${i}" "$systemdsystemunitdir/basic.target.wants/${i}"
271 # Make sure iscsid is started after dracut-cmdline and ready for the initqueue
272 mkdir
-p "${initdir}/$systemdsystemunitdir/iscsid.service.d"
275 echo "After=dracut-cmdline.service"
276 echo "Before=dracut-initqueue.service"
277 ) > "${initdir}/$systemdsystemunitdir/iscsid.service.d/dracut.conf"
279 # The iscsi deamon does not need to wait for any storage inside initrd
280 mkdir
-p "${initdir}/$systemdsystemunitdir/iscsid.socket.d"
283 echo "DefaultDependencies=no"
284 echo "Conflicts=shutdown.target"
285 echo "Before=shutdown.target sockets.target"
286 ) > "${initdir}/$systemdsystemunitdir/iscsid.socket.d/dracut.conf"
287 mkdir
-p "${initdir}/$systemdsystemunitdir/iscsiuio.socket.d"
290 echo "DefaultDependencies=no"
291 echo "Conflicts=shutdown.target"
292 echo "Before=shutdown.target sockets.target"
293 ) > "${initdir}/$systemdsystemunitdir/iscsiuio.socket.d/dracut.conf"
296 inst_dir
/var
/lib
/iscsi
297 dracut_need_initqueue