[Ovirt-devel] [PATCH node] Added support for local storage configuration.
Darryl L. Pierce
dpierce at redhat.com
Wed Nov 12 21:24:16 UTC 2008
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 | 156 ++++++++++++++++++++++++++++++++++++++++++
1 files changed, 156 insertions(+), 0 deletions(-)
diff --git a/scripts/ovirt-config-storage b/scripts/ovirt-config-storage
index c856ef1..e30c36e 100755
--- a/scripts/ovirt-config-storage
+++ b/scripts/ovirt-config-storage
@@ -1,2 +1,158 @@
#!/bin/bash
#
+# All sizes are in megabytes
+
+DRIVE=$(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)
+
+SPACE=$(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 ' /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"
+
+MEM_SIZE=$(virsh -c qemu:///system nodeinfo | awk '/Memory size/ { print $3 }')
+MEM_SIZE=$(echo "scale=0; $MEM_SIZE / 1024" | bc -l)
+SWAP_SIZE=$MEM_SIZE
+
+function do_resolve_sizes
+{
+ DATA_SIZE=$(echo "scale=0; ($SPACE - $BOOT_SIZE - $SWAP_SIZE - $ROOT_SIZE - $CONFIG_SIZE - $LOGGING_SIZE)" | bc -l)
+}
+
+function do_configure
+{
+ read -p "Swap partition size (Currently ${SWAP_SIZE} MB)? "
+ if [[ $REPLY =~ ^[0-9]+$ ]] && [[ $REPLY -gt 0 ]]; then
+ SWAP_SIZE=$REPLY
+ else
+ printf "Swap value is invalid: retaining ${SWAP_SIZE} MB.\n"
+ fi
+
+ read -p "Boot partition size (Currently ${BOOT_SIZE} MB)? "
+ if [[ $REPLY =~ ^[0-9]+$ ]] && [[ $REPLY -gt 0 ]]; then
+ BOOT_SIZE=$REPLY
+ else
+ printf "Boot value is invalid: retaining ${BOOT_SIZE}.\n"
+ fi
+
+ read -p "Root partition size (Current ${ROOT_SIZE} MB)? "
+ if [[ $REPLY =~ ^[0-9]+$ ]] && [[ $REPLY -gt 0 ]]; then
+ ROOT_SIZE=$REPLY
+ else
+ printf "Install size is invalid: retaining ${ROOT_SIZE} MB.\n"
+ fi
+
+ do_resolve_sizes
+}
+
+function do_review
+{
+ printf "\n"
+ printf "The local disk will be repartitioned as follows:\n"
+ printf "================================================\n"
+ printf " Physical Hard Disk: ${DRIVE}\n"
+ printf " Total storage available: ${SPACE} MB\n"
+ printf " Boot partition size: ${BOOT_SIZE} MB\n"
+ printf " Swap partition size: ${SWAP_SIZE} MB\n"
+ printf " Installation partition size: ${ROOT_SIZE} MB\n"
+ printf " Configuration partition size: ${CONFIG_SIZE} MB\n"
+ printf " Logging partition size: ${LOGGING_SIZE} MB\n"
+ printf " Data partition size: ${DATA_SIZE} MB\n"
+ printf "\n"
+}
+
+function do_partitioning
+{
+ while true; do
+ printf "\n"
+ printf "!!WARNING!!WARNING!!WARNING!!WARNING!!WARNING!!WARNING!!WARNING!!WARNING!!WARNING!!WARNING!!WARNING!!\n"
+ printf "!!WARNING!!WARNING!!WARNING!!WARNING!!WARNING!!WARNING!!WARNING!!WARNING!!WARNING!!WARNING!!WARNING!!\n"
+ printf "!!WARNING!! !!WARNING!!\n"
+ printf "!!WARNING!! !!WARNING!!\n"
+ printf "!!WARNING!! If you proceed this will destroy all data on your local system, and !!WARNING!!\n"
+ printf "!!WARNING!! your hard disk will be irreversably reconfiguration. !!WARNING!!\n"
+ printf "!!WARNING!! !!WARNING!!\n"
+ printf "!!WARNING!! !!WARNING!!\n"
+ printf "!!WARNING!!WARNING!!WARNING!!WARNING!!WARNING!!WARNING!!WARNING!!WARNING!!WARNING!!WARNING!!WARNING!!\n"
+ printf "!!WARNING!!WARNING!!WARNING!!WARNING!!WARNING!!WARNING!!WARNING!!WARNING!!WARNING!!WARNING!!WARNING!!\n"
+ printf "\n"
+ printf "\tContinue? (Y/n) "
+ read
+ case $REPLY in
+ Y|y)
+ printf "Preparing local storage. Please wait..."
+
+ {
+ vgroups=$(vgdisplay -C | awk '{ print $1" "; }')
+ vgremove -f $vgroups
+
+ dd if=/dev/zero of=$DRIVE bs=1K count=1
+ blockdev --rereadpt $DRIVE
+ partprobe -s $DRIVE
+
+ parted $DRIVE -s "mklabel msdos"
+ parted $DRIVE -s "mkpart primary ext2 0.0 ${BOOT_SIZE}M"
+ parted $DRIVE -s "mkpart primary ext2 ${BOOT_SIZE}M -1s"
+ parted $DRIVE -s "set 2 lvm on"
+
+ pvcreate "${DRIVE}2"
+ pvck
+ vgcreate /dev/HostVG "${DRIVE}2"
+
+ lvcreate --name Swap /dev/HostVG --size ${SWAP_SIZE}M
+ lvcreate --name Root /dev/HostVG --size ${ROOT_SIZE}M
+ lvcreate --name Config /dev/HostVG --size ${CONFIG_SIZE}M
+ lvcreate --name Logging /dev/HostVG --size ${LOGGING_SIZE}M
+ lvcreate --name Data /dev/HostVG --size ${DATA_SIZE}M
+
+ mke2fs -T ext2 "${DRIVE}1" -L "BOOT"
+ mke2fs -T swap /dev/HostVG/Swap
+ mke2fs -T ext2 /dev/HostVG/Root -L "ROOT"
+ mke2fs -T ext3 /dev/HostVG/Config -L "CONFIG"
+ mke2fs -T ext3 /dev/HostVG/Logging -L "LOGGING"
+ mke2fs -T ext3 /dev/HostVG/Data -L "DATA"
+ } > partition.log 2>&1
+
+ printf "Completed!\n\n"
+ break ;;
+ N|n) return ;;
+ esac
+ done
+}
+
+while true; do
+ do_resolve_sizes
+
+ 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_partitioning ; break ;;
+ "Quit") exit ;;
+ esac
+ done
+done
--
1.5.6.5
More information about the ovirt-devel
mailing list