[Ovirt-devel] [PATCH node] iscsi remote root basework This lays most of the groundwork for iscsi installation and configuration. At this time configuring iscsi is disabled due to multiple issues with dependent pieces.

Joey Boggs jboggs at redhat.com
Tue Dec 8 20:41:33 UTC 2009


- dracut does not currently support booting a dmsquash file system on an iscsiroot
- can not be configured in standalone mode since networking is not up, although works fine if ovirt-config-setup is run once booted.

Signed-off-by: Joey Boggs <jboggs at redhat.com>
---
 recipe/common-pkgs.ks        |    1 +
 scripts/ovirt-config-boot    |   67 ++++++++++++++++----
 scripts/ovirt-config-storage |  142 +++++++++++++++++++++++++++++++++++++++--
 scripts/ovirt-functions      |    8 +++
 4 files changed, 199 insertions(+), 19 deletions(-)

diff --git a/recipe/common-pkgs.ks b/recipe/common-pkgs.ks
index daff195..9bd3b07 100644
--- a/recipe/common-pkgs.ks
+++ b/recipe/common-pkgs.ks
@@ -73,3 +73,4 @@ kpartx
 # workaround for gpxe issue with the virt-preview qemu on F11 host kernel
 # https://bugzilla.redhat.com/show_bug.cgi?id=512358
 etherboot-zroms-kvm
