[Ovirt-devel] [PATCH node] Added support for local storage configuration.

Darryl L. Pierce dpierce at redhat.com
Mon Nov 17 22:08:16 UTC 2008


From: Darryl L. Pierce <dpierce redhat com>

NOTE: This is a reduxed patch based on Jim Meyering's changes, and includes
updates to support automated execution.

This patch wipes out the entire disk on the node and replaces it with
a set of partitions. The partitions are a raw partition to hold the bootable
kernel, and the rest of the disk is taken up as an physical volume.

On the physical volume is created the following logical volumes:

 * SWAP    - swap partition
 * ROOT    - to host the node image
 * CONFIG  - to hold node configuration data
 * LOGGING - to hold local logs
 * DATA    - to hold VM images

Signed-off-by: Darryl L. Pierce <dpierce at redhat.com>
---
 scripts/ovirt-config-storage |  224 ++++++++++++++++++++++++++++++++++++++++++
 scripts/ovirt-firstboot      |    5 +
 2 files changed, 229 insertions(+), 0 deletions(-)

diff --git a/scripts/ovirt-config-storage b/scripts/ovirt-config-storage
index c856ef1..e3b3592 100755
--- a/scripts/ovirt-config-storage
+++ b/scripts/ovirt-config-storage
@@ -1,2 +1,226 @@
 #!/bin/bash
 #
