busybox-initramfs: init: add support for iSCSI mounts

Add support for iSCSI mounts.

Based on the work by Yann Cézard <eesprit@free.fr> , adapted to the new syntax.

Example usage:

Example 1: Autoconfigure network based on iBFT, autologin to iSCSI target
based on iBFT, mount partition with label 'Storage':

disk=ISCSI=auto,LABEL=Storage

Example 2: Specify any needed iSCSI options, mount partition 1 on /dev/sdb:

disk=ISCSI=param1=val1,param2=val2,...,/dev/sdb1

Note: the parameter after the very last comma _must_ be a valid LABEL=, UUID=
or device path.

Signed-off-by: Alain Kalker <a.c.kalker@gmail.com>
This commit is contained in:
Alain Kalker 2012-03-26 02:27:35 +02:00
parent 4848bbb78c
commit ee48f9a59a

View File

@ -67,36 +67,6 @@ NBD_DEVS="0"
break=*) break=*)
BREAK="${arg#*=}" BREAK="${arg#*=}"
;; ;;
iscsi_auto)
ISCSI_AUTO=yes
;;
iscsi_initiator=*)
ISCSI_INITIATOR="${arg#iscsi_initiator=}"
;;
iscsi_target_name=*)
ISCSI_TARGET_NAME="${arg#iscsi_target_name=}"
;;
iscsi_target_ip=*)
ISCSI_TARGET_IP="${arg#iscsi_target_ip=}"
;;
iscsi_target_port=*)
ISCSI_TARGET_PORT="${arg#iscsi_target_port=}"
;;
iscsi_target_group=*)
ISCSI_TARGET_GROUP="${arg#iscsi_target_group=}"
;;
iscsi_username=*)
ISCSI_USERNAME="${arg#iscsi_username=}"
;;
iscsi_password=*)
ISCSI_PASSWORD="${arg#iscsi_password=}"
;;
iscsi_in_username=*)
ISCSI_IN_USERNAME="${arg#iscsi_in_username=}"
;;
iscsi_in_password=*)
ISCSI_IN_PASSWORD="${arg#iscsi_in_password=}"
;;
esac esac
done done
@ -175,6 +145,72 @@ NBD_DEVS="0"
mount_common "$CIFS_SHARE" "$2" "$3,$CIFS_OPTIONS" "cifs" mount_common "$CIFS_SHARE" "$2" "$3,$CIFS_OPTIONS" "cifs"
} }
get_iscsistart_options() {
# Convert kernel commandline ISCSI= options to iscsistart options
IFS_SAVE="$IFS"
IFS=,
for arg in $1; do
val="${arg#*=}"
case "$arg" in
iscsi_initiator=*)
option="-i"
;;
iscsi_target_name=*)
option="-t"
;;
iscsi_target_ip=*)
option="-a"
;;
iscsi_target_port=*)
option="-p"
;;
iscsi_target_group=*)
option="-g"
;;
iscsi_username=*)
option="-u"
;;
iscsi_password=*)
option="-w"
;;
iscsi_in_username=*)
option="-U"
;;
iscsi_in_password=*)
option="-W"
;;
esac
echo "$option $val"
done
IFS="$IFS_SAVE"
}
mount_iscsi() {
# Mount iSCSI target
ISCSI_DEV="${1##*,}"
ISCSI_OPTIONS="${1%,*}"
if [ ! -f "/sbin/iscsistart" ]; then
error "iscsistart" "iSCSI support not available"
fi
if [ "$ISCSI_OPTIONS" = "auto" ]; then
progress "Network configuration based on iBFT"
/sbin/iscsistart -N >&$SILENT_OUT 2>&1 || \
error "iscsistart" "Unable to configure network"
progress "iSCSI auto connect based on iBFT"
/sbin/iscsistart -b >&$SILENT_OUT 2>&1 || \
error "iscsistart" "Unable to auto connect"
else
/sbin/iscsistart $(get_iscsistart_options "$ISCSI_OPTIONS") >&$SILENT_OUT 2>&1 || \
error "iscsistart" "Unable to connect to ISCSI target"
fi
mount_common "$ISCSI_DEV" "$2" "$3" "$4"
}
mount_nbd() { mount_nbd() {
# Mount NBD device # Mount NBD device
NBD_SERVER="${1%%:*}" NBD_SERVER="${1%%:*}"
@ -210,6 +246,9 @@ NBD_DEVS="0"
CIFS=*|SMB=*) CIFS=*|SMB=*)
MOUNT_CMD="mount_cifs" MOUNT_CMD="mount_cifs"
;; ;;
ISCSI=*)
MOUNT_CMD="mount_iscsi"
;;
NBD=*) NBD=*)
MOUNT_CMD="mount_nbd" MOUNT_CMD="mount_nbd"
;; ;;
@ -261,27 +300,6 @@ NBD_DEVS="0"
error "load_modules" "Failed to load kernel module $module" error "load_modules" "Failed to load kernel module $module"
done done
} }
do_iscsi_login ()
{
if [ -z $ISCSI_AUTO ]; then
for i in $ISCSI_TARGET_IP; do
/sbin/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
else
echo "Network configuration based on iBFT."
/sbin/iscsistart -N
echo "iSCSI auto connect based on iBFT."
/sbin/iscsistart -b
fi
}
check_disks() { check_disks() {
progress "Checking disks" progress "Checking disks"
@ -353,10 +371,6 @@ NBD_DEVS="0"
[ -f "/sysroot/sbin/init" ] || error "final_check" "Could not find system." [ -f "/sysroot/sbin/init" ] || error "final_check" "Could not find system."
} }
if [ -n "$ISCSI_AUTO" -o -n "$ISCSI_TARGET_NAME" ]; then
do_iscsi_login
fi
# main boot sequence # main boot sequence
for BOOT_STEP in \ for BOOT_STEP in \