[Ovirt-devel] [PATCH node] improve ovirt-config-boot
Alan Pevec
apevec at redhat.com
Tue Feb 3 03:44:16 UTC 2009
setup two Root LVs, install into non-active and switch them just before
reboot
drop drive from parameters, always use /dev/disk/by-label/BOOT to find
the boot partition
enable post-install hooks for e.g. Cobbler PXE-only-once feature
Signed-off-by: Alan Pevec <apevec at redhat.com>
---
ovirt-node.spec.in | 4 ++
scripts/ovirt-config-boot | 83 ++++++++++++++++++-------------------
scripts/ovirt-config-boot-wrapper | 5 ++-
scripts/ovirt-config-storage | 11 +++--
scripts/ovirt-early | 3 +-
scripts/ovirt-firstboot | 3 +-
scripts/ovirt-functions | 29 ++++++++----
7 files changed, 79 insertions(+), 59 deletions(-)
diff --git a/ovirt-node.spec.in b/ovirt-node.spec.in
index 287a29f..5226131 100644
--- a/ovirt-node.spec.in
+++ b/ovirt-node.spec.in
@@ -190,6 +190,9 @@ mkdir -p %{buildroot}/usr/lib/anaconda-runtime
install -p -m 644 images/syslinux-vesa-splash.jpg %{buildroot}/usr/lib/anaconda-runtime
# ovirt-logos
+# ovirt-config-boot post-install hooks
+%{__install} -d -m0755 %{buildroot}%{_sysconfdir}/ovirt-config-boot.d
+
# default ovirt-config-setup menu options
%{__install} -d -m0755 %{buildroot}%{_sysconfdir}/ovirt-config-setup.d
%{__ln_s} ../..%{_sbindir}/ovirt-config-storage %{buildroot}%{_sysconfdir}/ovirt-config-setup.d/"00_Disk Partitioning"
@@ -283,6 +286,7 @@ fi
%config %{_sysconfdir}/cron.hourly/ovirt-kinit
%config %{_sysconfdir}/logrotate.d/ovirt-logrotate.conf
%config %{_sysconfdir}/cron.hourly/ovirt-logrotate
+%{_sysconfdir}/ovirt-config-boot.d
%{_sysconfdir}/ovirt-config-setup.d
%files stateful
diff --git a/scripts/ovirt-config-boot b/scripts/ovirt-config-boot
index 30ad8df..34d696f 100755
--- a/scripts/ovirt-config-boot
+++ b/scripts/ovirt-config-boot
@@ -3,10 +3,7 @@
# ovirt-config-boot - configure local boot/root disk partitions
# SYNOPSIS
-# ovirt-config-boot boot_disk livecd_path bootparams reboot
-#
-# boot_disk - boot disk device e.g. /dev/sda
-# default is $OVIRT_INIT
+# ovirt-config-boot livecd_path bootparams reboot
#
# livecd_path - where livecd media is mounted,
# parent of LiveOS and isolinux folders
@@ -26,20 +23,32 @@ trap '__st=$?; stop_log; exit $__st' 0
trap 'exit $?' 1 2 13 15
ovirt_boot_setup() {
- local disk=$1
- local live=$2
- local bootparams=$3
+ local live=$1
+ local bootparams=$2
+ local disk
+ local partN=-1
log "installing oVirt Node image."
mount_boot
# check that /boot mounted ok and find partition number for GRUB
- BOOT=$(mount|awk '$3 == "/boot" {print $1}')
- BOOT=$(( ${BOOT#$disk} - 1 ))
+ eval $(mount|awk '$3 == "/boot" {
+ print "disk=" substr($1,1,length($1)-1);
+ partN=substr($1,length($1),1); partN--;
+ print "partN=" partN;
+ }')
rc=$?
- if [ $rc -ne 0 -o $BOOT -lt 0 ]; then
+ if [ $rc -ne 0 -o $partN -lt 0 ]; then
log "boot partition not available."
+ return 1
+ fi
+ mkdir -p /liveos
+ # prepare Root partition update
+ lvrename HostVG RootBackup RootNew \
+ && mount /dev/HostVG/RootNew /liveos
+ rc=$?
+ if [ $rc -ne 0 ]; then
+ log "root partition not available."
return $rc
fi
- mount_liveos
# install oVirt Node image for local boot
if [ -e "$live/syslinux" ]; then
syslinux=syslinux
@@ -96,21 +105,24 @@ lvm vgchange -ay --ignorelockingfailure HostVG \
gzip -9 |
cat $live/$syslinux/initrd0.img - > /boot/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="console=tty0 $(echo $bootparams | sed s/console=tty0//g)"
+ bootparams="ro root=/dev/HostVG/Root roottypefs=ext3 console=tty0 \
+ $(echo $bootparams | sed s/console=tty0//g)"
cat > /boot/grub/grub.conf << EOF
default=0
timeout=5
hiddenmenu
-title oVirt Node
- root (hd0,$BOOT)
- kernel /vmlinuz0 ro root=/dev/HostVG/Root roottypefs=ext3 liveimg $bootparams
+title oVirt Node (${version}-${release})
+ root (hd0,$partN)
+ kernel /vmlinuz0 $bootparams
initrd /initrd0.img
EOF
echo "(hd0) $disk" > /boot/grub/device.map
( cd /usr/share/grub/*; cp -p stage? e2fs_stage1_5 /boot/grub )
grub --device-map=/boot/grub/device.map <<EOF
-root (hd0,$BOOT)
+root (hd0,$partN)
setup --prefix=/grub (hd0)
EOF
rc=$?
@@ -120,47 +132,34 @@ EOF
fi
umount /liveos
umount /boot
+ # mark new Root ready to go, reboot() in ovirt-function switches it to active
+ lvrename HostVG RootNew RootUpdate
- # caller decides when to reboot
rm -rf $tmpdir
log "done."
- # avoid reboot loops using Cobbler PXE only once
- # Cobbler XMLRPC post-install trigger (XXX is there cobbler SRV record?):
- # wget "http://192.168.50.2/cblr/svc/op/trig/mode/post/system/$(hostname)"
- # -O /dev/null
}
start_log
-disk=$1
-live=$2
-bootparams=$3
-doreboot=$4
-if [ -z "$disk" ]; then
- disk=$OVIRT_INIT
-fi
-if [ -z "$live" ]; then
- mount_live
- live=/live
+live=$1
+bootparams=$2
+doreboot=$3
+if [ -z "$live" -o "$live" = "-h" -o "$live" = "--help" ]; then
+ echo "Usasge: $0 livecd_path bootparams reboot(yes/no)"
fi
if [ -z "$bootparams" ]; then
bootparams="$OVIRT_BOOTPARAMS"
fi
-
-# ensure the disk is not blank
-parted $disk -s "print all"
-
-if [ 0 -eq $? ]; then
- ovirt_boot_setup "$disk" "$live" "$bootparams"
-else
- log "Please configure $disk before attempting to install the node image."
- log "Use the option 'Disk Partitioning' from the main menu."
- doreboot="no"
+if [ -z "$doreboot" ]; then
+ doreboot="yes"
fi
-if [ -z "$doreboot" -o "$doreboot" = "yes" ]; then
+ovirt_boot_setup "$live" "$bootparams"
+rc=$?
+if [ $rc -eq 0 -a "$doreboot" = "yes" ]; then
disable_firstboot
ovirt_store_firstboot_config
stop_log
reboot
fi
stop_log
+exit $rc
diff --git a/scripts/ovirt-config-boot-wrapper b/scripts/ovirt-config-boot-wrapper
index 7e1c85b..a829f99 100755
--- a/scripts/ovirt-config-boot-wrapper
+++ b/scripts/ovirt-config-boot-wrapper
@@ -3,6 +3,8 @@
# Wrapper function to make sure the user wishes to continue before
# rebooting the system
+. /etc/init.d/ovirt-functions
+
while true; do
clear
printf "\n\n oVirt Node Local Installation and Reboot\n\n"
@@ -15,7 +17,8 @@ continuing."
read -p "Do you wish to continue? (Y|N)? "
r=$(echo $REPLY|tr '[[:lower:]]' '[[:upper:]]')
if [ "$r" == "Y" ]; then
- /usr/sbin/ovirt-config-boot
+ mount_live
+ /usr/sbin/ovirt-config-boot /live
break
elif [ "$r" == "N" ]; then
printf "\nExiting back to the menu\n"
diff --git a/scripts/ovirt-config-storage b/scripts/ovirt-config-storage
index 35b4461..faaf006 100755
--- a/scripts/ovirt-config-storage
+++ b/scripts/ovirt-config-storage
@@ -67,7 +67,7 @@ check_partition_sizes()
get_selected_drive_size
disk_size=$SPACE
need_size=$(echo "scale=0;" \
- "$BOOT_SIZE + $SWAP_SIZE + $ROOT_SIZE" \
+ "$BOOT_SIZE + $SWAP_SIZE + $ROOT_SIZE * 2" \
"+ $CONFIG_SIZE + $LOGGING_SIZE + $min_data_size" | bc -l)
if [ $need_size -gt $disk_size ]; then
@@ -224,7 +224,7 @@ do_review()
local data_size_display="$DATA_SIZE MB"
if [ "$DATA_SIZE" = -1 ]; then
local remaining_mb=$(( $SPACE - $BOOT_SIZE - $SWAP_SIZE \
- - $ROOT_SIZE - $CONFIG_SIZE - $LOGGING_SIZE ))
+ - $ROOT_SIZE * 2 - $CONFIG_SIZE - $LOGGING_SIZE ))
data_size_display="$remaining_mb MB"
fi
@@ -236,7 +236,7 @@ The local disk will be repartitioned as follows:
Total storage available: $SPACE MB
Boot partition size: $BOOT_SIZE MB
Swap partition size: $SWAP_SIZE MB
- Installation partition size: $ROOT_SIZE MB
+ Installation partition size: $ROOT_SIZE * 2 MB
Configuration partition size: $CONFIG_SIZE MB
Logging partition size: $LOGGING_SIZE MB
Data partition size: $data_size_display
@@ -334,10 +334,13 @@ perform_partitioning()
echo "/dev/HostVG/Swap swap swap defaults 0 0" >> /etc/fstab
fi
if [ "$ROOT_SIZE" -gt 0 ]; then
- log "Creating root partition"
+ log "Creating root and root backup partitions"
lvcreate --name Root --size ${ROOT_SIZE}M /dev/HostVG
mke2fs -j /dev/HostVG/Root -L "ROOT"
tune2fs -c 0 -i 0 /dev/HostVG/Root
+ lvcreate --name RootBackup --size ${ROOT_SIZE}M /dev/HostVG
+ mke2fs -j /dev/HostVG/RootBackup -L "ROOT2"
+ tune2fs -c 0 -i 0 /dev/HostVG/RootBackup
fi
if [ "$CONFIG_SIZE" -gt 0 ]; then
log "Creating config partition"
diff --git a/scripts/ovirt-early b/scripts/ovirt-early
index 7971234..bf39f7f 100755
--- a/scripts/ovirt-early
+++ b/scripts/ovirt-early
@@ -366,7 +366,8 @@ start() {
$BONDING_MODCONF_FILE
if [ $local_boot = 1 ]; then
# local disk installation for managed mode
- ovirt-config-boot $init "" "$bootparams"
+ mount_live
+ ovirt-config-boot /live "$bootparams"
fi
fi
fi
diff --git a/scripts/ovirt-firstboot b/scripts/ovirt-firstboot
index 593a55b..2d87768 100755
--- a/scripts/ovirt-firstboot
+++ b/scripts/ovirt-firstboot
@@ -47,7 +47,8 @@ start ()
ovirt-config-logging AUTO
ovirt-config-collectd AUTO
if [ "$OVIRT_LOCAL_BOOT" = 1 ]; then
- ovirt-config-boot $OVIRT_INIT "" "$OVIRT_BOOTPARAMS" no
+ mount_live
+ ovirt-config-boot /live "$OVIRT_BOOTPARAMS" no
disable_firstboot
reboot
fi
diff --git a/scripts/ovirt-functions b/scripts/ovirt-functions
index 98d5d53..f3ba4fc 100644
--- a/scripts/ovirt-functions
+++ b/scripts/ovirt-functions
@@ -208,16 +208,6 @@ mount_boot() {
mount /dev/disk/by-label/BOOT /boot
}
-# mount liveos partition
-# LiveOS/
-mount_liveos() {
- if grep -q " /liveos " /proc/mounts; then
- return 0
- fi
- mkdir -p /liveos
- mount /dev/HostVG/Root /liveos
-}
-
# mount config partition
# /config for persistance
mount_config() {
@@ -442,3 +432,22 @@ add_if_not_exist() {
is_numeric() {
printf "$1" | grep -q -E '^[0-9]+$'
}
+
+# reboot wrapper
+# cleanup before reboot
+reboot() {
+ # setup new Root if update is prepared
+ if [ -e /dev/HostVG/RootUpdate ]; then
+ lvrename HostVG Root RootBackup
+ lvrename HostVG RootUpdate Root
+ fi
+ # run post-install hooks
+ # e.g. to avoid reboot loops using Cobbler PXE only once
+ # Cobbler XMLRPC post-install trigger (XXX is there cobbler SRV record?):
+ # wget "http://192.168.50.2/cblr/svc/op/trig/mode/post/system/$(hostname)"
+ # -O /dev/null
+ for hook in $(ls /etc/ovirt-config-boot.d/* 2>/dev/null); do
+ $hook
+ done
+ /sbin/reboot
+}
--
1.6.0.6
More information about the ovirt-devel
mailing list