+# To automate the partitioning, pass in the specific fields in this order
+# ovirt-config-storage [swap size] [boot size] [root size] [logging size]
+#
+# All sizes are in megabytes
+#
+
+ME=$(basename "$0")
+warn() { printf '%s: %s\n' "$ME" "$*" >&2; }
+die() { warn "$*"; exit 1; }
+
+check_partition_sizes()
+{
+    # FIXME: use this function before performing any partitioning, auto or not
+    :
+    # Perform some sanity checks.  E.g.,
+    # What if DATA_SIZE ends up zero or negative?
+    # What if any of those partition sizes is smaller than
+    # the minimum size for an ext3 partition?  Diagnose it here
+    # or just let the mke2fs failure suffice.
+}
+
+do_configure()
+{
+    DEVICES=$(for drive in `hal-find-by-capability --capability storage`; do
+        info=$(lshal -u $drive -s)
+        if [[ $info =~ "storage.drive_type = 'disk'" ]]; then
+             lshal -u $drive -s | awk ' /block.device/ {
+                    match($0, "block.device = *'"'"'(.*)'"'"'", device)
+                    printf "%s", device[1]
+            }'
+        fi
+    done)
+
+    DEVICES="$DEVICES Abort"
+
+    select DEVICE in $DEVICES
+    do
+        case "$DEVICE" in
+            "Abort") return ;;
+
+            *)
+                DRIVE=$DEVICE
+                SPACE=$(for drive in `hal-find-by-capability --capability storage`; do
+                    info=$(lshal -u $drive -s)
+                    if [[ $info =~ $DRIVE ]]; then
+                         lshal -u $drive -s | awk ' /storage.size/ {
+                                match($0, "storage.size *= *([0-9]+)", device)
+                                printf "%s", device[1]
+                        }'
+                    fi
+                done)
+
+                SPACE=$(echo "scale=0; $SPACE / (1024 * 1024)" | bc -l)
+                BOOT_SIZE="256"
+                ROOT_SIZE="256"
+                CONFIG_SIZE="5"
+                LOGGING_SIZE="256"
+
+                for i in swap boot root logging config; do
+                    uc=$(echo $i|tr '[[:lower:]]' '[[:upper:]]')
+                    var=${uc}_SIZE
+                    eval "size=\$$var"
+                    read -p "Change $i partition size (Currently $size MB)? "
+                    if [[ $REPLY =~ ^[0-9]+$ ]] && [[ $REPLY -gt 0 ]]; then
+                        eval "$var=$REPLY"
+                    else
+                        printf "invalid value: '$i'.  retaining $size MB.\n"
+                    fi
+                done
+
+                return
+                ;;
+        esac
+    done
+}
+
+do_review()
+{
+    if [ -z "$DRIVE" ]; then
+        printf "\nNo storage device selected.\n"
+        return
+    fi
+
+    cat <<EOF
+
+The local disk will be repartitioned as follows:
+================================================
+           Physical Hard Disk: $DRIVE
+      Total storage available: $SPACE MB
+          Swap partition size: $SWAP_SIZE MB
+          Boot partition size: $BOOT_SIZE MB
+  Installation partition size: $ROOT_SIZE MB
+ Configuration partition size: $CONFIG_SIZE MB
+       Logging partition size: $LOGGING_SIZE MB
+
+EOF
+}
+
+perform_partitioning()
+{
+    if [ -z "$DRIVE" ]; then
+        printf "\nNo storage device selected.\n"
+        return
+    fi
+
+    printf "Preparing local storage. Please wait..."
+
+    {
+    vgroups=$(vgdisplay -C | awk '{ print $1" "; }')
+    vgremove -f $vgroups
+
+    # Exit upon any failure.
+    set -e
+
+    dd if=/dev/zero of=$DRIVE bs=1K count=1
+    blockdev --rereadpt $DRIVE
+    partprobe -s $DRIVE
+
+    parted $DRIVE -s "mklabel gpt"
+    parted $DRIVE -s "mkpart primary ext2 0M ${BOOT_SIZE}M"
+    parted $DRIVE -s "mkpart primary ext2 ${BOOT_SIZE}M ${SPACE}M"
+    parted $DRIVE -s "set 2 lvm on"
+
+    pvcreate "${DRIVE}2"
+    pvck
+    vgcreate /dev/HostVG "${DRIVE}2"
+
+    lvcreate --name Swap    --size ${SWAP_SIZE}M    /dev/HostVG
+    lvcreate --name Root    --size ${ROOT_SIZE}M    /dev/HostVG
+    lvcreate --name Config  --size ${CONFIG_SIZE}M  /dev/HostVG
+    lvcreate --name Logging --size ${LOGGING_SIZE}M /dev/HostVG
+    lvcreate --name Data    -l 100%FREE             /dev/HostVG
+
+    mke2fs -T ext3 "${DRIVE}1"         -L "BOOT"
+    tune2fs -c 0 -i 0 "${DRIVE}1"
+    mkswap /dev/HostVG/Swap
+    mke2fs -T ext3 /dev/HostVG/Root    -L "ROOT"
+    tune2fs -c 0 -i 0 /dev/HostVG/Root
+    mke2fs -T ext3 /dev/HostVG/Config  -L "CONFIG"
+    tune2fs -c 0 -i 0 /dev/HostVG/Config
+    mke2fs -T ext3 /dev/HostVG/Logging -L "LOGGING"
+    tune2fs -c 0 -i 0 /dev/HostVG/Logging
+    mke2fs -T ext3 /dev/HostVG/Data    -L "DATA"
+    tune2fs -c 0 -i 0 /dev/HostVG/Data
+    } > /var/log/ovirt-partition.log 2>&1
+
+    printf "Completed!\n\n"
+}
+
+do_confirm()
+{
+    if [ -z "$DRIVE" ]; then
+        printf "\nNo storage device selected.\n"
+        return
+    fi
+
+    while true; do
+        sp='                                                    '
+        w='!!WARNING'
+        wb="$w"'!!'
+        w8="$w$w$w$w$w$w$w$w"
+        printf '%s!!\n' \
+          "$w8" \
+          "$w8" \
+          "$wb$sp$w" \
+          "$wb$sp$w" \
+          "$wb    If you proceed, this will destroy all data on your local" \
+          "$wb    system, and your hard disk will be irreversably reconfigured" \
+          "$wb$sp$w" \
+          "$wb$sp$w" \
+        "$w8" \
+        "$w8"
+        printf "\n\tContinue? (Y/n) "
+        read
+        case $REPLY in
+            Y|y)
+                check_partition_sizes
+                perform_partitioning
+                break
+                ;;
+            N|n)  return ;;
+        esac
+    done
+}
+
+MEM_SIZE=$(virsh --readonly -c qemu:///system nodeinfo \
+           | awk '/Memory size/ { print $3 }')
+case $MEM_SIZE in
+    ''|*[^0-9]*) die failed to get system memory size;;
+esac
+
+MEM_SIZE=$(echo "scale=0; $MEM_SIZE / 1024" | bc -l)
+SWAP_SIZE=$MEM_SIZE
+
+if [ "$1" == "AUTO" ]; then
+    DRIVE=$OVIRT_VOL
+    if [ -n "$OVIRT_BOOT_SIZE" ]; then BOOT_SIZE=$OVIRT_BOOT_SIZE; else BOOT_SIZE=256; fi
+    if [ -n "$OVIRT_ROOT_SIZE" ]; then ROOT_SIZE=$OVIRT_ROOT_SIZE; else ROOT_SIZE=256; fi
+    if [ -n "$OVIRT_LOGGING_SIZE" ]; then LOGGING_SIZE=$OVIRT_LOGGING_SIZE; else LOGGING_SIZE=512; fi
+    if [ -n "$OVIRT_CONFIG_SIZE" ]; then CONFIG_SIZE=$OVIRT_CONFIG_SIZE; else CONFIG_SIZE=5; fi
+    check_partition_sizes
+    printf "Partitioning hard disk..."
+    perform_partitioning
+    printf "[DONE]\n"
+    exit 0
+else
+    while true; do
+
+        OPTIONS="Configure Review Partition Quit"
+        PS3="Choose an option: "
+
+        printf "\n"
+
+        select OPTION in $OPTIONS
+        do
+            case "$OPTION" in
+                "Configure") do_configure ; break ;;
+                "Review")    do_review    ; break ;;
+                "Partition") do_confirm   ; break ;;
+                "Quit")      exit ;;
+            esac
+        done
+    done
+fi
diff --git a/scripts/ovirt-firstboot b/scripts/ovirt-firstboot
index 82d9e48..2a334e6 100755
--- a/scripts/ovirt-firstboot
+++ b/scripts/ovirt-firstboot
@@ -29,6 +29,11 @@
 
 start ()
 {
+    if [ -n "$OVIRT_VOL" ]; then
+        INTERACTIVE="N"
+        ovirt-config-storage AUTO
+    fi
+
     ovirt-config-setup
 }
 
-- 
1.5.6.5




More information about the ovirt-devel mailing list