+dracut-network
diff --git a/scripts/ovirt-config-boot b/scripts/ovirt-config-boot
index 470f57b..4c4e3d7 100755
--- a/scripts/ovirt-config-boot
+++ b/scripts/ovirt-config-boot
@@ -29,9 +29,28 @@ ovirt_boot_setup() {
     local disk2
     local partN=-1
     log "installing the image."
+    if [ -h /dev/disk/by-label/Boot ]; then
+        mount_boot
+        mountpoint /boot
+        if [ $? -ne 0 ] ; then
+            log "Boot partition not available"
+            return 1
+        fi
+        grub_dev_label="Boot"
+        # Grab OVIRT_ISCSI VARIABLES from boot partition for upgrading
+        # file created only if OVIRT_ISCSI_ENABLED=y
+        if [ -f /boot/ovirt ]; then
+            . /boot/ovirt
+        iscsiadm -p $OVIRT_ISCSI_TARGET_IP:$OVIRT_ISCSI_TARGET_PORT -m discovery -t sendtargets
+        log "Restarting iscsi service"
+        service iscsi restart
+        fi
+    else
+        grub_dev_label="RootBackup"
+    fi
     mount_liveos
     # check that /boot mounted ok and find partition number for GRUB
-    eval $(readlink -f /dev/disk/by-label/RootBackup|awk {'
+    eval $(readlink -f /dev/disk/by-label/$grub_dev_label|awk {'
         print "disk=" substr($1,1,length($1)-1);
         print "disk2=" substr($1,1,length($1)-2);
         partN=substr($1,length($1),1); partN--;
@@ -75,9 +94,10 @@ ovirt_boot_setup() {
     fi
     if [ $rc -ne 0 ]; then
       log "root partition not available."
-      log "$(lvdisplay -c)"
+      log "$(ls -al /dev/disk/by-label)"
       return $rc
     fi
+
     mount $candidate_dev /liveos
     # install oVirt Node image for local boot
     if [ -e "$live/syslinux" ]; then
@@ -87,12 +107,25 @@ ovirt_boot_setup() {
     else
       syslinux=
     fi
-    rm -rf /liveos/boot/grub
+
     rm -rf /liveos/LiveOS
-    mkdir -p /liveos/boot/grub
     mkdir -p /liveos/LiveOS
+
+    if [ "$OVIRT_ISCSI_ENABLED" == "y" ]; then
+        initrd_dest="/boot"
+        grub_dir="/boot/grub"
+        grub_prefix="/grub"
+    else
+        initrd_dest="/liveos"
+        grub_dir="/liveos/boot/grub"
+        grub_prefix="/boot/grub"
+    fi
+
+    rm -rf  $grub_dir
+    mkdir -p $grub_dir
+
     cp -p $live/LiveOS/squashfs.img /liveos/LiveOS \
-    && cp -p $live/$syslinux/vmlinuz0 /liveos
+    && cp -p $live/$syslinux/vmlinuz0 $initrd_dest
     rc=$?
     if [ $rc -ne 0 ]; then
       log "image copy failed."
@@ -139,17 +172,23 @@ set -e\
         # lvm is not static in Fedora
         cp /lib$bit/libreadline.so.5 /lib$bit/libncurses.so.5 lib$bit
     fi
+
     find $init_script bin/lvm lib$bit -type f |
         cpio -H newc --quiet -o |
         gzip -9 |
-        cat $live/$syslinux/initrd0.img - > /liveos/initrd0.img
+        cat $live/$syslinux/initrd0.img - > $initrd_dest/initrd0.img
 
     version=$(rpm -q --qf '%{version}' ovirt-node)
     release=$(rpm -q --qf '%{release}' ovirt-node)
     # reorder tty0 to allow both serial and phys console after installation
-    bootparams="ro root=LABEL=Root roottypefs=ext3 console=tty0 \
+    if [ "$OVIRT_ISCSI_ENABLED" == "y" ]; then
+        bootparams="ro root=LABEL=live:Root roottypefs=ext3 console=tty0 \
+                    netroot=iscsi:$OVIRT_ISCSI_TARGET_IP::$OVIRT_ISCSI_TARGET_PORT::$OVIRT_ISCSI_NODE_NAME ip=eth0:dhcp"
+    else
+        bootparams="ro root=LABEL=live:Root roottypefs=ext3 console=tty0 \
                 $(echo $bootparams | sed s/console=tty0//g)"
-    cat > /liveos/boot/grub/grub.conf << EOF
+    fi
+    cat > $grub_dir/grub.conf << EOF
 default=0
 timeout=5
 hiddenmenu
@@ -158,11 +197,11 @@ title oVirt Node (${version}-${release})
     kernel /vmlinuz0 $bootparams
     initrd /initrd0.img
 EOF
-    echo "(hd0) $disk" > /liveos/boot/grub/device.map
-    ( cd /usr/share/grub/*; cp -p stage? e2fs_stage1_5 /liveos/boot/grub )
-    grub --device-map=/liveos/boot/grub/device.map <<EOF
+    echo "(hd0) $disk" > $grub_dir/device.map
+    ( cd /usr/share/grub/*; cp -p stage? e2fs_stage1_5 $grub_dir )
+    grub --device-map=$grub_dir/device.map <<EOF
 root (hd0,$partN)
-setup --prefix=/boot/grub (hd0)
+setup --prefix=$grub_prefix (hd0)
 EOF
     rc=$?
     if [ $rc -ne 0 ]; then
@@ -175,6 +214,10 @@ EOF
     e2label $candidate_dev RootUpdate
 
     rm -rf $tmpdir
+    if [ "$OVIRT_ISCSI_ENABLED" == "y" ]; then 
+        # copy default for when Root/HostVG is inaccessible(iscsi upgrade
+        cp $OVIRT_DEFAULTS /boot
+    fi
     log "done."
 }
 
diff --git a/scripts/ovirt-config-storage b/scripts/ovirt-config-storage
index 57aaebd..f9a5b41 100755
--- a/scripts/ovirt-config-storage
+++ b/scripts/ovirt-config-storage
@@ -21,13 +21,13 @@ if is_booted_from_local_disk; then
 fi
 
 default_overcommit=0.5
-
+default_boot_size=50
 default_root_size=256
 default_config_size=5
 default_logging_size=2048
 # -1 indicates data partition should use remaining disk
 default_data_size=-1
-
+boot_min_size=50
 root_min_size=256
 config_min_size=5
 logging_min_size=5
@@ -206,6 +206,11 @@ get_dev_name()
 do_configure()
 {
     local name_and_size
+    if [ "$OVIRT_ISCSI_ENABLED" == "y" ]; then
+        printf "\n\nPlease select the disk to use for the Boot partition.\n\n"
+        BOOTDRIVE=$(get_dev_name) || return 0
+        get_drive_size $BOOTDRIVE BOOTDRIVESPACE
+    fi
     printf "\n\nPlease select the disk to use for the Root.\n\n"
     ROOTDRIVE=$(get_dev_name) || return 0
     get_drive_size $ROOTDRIVE ROOTDRIVESPACE
@@ -230,7 +235,12 @@ do_configure()
     fi
 
     local space_left=$HOSTVGDRIVESPACE
-    for part in swap root config logging data ; do
+    if [ "$OVIRT_ISCSI_ENABLED" == "y" ]; then
+        partlist="boot swap root config logging data"
+    else
+        partlist="swap root config logging data"
+    fi
+    for part in $partlist ; do
         part_regexp="^0$"
         if [ "$part" = "data" ]; then
             part_regexp="^\-1|0$"
@@ -276,12 +286,19 @@ do_configure()
     # save input variables
     augtool <<EOF
 set /files$OVIRT_DEFAULTS/OVIRT_INIT $ROOTDRIVE
+set /files$OVIRT_DEFAULTS/OVIRT_VOL_BOOT_SIZE $BOOT_SIZE
 set /files$OVIRT_DEFAULTS/OVIRT_VOL_SWAP_SIZE $SWAP_SIZE
 set /files$OVIRT_DEFAULTS/OVIRT_VOL_ROOT_SIZE $ROOT_SIZE
 set /files$OVIRT_DEFAULTS/OVIRT_VOL_CONFIG_SIZE $CONFIG_SIZE
 set /files$OVIRT_DEFAULTS/OVIRT_VOL_LOGGING_SIZE $LOGGING_SIZE
 set /files$OVIRT_DEFAULTS/OVIRT_VOL_DATA_SIZE $DATA_SIZE
 EOF
+
+   if [ -n $BOOTDRIVE ]; then
+       augtool <<EOF
+set /files$OVIRT_DEFAULTS/OVIRT_BOOT_INIT $BOOTDRIVE
+EOF
+   fi
 }
 
 do_review()
@@ -356,20 +373,33 @@ perform_partitioning()
     partprobe -s $ROOTDRIVE
 
     MEM_SIZE_MB=$(echo "scale=0; $MEM_SIZE_MB / 1024;" | bc -l)
+    local boot_size_si=$(echo "scale=0; $BOOT_SIZE * (1024 * 1024) / (1000 * 1000)" | bc -l)
     log "Labeling Drive: $ROOTDRIVE"
     parted $ROOTDRIVE -s "mklabel ${LABEL_TYPE}"
+    if [ -n "$BOOTDRIVE" ]; then
+        dd if=/dev/zero of=$BOOTDRIVE bs=1024K count=1
+        blockdev --rereadpt $BOOTDRIVE
+        partprobe -s $BOOTDRIVE
+        log "Creating boot partition"
+        parted $BOOTDRIVE -s "mklabel ${LABEL_TYPE}"
+        parted $BOOTDRIVE -s "mkpartfs primary ext2 0M ${boot_size_si}M"
+    fi
     if [ $ROOTDRIVE != $HOSTVGDRIVE ]; then
         log "Labeling Drive: $HOSTVGDRIVE"
         parted $HOSTVGDRIVE -s "mklabel ${LABEL_TYPE}"
     fi
     log "Creating Root and RootBackup Partitions"
     let RootBackup_end=${ROOT_SIZE}*2
-    parted $ROOTDRIVE -s "mkpartfs primary ext2 0M ${ROOT_SIZE}M"
-    parted $ROOTDRIVE -s "mkpartfs primary ext2 ${ROOT_SIZE}M ${RootBackup_end}M"
+    parted $ROOTDRIVE -s "mkpart primary ext2 0M ${ROOT_SIZE}M"
+    parted $ROOTDRIVE -s "mkpart primary ext2 ${ROOT_SIZE}M ${RootBackup_end}M"
     # sleep to ensure filesystems are created before continuing
     sleep 10
-    e2label ${ROOTDRIVE}1 Root
-    e2label ${ROOTDRIVE}2 RootBackup
+    if [ -n "$BOOTDRIVE" ]; then
+        mke2fs ${BOOTDRIVE}1 -L Boot
+        tune2fs -c 0 -i 0 ${BOOTDRIVE}1
+    fi
+    mke2fs ${ROOTDRIVE}1 -L Root
+    mke2fs ${ROOTDRIVE}2 -L RootBackup
     tune2fs -c 0 -i 0 ${ROOTDRIVE}1
     tune2fs -c 0 -i 0 ${ROOTDRIVE}2
     log "Creating LVM partition"
@@ -468,6 +498,7 @@ perform_partitioning()
 
 do_confirm()
 {
+
     if [ -z "$ROOTDRIVE" ]; then
         printf "\nNo storage device selected.\n"
         return
@@ -502,6 +533,101 @@ do_confirm()
     done
 }
 
+do_iscsi_target()
+{
+while true; do
+    OPTIONS="\"Target IP\" \"Target Port\"" #\"CHAP Username\" \"CHAP Password\""
+    printf "\nPress Enter to leave option blank or Q to quit (default Target Port is 3260)\n"
+    eval set $OPTIONS
+    PS3="Choose an option: "
+    for OPTION in "$@"; do
+        while true; do
+            read -ep "Enter $OPTION: "
+            if [[ $REPLY == "q" || $REPLY == "Q" ]]; then
+                return
+            fi
+
+            if [ "$OPTION" == "Target IP" ]; then
+                OVIRT_ISCSI_TARGET_IP=$REPLY
+                if [ -n "$REPLY" ]; then
+                    break;
+                fi
+
+            elif [ "$OPTION" == "Target Port" ]; then
+                OVIRT_ISCSI_TARGET_PORT=$REPLY
+                if [ -z "$REPLY" ]; then
+                    OVIRT_ISCSI_TARGET_PORT="3260"
+                    break;
+                else
+                    break;
+                fi
+
+            elif [ "$OPTION" == "CHAP Username" ]; then
+                OVIRT_ISCSI_CHAP_USERNAME=$REPLY
+                break
+
+            elif [ "$OPTION" == "CHAP Password" ]; then
+                OVIRT_ISCSI_CHAP_PASSWORD=$REPLY
+                break;
+            fi
+        done
+    done
+
+    cat <<EOF
+
+The iSCSI target be configured as follows:
+================================================
+    Target IP:   $OVIRT_ISCSI_TARGET_IP
+  Target Port:   $OVIRT_ISCSI_TARGET_PORT
+
+EOF
+#     Username:   $OVIRT_ISCSI_CHAP_USERNAME
+#     Password:   $OVIRT_ISCSI_CHAP_PASSWORD
+#EOF
+
+if ask_yes_or_no "Is this correct ([Y]es/[N]o)?" true true; then
+
+    OVIRT_ISCSI_ENABLED="y"
+    augtool <<EOF
+set /files/etc/default/ovirt/OVIRT_ISCSI_ENABLED y
+set /files/etc/default/ovirt/OVIRT_ISCSI_TARGET_IP $OVIRT_ISCSI_TARGET_IP
+set /files/etc/default/ovirt/OVIRT_ISCSI_TARGET_PORT $OVIRT_ISCSI_TARGET_PORT
+EOF
+
+    if [[ -n "$OVIRT_ISCSI_CHAP_USERNAME" && -n "$OVIRT_ISCSI_CHAP_PASSWORD" ]]; then
+        log "setting iscsid.conf username/password"
+        augtool <<EOF
+set /files/etc/iscsi/iscsid.conf/node.session.auth.authmethod CHAP
+set /files/etc/iscsi/iscsid.conf/node.session.auth.username $OVIRT_ISCSI_CHAP_USERNAME
+set /files/etc/iscsi/iscsid.conf/node.session.auth.password $OVIRT_ISCSI_CHAP_PASSWORD
+set /files/etc/default/ovirt/OVIRT_ISCSI_CHAP_USERNAME $OVIRT_ISCSI_CHAP_USERNAME
+set /files/etc/default/ovirt/OVIRT_ISCSI_CHAP_PASSWORD $OVIRT_ISCSI_CHAP_PASSWORD
+EOF
+    fi
+
+    iscsiadm -p $OVIRT_ISCSI_TARGET_IP:$OVIRT_ISCSI_TARGET_PORT -m discovery -t sendtargets
+    log "Restarting iscsi service"
+    service iscsi restart
+
+ISCSI_NODE_NAMES="$(iscsiadm -m discovery -p $OVIRT_ISCSI_TARGET_IP:$OVIRT_ISCSI_TARGET_PORT -t sendtargets|awk {'print $2'})"
+
+printf "\n\n Select iSCSI target node\n\n" >&2
+select OVIRT_ISCSI_NODE_NAME in $ISCSI_NODE_NAMES ; do
+log " Selected Node Name: $OVIRT_ISCSI_NODE_NAME"
+break;
+done
+
+augtool <<EOF
+set /files/etc/default/ovirt/OVIRT_ISCSI_ENABLED y
+set /files/etc/default/ovirt/OVIRT_ISCSI_TARGET_IP $OVIRT_ISCSI_TARGET_IP
+set /files/etc/default/ovirt/OVIRT_ISCSI_TARGET_PORT $OVIRT_ISCSI_TARGET_PORT
+set /files/etc/default/ovirt/OVIRT_ISCSI_NODE_NAME $OVIRT_ISCSI_NODE_NAME
+EOF
+break;
+fi
+done
+}
+
 MEM_SIZE_MB=$(awk '/MemTotal:/ { print $2 }' /proc/meminfo)
 case $MEM_SIZE_MB in
     ''|*[^0-9]*) die failed to get system memory size;;
@@ -527,6 +653,7 @@ fi
 
 CALC_SWAP_SIZE=$(echo "scale=0; ${BASE_SWAP_SIZE} + ${OVERCOMMIT_SWAP_SIZE};" | bc -l)
 
+BOOT_SIZE=${OVIRT_VOL_BOOT_SIZE:-$default_boot_size}
 SWAP_SIZE=${OVIRT_VOL_SWAP_SIZE:-$CALC_SWAP_SIZE}
 ROOT_SIZE=${OVIRT_VOL_ROOT_SIZE:-$default_root_size}
 CONFIG_SIZE=${OVIRT_VOL_CONFIG_SIZE:-$default_config_size}
@@ -577,6 +704,7 @@ else
         select OPTION in "$@"
         do
             case "$OPTION" in
+                "Enable iSCSI Target") do_iscsi_target; break ;;
                 "Configure Storage") do_configure ; break ;;
                 "Review")    do_review    ; break ;;
                 "Commit Changes And Quit") do_confirm   ; break ;;
diff --git a/scripts/ovirt-functions b/scripts/ovirt-functions
index 7cf8613..7cd9c81 100644
--- a/scripts/ovirt-functions
+++ b/scripts/ovirt-functions
@@ -304,6 +304,14 @@ mount_config() {
     fi
 }
 
+mount_boot() {
+
+    if grep -q " /boot " /etc/mtab; then
+       return 0
+    fi
+    mkdir -p /boot
+    mount /dev/disk/by-label/Boot /boot
+}
 # stop any service which keeps /var/log busy
 # keep the list of services
 unmount_logging_services() {
-- 
1.6.5.2




More information about the ovirt-devel mailing list