Darryl L. Pierce
2008-Nov-12 13:42 UTC
[Ovirt-devel] [PATCH node] Added support for local storage configuration.
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
Daniel P. Berrange
2008-Nov-12 13:51 UTC
[Ovirt-devel] [PATCH node] Added support for local storage configuration.
On Wed, Nov 12, 2008 at 08:42:52AM -0500, Darryl L. Pierce wrote:> 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.> + 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"Since we've no particular need for MS DOS compatability, how about we just use GPT partitions, avoiding the whole 2TB limit.> + 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"Why no journal on /boot. This means if the host shuts down uncleanly it'll have todo a full fsck.> + mke2fs -T swap /dev/HostVG/SwapThat isn't the way you create a swap partition. You want mkswap. And still need to disable the various auto-fsck settings on all partitions Daniel -- |: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|
Darryl L. Pierce
2008-Nov-12 21:24 UTC
[Ovirt-devel] [PATCH node] Added support for local storage configuration.
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
Darryl L. Pierce
2008-Nov-13 22:05 UTC
[Ovirt-devel] [PATCH node] Added support for local storage configuration.
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 | 199 ++++++++++++++++++++++++++++++++++++++++++
1 files changed, 199 insertions(+), 0 deletions(-)
diff --git a/scripts/ovirt-config-storage b/scripts/ovirt-config-storage
index c856ef1..25962e1 100755
--- a/scripts/ovirt-config-storage
+++ b/scripts/ovirt-config-storage
@@ -1,2 +1,201 @@
#!/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
+#
+
+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
+
+ read -p "Logging partition size (Current ${LOGGING_SIZE} MB)? "
+ if [[ $REPLY =~ ^[0-9]+$ ]] && [[ $REPLY -gt 0 ]]; then
+ LOGGING_SIZE=$REPLY
+ else
+ printf "Install size is invalid: retaining ${LOGGING_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 " Swap partition size: ${SWAP_SIZE} MB\n"
+ printf " Boot partition size: ${BOOT_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 perform_partitioning
+{
+ 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 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 -j -T ext2 "${DRIVE}1" -L "BOOT"
+ tune2fs -c 0 -i 0 "${DRIVE}1"
+ mkswap /dev/HostVG/Swap
+ mke2fs -j -T ext2 /dev/HostVG/Root -L "ROOT"
+ tune2fs -c 0 -i 0 /dev/HostVG/Root
+ mke2fs -j -T ext3 /dev/HostVG/Config -L "CONFIG"
+ tune2fs -c 0 -i 0 /dev/HostVG/Config
+ mke2fs -j -T ext3 /dev/HostVG/Logging -L "LOGGING"
+ tune2fs -c 0 -i 0 /dev/HostVG/Logging
+ mke2fs -j -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"
+}
+
+function do_confirm
+{
+ 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)
+ perform_partitioning; break ;;
+ N|n) return ;;
+ esac
+ done
+}
+
+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
+
+# If the any partition size was provided as a kernel argument,
+# then set the values and run without prompting
+
+counter=0
+while [ "$1" != "" ]; do
+ AUTO="Y"
+ case $counter in
+ 0) SWAP_SIZE=$1; break ;;
+ 1) BOOT_SIZE=$1; break ;;
+ 2) ROOT_SIZE=$1; break ;;
+ 3) LOGGING_SIZE=$1; break ;;
+ esac
+ counter=`expr $counter + 1 `
+ shift
+done
+
+if [ "$AUTO" == "Y" ]; then
+ printf "Partitioning hard disk..."
+ perform_partitioning
+ printf "[DONE]\n"
+ exit 0
+else
+ 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_confirm ; break ;;
+ "Quit") exit ;;
+ esac
+ done
+ done
+fi
--
1.5.6.5
Darryl L. Pierce
2008-Nov-14 14:22 UTC
[Ovirt-devel] [PATCH node] Added support for local storage configuration.
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 | 183 ++++++++++++++++++++++++++++++++++++++++++
1 files changed, 183 insertions(+), 0 deletions(-)
diff --git a/scripts/ovirt-config-storage b/scripts/ovirt-config-storage
index c856ef1..eaaf220 100755
--- a/scripts/ovirt-config-storage
+++ b/scripts/ovirt-config-storage
@@ -1,2 +1,185 @@
#!/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
+#
+
+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
+{
+ for i in swap boot root logging; do
+ uc=$(echo $i|tr '[[:lower:]]' '[[:upper:]]')
+ var=${uc}_SIZE
+ eval "size=\$$var"
+ read -p "$i partition size (Currently $size MB)? "
+ if [[ $REPLY =~ ^[0-9]+$ ]] && [[ $REPLY -gt 0 ]]; then
+ eval "$var=$REPLY"
+ else
+ printf "Invalid value for $i. Retaining $size MB.\n"
+ fi
+ done
+
+ 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 " Swap partition size: ${SWAP_SIZE} MB\n"
+ printf " Boot partition size: ${BOOT_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 perform_partitioning
+{
+ 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 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 -j -T ext2 "${DRIVE}1" -L "BOOT"
+ tune2fs -c 0 -i 0 "${DRIVE}1"
+ mkswap /dev/HostVG/Swap
+ mke2fs -j -T ext2 /dev/HostVG/Root -L "ROOT"
+ tune2fs -c 0 -i 0 /dev/HostVG/Root
+ mke2fs -j -T ext3 /dev/HostVG/Config -L "CONFIG"
+ tune2fs -c 0 -i 0 /dev/HostVG/Config
+ mke2fs -j -T ext3 /dev/HostVG/Logging -L "LOGGING"
+ tune2fs -c 0 -i 0 /dev/HostVG/Logging
+ mke2fs -j -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"
+}
+
+function do_confirm
+{
+ 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)
+ perform_partitioning; break ;;
+ N|n) return ;;
+ esac
+ done
+}
+
+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
+
+# If the any partition size was provided as a kernel argument,
+# then set the values and run without prompting
+
+counter=0
+while [ "$1" != "" ]; do
+ AUTO="Y"
+ case $counter in
+ 0) SWAP_SIZE=$1; break ;;
+ 1) BOOT_SIZE=$1; break ;;
+ 2) ROOT_SIZE=$1; break ;;
+ 3) LOGGING_SIZE=$1; break ;;
+ esac
+ counter=`expr $counter + 1 `
+ shift
+done
+
+if [ "$AUTO" == "Y" ]; then
+ printf "Partitioning hard disk..."
+ perform_partitioning
+ printf "[DONE]\n"
+ exit 0
+else
+ 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_confirm ; break ;;
+ "Quit") exit ;;
+ esac
+ done
+ done
+fi
--
1.5.6.5
Darryl L. Pierce
2008-Nov-14 22:02 UTC
[Ovirt-devel] [PATCH node] Added support for local storage configuration.
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 | 183 ++++++++++++++++++++++++++++++++++++++++++
1 files changed, 183 insertions(+), 0 deletions(-)
diff --git a/scripts/ovirt-config-storage b/scripts/ovirt-config-storage
index c856ef1..eaaf220 100755
--- a/scripts/ovirt-config-storage
+++ b/scripts/ovirt-config-storage
@@ -1,2 +1,185 @@
#!/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
+#
+
+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
+{
+ for i in swap boot root logging; do
+ uc=$(echo $i|tr '[[:lower:]]' '[[:upper:]]')
+ var=${uc}_SIZE
+ eval "size=\$$var"
+ read -p "$i partition size (Currently $size MB)? "
+ if [[ $REPLY =~ ^[0-9]+$ ]] && [[ $REPLY -gt 0 ]]; then
+ eval "$var=$REPLY"
+ else
+ printf "Invalid value for $i. Retaining $size MB.\n"
+ fi
+ done
+
+ 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 " Swap partition size: ${SWAP_SIZE} MB\n"
+ printf " Boot partition size: ${BOOT_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 perform_partitioning
+{
+ 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 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 -j -T ext2 "${DRIVE}1" -L "BOOT"
+ tune2fs -c 0 -i 0 "${DRIVE}1"
+ mkswap /dev/HostVG/Swap
+ mke2fs -j -T ext2 /dev/HostVG/Root -L "ROOT"
+ tune2fs -c 0 -i 0 /dev/HostVG/Root
+ mke2fs -j -T ext3 /dev/HostVG/Config -L "CONFIG"
+ tune2fs -c 0 -i 0 /dev/HostVG/Config
+ mke2fs -j -T ext3 /dev/HostVG/Logging -L "LOGGING"
+ tune2fs -c 0 -i 0 /dev/HostVG/Logging
+ mke2fs -j -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"
+}
+
+function do_confirm
+{
+ 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)
+ perform_partitioning; break ;;
+ N|n) return ;;
+ esac
+ done
+}
+
+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
+
+# If the any partition size was provided as a kernel argument,
+# then set the values and run without prompting
+
+counter=0
+while [ "$1" != "" ]; do
+ AUTO="Y"
+ case $counter in
+ 0) SWAP_SIZE=$1; break ;;
+ 1) BOOT_SIZE=$1; break ;;
+ 2) ROOT_SIZE=$1; break ;;
+ 3) LOGGING_SIZE=$1; break ;;
+ esac
+ counter=`expr $counter + 1 `
+ shift
+done
+
+if [ "$AUTO" == "Y" ]; then
+ printf "Partitioning hard disk..."
+ perform_partitioning
+ printf "[DONE]\n"
+ exit 0
+else
+ 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_confirm ; break ;;
+ "Quit") exit ;;
+ esac
+ done
+ done
+fi
--
1.5.6.5
Darryl L. Pierce
2008-Nov-17 20:49 UTC
[Ovirt-devel] [PATCH node] Added support for local storage configuration.
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
If a kernel argument named OVIRT_VOL is present, then the firstboot script
will run ovirt-config-storage in non-interactive mode. Default values are used
unless environment variables override them.
Signed-off-by: Darryl L. Pierce <dpierce at redhat.com>
---
scripts/ovirt-config-storage | 200 ++++++++++++++++++++++++++++++++++++++++++
scripts/ovirt-firstboot | 6 +-
2 files changed, 205 insertions(+), 1 deletions(-)
diff --git a/scripts/ovirt-config-storage b/scripts/ovirt-config-storage
index c856ef1..04db5ea 100755
--- a/scripts/ovirt-config-storage
+++ b/scripts/ovirt-config-storage
@@ -1,2 +1,202 @@
#!/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
+#
+
+function init
+{
+ 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_CONFIG_SIZE" ]; then
CONFIG_SIZE=$OVIRT_CONFIG_SIZE; else CONFIG_SIZE="5"; fi
+ if [ -n "$OVIRT_LOGGING_SIZE" ]; then
LOGGING_SIZE=$OVIRT_LOGGING_SIZE; else LOGGING_SIZE="256"; fi
+ if [ -n "$OVIRT_DATA_SIZE" ]; then DATA_SIZE=$OVIRT_DATA_SIZE; fi
+
+ 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 resolve_sizes
+{
+ DATA_SIZE=$(echo "scale=0; ($SPACE - $BOOT_SIZE - $SWAP_SIZE -
$ROOT_SIZE - $CONFIG_SIZE - $LOGGING_SIZE)" | bc -l)
+}
+
+function 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)
+
+ 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 for $i. Retaining $size
MB.\n"
+ fi
+ done
+
+ resolve_sizes
+
+ return
+ ;;
+ esac
+ done
+}
+
+function review
+{
+ printf "\n"
+ if [ -n "$DRIVE" ]; then
+ 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 " Swap partition size: ${SWAP_SIZE} MB\n"
+ printf " Boot partition size: ${BOOT_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"
+ else
+ printf "No storage device selected.\n"
+ fi
+}
+
+function perform_partitioning
+{
+ printf "\n"
+ if [ -n "$DRIVE" ]; then
+ 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 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 -j -T ext3 "$DRIVE"1 -L "BOOT"
+ tune2fs -c 0 -i 0 "$DRIVE"1
+ mkswap /dev/HostVG/Swap
+ mke2fs -j -T ext3 /dev/HostVG/Root -L "ROOT"
+ tune2fs -c 0 -i 0 /dev/HostVG/Root
+ mke2fs -j -T ext3 /dev/HostVG/Config -L "CONFIG"
+ tune2fs -c 0 -i 0 /dev/HostVG/Config
+ mke2fs -j -T ext3 /dev/HostVG/Logging -L "LOGGING"
+ tune2fs -c 0 -i 0 /dev/HostVG/Logging
+ mke2fs -j -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"
+ else
+ printf "No storage device selected.\n"
+ fi
+}
+
+function confirm
+{
+ printf "\n"
+ if [ -n "$DRIVE" ]; then
+ while true; do
+ 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)
+ perform_partitioning; break ;;
+ N|n) return ;;
+ esac
+ done
+ else
+ printf "No storage device selected!\n"
+ fi
+}
+
+init
+
+if [ "$1" == "AUTO" ]; then
+ DRIVE=$OVIRT_VOL
+ perform_partitioning
+ printf "[DONE]\n"
+ exit 0
+else
+ while true; do
+ resolve_sizes
+
+ OPTIONS="Configure Review Partition Quit"
+ PS3="Choose an option: "
+
+ printf "\n"
+
+ select OPTION in $OPTIONS
+ do
+ case "$OPTION" in
+ "Configure") configure ; break ;;
+ "Review") review ; break ;;
+ "Partition") confirm ; break ;;
+ "Quit") exit ;;
+ esac
+ done
+ done
+fi
diff --git a/scripts/ovirt-firstboot b/scripts/ovirt-firstboot
index 82d9e48..70a88f1 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
}
@@ -52,4 +57,3 @@ case "$1" in
echo "Usage: ovirt-firstboot {start}"
exit 2
esac
-
--
1.5.6.5
Darryl L. Pierce
2008-Nov-17 22:08 UTC
[Ovirt-devel] [PATCH node] Added support for local storage configuration.
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