This file is indexed.

/usr/share/initramfs-tools/scripts/local-top/iscsi is in open-iscsi 2.0.874-3~deb9u1.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
#!/bin/sh

PREREQ=""

prereqs()
{
	echo "$PREREQ"
}

case $1 in
# get pre-requisites
prereqs)
	prereqs
	exit 0
	;;
esac

parse_root_param ()
{
	target="$1"
	auth="$2"
	OLDIFS="$IFS"
	IFS=":"
	set -- $target
	IFS="$OLDIFS"

	tmp_ISCSI_TARGET_IP="$1"
	if [ -n "$2" ] ; then
		if [ x"$2" != x"6" ] ; then
			echo "Warning: unsupported protocol specified for iSCSI root parameter, assuming 6 (TCP)" >&2
		fi
	fi
	tmp_ISCSI_TARGET_PORT="$3"
	tmp_ISCSI_ROOT_LUN="$4"
	tmp_ISCSI_TARGET_NAME="$5"
	shift 5
	while [ -n "$1" ] ; do
		tmp_ISCSI_TARGET_NAME="${tmp_ISCSI_TARGET_NAME}:$1"
		shift
	done

	if [ -z "$tmp_ISCSI_TARGET_IP" ] || [ -z "$tmp_ISCSI_TARGET_NAME" ] ; then
		echo "Warning: empty iSCSI IP / target name currently not supported for root=iscsi:, ignoring parameter" >&2
		return
	fi

	OLDIFS="$IFS"
	IFS=":"
	set -- $auth
	IFS="$OLDIFS"

	tmp_ISCSI_USERNAME=""
	tmp_ISCSI_PASSWORD=""
	tmp_ISCSI_IN_USERNAME=""
	tmp_ISCSI_IN_PASSWORD=""

	if [ $# -gt 4 ] ; then
		echo "Warning: invalid authentication for root=iscsi:, ignoring" >&2
		return
	fi

	if [ $# -gt 0 ] ; then
		tmp_ISCSI_USERNAME="$1"
		tmp_ISCSI_PASSWORD="$2"
		if [ $# -gt 2 ] ; then
			tmp_ISCSI_IN_USERNAME="$3"
			tmp_ISCSI_IN_PASSWORD="$4"
		fi
	fi

	ISCSI_TARGET_IP="$tmp_ISCSI_TARGET_IP"
	ISCSI_TARGET_PORT="$tmp_ISCSI_TARGET_PORT"
	ISCSI_TARGET_NAME="$tmp_ISCSI_TARGET_NAME"
	ISCSI_ROOT_LUN="$tmp_ISCSI_ROOT_LUN"
	if [ -n "$tmp_ISCSI_USERNAME" ] ; then
		ISCSI_USERNAME="$tmp_ISCSI_USERNAME"
		ISCSI_PASSWORD="$tmp_ISCSI_PASSWORD"
	fi
	if [ -n "$tmp_ISCSI_IN_USERNAME" ] ; then
		ISCSI_IN_USERNAME="$tmp_ISCSI_IN_USERNAME"
		ISCSI_IN_PASSWORD="$tmp_ISCSI_IN_PASSWORD"
	fi
	ISCSI_HAD_ROOT=yes
}

do_iscsi_login ()
{
	# Bring in the main config
	. /conf/initramfs.conf
	for conf in conf/conf.d/*; do
		[ -f ${conf} ] && . ${conf}
	done
	. /scripts/functions

	udevadm settle

	if [ -n "$ISCSI_AUTO" ] ; then
		# try to auto-configure network interface based
		# on firmware values
		modprobe iscsi_ibft
		iscsistart -N

		# write out /run/net-$IFACE.conf based on what
		# was in the firmware
		iscsistart -f | while read k eq v; do
			case "${k} ${eq} ${v}" in
			("# BEGIN RECORD"*)
				DEVICE=""
				PROTO="none"
				IPV4ADDR=""
				IPV4NETMASK=""
				IPV4GATEWAY=""
				IPV4DNS0=""
				IPV4DNS1=""
				UPTIME="0"
				DHCPLEASETIME="0"
				DOMAINSEARCH=""
				continue
				;;
			("# END RECORD"*)
				if [ -n "$DEVICE" ] ; then
				{
					echo "DEVICE='${DEVICE}'"
					echo "PROTO='${PROTO}'"
					echo "IPV4ADDR='${IPV4ADDR}'"
					echo "IPV4BROADCAST=''"
					echo "IPV4NETMASK='${IPV4NETMASK}'"
					echo "IPV4GATEWAY='${IPV4GATEWAY}'"
					echo "IPV4DNS0='${IPV4DNS0}'"
					echo "IPV4DNS1='${IPV4DNS1}'"
					echo "HOSTNAME=''"
					echo "DNSDOMAIN=''"
					echo "NISDOMAIN=''"
					echo "ROOTSERVER=''"
					echo "ROOTPATH=''"
					echo "UPTIME='${UPTIME}'"
					echo "DHCPLEASETIME='${DHCPLEASETIME}'"
					echo "DOMAINSEARCH=''"
				} > "/run/net-${DEVICE}.conf"
				echo "${DEVICE}" > /run/initramfs/open-iscsi.interface
				# iscsistart -N doesn't set the default gateway. Therefore,
				# we need to add it ourselves. However, the ip command is
				# only available if we use busybox in the initramfs (it's
				# in open-iscsi's Recommends), so check for that.
				if [ -n "${IPV4GATEWAY}" ] && which ip >/dev/null 2>&1 ; then
					ip route add default via "${IPV4GATEWAY}"
				fi
				fi
				continue
				;;
			esac
			if [ "${eq}" != "=" ] ; then
				continue
			fi
			case "${k}" in
				iface.ipaddress)     IPV4ADDR="${v}" ;;
				iface.subnet_mask)   IPV4NETMASK="${v}" ;;
				iface.gateway)       IPV4GATEWAY="${v}" ;;
				iface.primary_dns)   IPV4DNS0="${v}" ;;
				iface.secondary_dns) IPV4DNS1="${v}" ;;
				iface.net_ifacename) DEVICE="${v}" ;;
			esac
		done
	fi

	# run configure_networking even if we have iscsi_auto, because there
	# could be other network interfaces that need to be configured
	# manually
	configure_networking

	# Save network device we configured via configure_networking, but only
	# if we didn't already get one from autoconfiguration (then we always
	# prefer that).
	if ! [ -e /run/initramfs/open-iscsi.interface ] ; then
		if [ -z "${DEVICE}" ] || ! [ -e "/run/net-${DEVICE}.conf" ] ; then
			for i in /run/net-*.conf ; do
				[ -e "${i}" ] && { . "${i}" ; break ; }
			done
		fi
		if [ -n "${DEVICE}" ] ; then
			echo "${DEVICE}" > /run/initramfs/open-iscsi.interface
		fi
	fi

	modprobe iscsi_tcp
	modprobe crc32c

	# If iscsiuio is present in the initramfs, start it, in case UIO
	# offloading is required.
	if [ -x /sbin/iscsiuio ] ; then
		start-stop-daemon --start --quiet --pidfile /run/initramfs/iscsiuio.pid \
				  --startas /sbin/iscsiuio --name iscsiuio \
				  --exec /sbin/iscsiuio -- --pid=/run/initramfs/iscsiuio.pid || :
	fi

	if [ -z $ISCSI_AUTO ]; then
		if [ -z $ISCSI_INITIATOR ]; then
			. /etc/initiatorname.iscsi
			ISCSI_INITIATOR=$InitiatorName
		fi

		if [ -z $ISCSI_TARGET_PORT ]; then
			ISCSI_TARGET_PORT=3260
		fi

		if [ -z $ISCSI_TARGET_GROUP ]; then
			ISCSI_TARGET_GROUP=1
		fi

		iscsistart -i $ISCSI_INITIATOR -t $ISCSI_TARGET_NAME	\
			   -g $ISCSI_TARGET_GROUP -a $ISCSI_TARGET_IP	\
			   -p $ISCSI_TARGET_PORT \
			   ${ISCSI_USERNAME:+-u "$ISCSI_USERNAME"}	\
			   ${ISCSI_PASSWORD:+-w "$ISCSI_PASSWORD"}	\
			   ${ISCSI_IN_USERNAME:+-U "$ISCSI_IN_USERNAME"}\
			   ${ISCSI_IN_PASSWORD:+-W "$ISCSI_IN_PASSWORD"}
	else
		modprobe iscsi_ibft
		iscsistart -b
	fi

	if [ -z $ISCSI_TARGET_PORT ]; then
		ISCSI_TARGET_PORT=3260
	fi

	if [ -z $ISCSI_TARGET_GROUP ]; then
		ISCSI_TARGET_GROUP=1
	fi

	for i in $ISCSI_TARGET_IP; do
	iscsistart -i $ISCSI_INITIATOR -t $ISCSI_TARGET_NAME	\
		   -g $ISCSI_TARGET_GROUP -a $i \
		   -p $ISCSI_TARGET_PORT \
		   ${ISCSI_USERNAME:+-u "$ISCSI_USERNAME"}	\
		   ${ISCSI_PASSWORD:+-w "$ISCSI_PASSWORD"}	\
		   ${ISCSI_IN_USERNAME:+-U "$ISCSI_IN_USERNAME"}\
		   ${ISCSI_IN_PASSWORD:+-W "$ISCSI_IN_PASSWORD"}
	done
}

parse_iscsi_ops ()
{
	[ -r /etc/iscsi.initramfs ] && . /etc/iscsi.initramfs

	for x in $(cat /proc/cmdline); do
		case ${x} in
		iscsi_auto)
			ISCSI_AUTO=true
			;;
        	iscsi_initiator=*)
                	ISCSI_INITIATOR="${x#iscsi_initiator=}"
                	;;
        	iscsi_target_name=*)
                	ISCSI_TARGET_NAME="${x#iscsi_target_name=}"
                	;;
        	iscsi_target_ip=*)
                	ISCSI_TARGET_IP="${x#iscsi_target_ip=}"
                	;;
        	iscsi_target_port=*)
                	ISCSI_TARGET_PORT="${x#iscsi_target_port=}"
                	;;
		iscsi_target_group=*)
			ISCSI_TARGET_GROUP="${x#iscsi_target_group=}"
			;;
		iscsi_username=*)
			ISCSI_USERNAME="${x#iscsi_username=}"
			;;
		iscsi_password=*)
			ISCSI_PASSWORD="${x#iscsi_password=}"
			;;
		iscsi_in_username=*)
			ISCSI_IN_USERNAME="${x#iscsi_in_username=}"
			;;
		iscsi_in_password=*)
			ISCSI_IN_PASSWORD="${x#iscsi_in_password=}"
			;;
		root=iscsi:*@*)
			x="${x##root=iscsi:}"
			parse_root_param "${x#*@}" "${x%%@*}"
			;;
		root=iscsi:*)
			parse_root_param "${x##root=iscsi:}" ""
			;;
		esac
	done
}

if [ ! -x /sbin/iscsistart ]; then
	exit 0
fi

parse_iscsi_ops

if ( [ -z $ISCSI_TARGET_NAME ] || [ -z $ISCSI_TARGET_IP ] ) && [ -z $ISCSI_AUTO ]; then
	exit 0
fi

do_iscsi_login

udevadm settle

# The second check is to allow us to use multiple root= parameters. That way
# one may specify root=iscsi:... root=UUID=... to mount partitions on an iSCSI
# disk. (The latter value will overwrite the former for purposes of the main
# initramfs scripts, but our loop that scans /proc/cmdline will still detect
# the former and set proper parameters.
if [ -n "$ISCSI_HAD_ROOT" ] && [ x"${ROOT##iscsi:}" != x"${ROOT}" ] ; then
	if [ -z "$ISCSI_ROOT_LUN" ] ; then
		ISCSI_ROOT_LUN=0
	fi
	found=0
	# FIXME: RFC 4173 defines the LUN field to be more complicated and that
	#        the same LUN may have multiple representations.
	for disk in /dev/disk/by-path/*-iscsi-*-"${ISCSI_ROOT_LUN}" ; do
		# Resolve device name, as the colons in the by-path name will
		# cause mount to think that this is a NFS share, which we don't
		# want.
		if ! disk="$(readlink -f "$disk")" ; then
			continue
		fi

		# Try to load file system type module (ignore errors), otherwise
		# this won't succeed.
		if fstype=$(get_fstype "$disk") ; then
			modprobe "$fstype" || :
			ROOTFSTYPE="$fstype"
		fi

		# Try to mount read-only and see if it's the right filesystem.
		# If so, record the device name but umount again, because we
		# want to be able to do an fsck on it.
		if mount -r -t "${ROOTFSTYPE:-auto}" ${ROOTFLAGS} "${disk}" ${rootmnt} ; then
			if [ -d ${rootmnt}/proc ] ; then
				# This will be sourced by init after this hook has run.
				echo "export ROOT=$disk" >> /conf/param.conf
				if [ -n "$ROOTFSTYPE" ] && [ x"$ROOTFSTYPE" != x"auto" ] ; then
					echo "export ROOTFSTYPE=$ROOTFSTYPE" >> /conf/param.conf
				fi
				found=1
			fi
			umount ${rootmnt}
			if [ $found -eq 1 ] ; then
				break
			fi
		fi
	done
fi

exit 0