#! /bin/sh # Install iSCSI packages in the target if necessary. iSCSI volumes # containing the root filesystem also need some special settings for # robustness. . /lib/partman/lib/base.sh get_default_interface () { db_get netcfg/choose_interface || return 1 default_interface="${RET%%:*}" # Work around netcfg/choose_interface not always being set: # https://bugs.launchpad.net/ubuntu/+source/netcfg/+bug/430820 if [ -z "$default_interface" ]; then default_interface=eth0 fi } have_iscsi= portal= target= username= password= username_in= password_in= for dev in $DEVICES/*; do [ -d "$dev" ] || continue [ -e "$dev/iscsi_portal" ] || continue have_iscsi=1 cd "$dev" portal="$(cat "$dev/iscsi_portal")" target="$(cat "$dev/iscsi_target")" contains_root= open_dialog PARTITIONS while { read_line num id size type fs path name; [ "$id" ]; }; do [ "$fs" != free ] || continue [ -f "$id/method" ] || continue [ -f "$id/acting_filesystem" ] || continue [ -f "$id/mountpoint" ] || continue mountpoint="$(cat "$id/mountpoint")" [ "$mountpoint" = / ] || continue contains_root=1 done close_dialog [ "$contains_root" ] || continue iscsiadm -m node --portal "${portal%,*}" --targetname "$target" -o update -n 'node.conn[0].timeo.noop_out_interval' -v 0 iscsiadm -m node --portal "${portal%,*}" --targetname "$target" -o update -n 'node.conn[0].timeo.noop_out_timeout' -v 0 iscsiadm -m node --portal "${portal%,*}" --targetname "$target" -o update -n 'node.session.timeo.replacement_timeout' -v 86400 username="$(cat "$dev/iscsi_username")" password="$(cat "$dev/iscsi_password")" username_in="$(cat "$dev/iscsi_username_in")" password_in="$(cat "$dev/iscsi_password_in")" break done if [ "$have_iscsi" ]; then apt-install open-iscsi || true fi if [ "$portal" ]; then group="${portal##*,}" portal="${portal%,*}" ip="${portal%%:*}" port="${portal#*:}" mkdir -p /target/etc/iscsi get_default_interface if [ -f "/sys/class/net/$default_interface/address" ]; then cat >>/target/etc/iscsi/iscsi.initramfs <>/target/etc/iscsi/iscsi.initramfs <>/target/etc/iscsi/iscsi.initramfs <>/target/etc/iscsi/iscsi.initramfs <