[Ovirt-devel] [PATCH node] ovirt-config-boot - minimal installer for livecd image to local disk

Alan Pevec apevec at redhat.com
Fri Dec 12 18:32:12 UTC 2008


LiveOS folder is copied to /dev/HostVG/Root LVM volume,
kernel,initrd and GRUB are installed to /dev/HostVG/Boot partition.

livecd initrd is modified on the fly to support LVM,
which is not included in initramfs produced by mayflower/mkliveinitrd

Example usage:
ovirt-config-boot "$disk" /live "$bootparam1 $bootparam2"
caller is responsible to issue reboot

Signed-off-by: Alan Pevec <apevec at redhat.com>
---
 Makefile.am               |    1 +
 ovirt-node.spec.in        |    5 ++
 scripts/ovirt-config-boot |  122 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 128 insertions(+), 0 deletions(-)
 create mode 100755 scripts/ovirt-config-boot

diff --git a/Makefile.am b/Makefile.am
index a47beaa..09ba56b 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -27,6 +27,7 @@ EXTRA_DIST =			\
   scripts/collectd.conf.in	\
   scripts/ovirt			\
   scripts/ovirt-awake		\
+  scripts/ovirt-config-boot  \
   scripts/ovirt-config-logging  \
   scripts/ovirt-config-networking \
   scripts/ovirt-config-password \
diff --git a/ovirt-node.spec.in b/ovirt-node.spec.in
index ef49b39..8303537 100644
--- a/ovirt-node.spec.in
+++ b/ovirt-node.spec.in
@@ -35,6 +35,7 @@ Requires:       bind-utils
 # qemu-img RPM.
 Requires:       qemu-img
 Requires:       nc
+Requires:       grub
 Requires:       /usr/sbin/crond
 ExclusiveArch:  %{ix86} x86_64
 
@@ -111,6 +112,7 @@ cd -
 %{__install} -d -m0755 %{buildroot}%{_sysconfdir}/logrotate.d
 
 %{__install} -p -m0755 scripts/ovirt-awake %{buildroot}%{_sbindir}
+%{__install} -p -m0755 scripts/ovirt-config-boot %{buildroot}%{_sbindir}
 %{__install} -p -m0755 scripts/ovirt-config-logging %{buildroot}%{_sbindir}
 %{__install} -p -m0755 scripts/ovirt-config-networking %{buildroot}%{_sbindir}
 %{__install} -p -m0755 scripts/ovirt-config-password %{buildroot}%{_sbindir}
@@ -202,6 +204,8 @@ fi
 
 %files stateless
 %defattr(-,root,root,0755)
+%{_sbindir}/ovirt-awake
+%{_sbindir}/ovirt-config-boot
 %{_sbindir}/ovirt-config-logging
 %{_sbindir}/ovirt-config-networking
 %{_sbindir}/ovirt-config-password
@@ -242,6 +246,7 @@ fi
 * Thu Dec 11 2008 Perry Myers <pmyers at redhat.com> - 0.96
 - Subpackage stateful/stateless to separate out functionality for
   embedded Node and Node running as part of already installed OS
+- ovirt-config-* setup scripts for standalone mode
 
 * Thu Sep 11 2008 Chris Lalancette <clalance at redhat.com> - 0.92 0.7
 - Add the ovirt-install- and ovirt-uninstall-node scripts, and refactor
diff --git a/scripts/ovirt-config-boot b/scripts/ovirt-config-boot
new file mode 100755
index 0000000..ad0aeb1
--- /dev/null
+++ b/scripts/ovirt-config-boot
@@ -0,0 +1,122 @@
+#!/bin/bash
+#
+# ovirt-config-boot - configure local boot disk partition
+
+# SYNOPSIS
+# ovirt-config-boot livecd_path bootparams
+#
+#       boot_disk   - boot disk device e.g. /dev/sda
+#
+#       livecd_path - where livecd media is mounted,
+#                     parent of LiveOS and isolinux folders
+#
+#       bootparams  - extra boot parameters like console=...
+#
+
+# Source functions library
+. /etc/init.d/functions
+. /etc/init.d/ovirt-functions
+
+
+# local_boot_install livecd_path bootparams
+#  livecd_path -livecd media
+#  bootparams - extra boot parameters like console=...
+#
+#  copy oVirt Node image to the local LVM /dev/HostVG
+ovirt_boot_setup() {
+    local disk=$1
+    local live=$2
+    local bootparams=$3
+    printf "installing oVirt Node image ... "
+    mount_boot
+    mount_liveos
+    # install oVirt Node image for local boot
+    if [ -e "$live/syslinux" ]; then
+      syslinux=syslinux
+    elif [ -e "$live/isolinux" ]; then
+      syslinux=isolinux
+    else
+      syslinux=
+    fi
+    rm -rf /boot/grub
+    rm -rf /liveos/LiveOS
+    mkdir -p /boot/grub
+    mkdir -p /liveos/LiveOS
+    cp -p $live/LiveOS/squashfs.img /liveos/LiveOS \
+    && cp -p $live/$syslinux/vmlinuz0 /boot
+    rc=$?
+    if [ $rc -ne 0 ]; then
+      printf "image copy failed\n"
+      return $rc
+    fi
+    # append LVM support to the livecd initramfs
+    tmpdir=$(mktemp -d)
+    cd $tmpdir
+    gzip -dc $live/$syslinux/initrd0.img |
+        cpio -id init sbin/real-init 2> /dev/null
+    init_script=init
+    if [ -e sbin/real-init ]; then
+        # Fedora 10 mkliveinitrd
+        init_script=sbin/real-init
+    fi
+    sed -i '/^\/sbin\/udev.*settle/ a \echo Scanning logical volumes\
+lvm vgscan --ignorelockingfailure\
+echo Activating logical volumes\
+lvm vgchange -ay --ignorelockingfailure HostVG \
+' $init_script
+    # fix emergency shell
+    sed -i 's/^    bash$/    bash < \/dev\/console/' $init_script
+    # do not fail if device node already exists
+    sed -i 's/mknod.*$/& || :/' $init_script
+    mkdir -p bin
+    bit=
+    if [ -e /lib64 ]; then
+        bit=64
+    fi
+    mkdir -p lib$bit
+    if [ -e /sbin/lvm.static ]; then
+        cp /sbin/lvm.static bin/lvm
+    else
+        cp /sbin/lvm bin
+        # 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 - > /boot/initrd0.img
+
+    cat > /boot/grub/grub.conf << EOF
+default=0
+timeout=5
+hiddenmenu
+title oVirt Node
+    root (hd0,0)
+    kernel /vmlinuz0 ro root=/dev/HostVG/Root roottypefs=ext3 liveimg $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 > /dev/null <<EOF
+root (hd0,0)
+setup --prefix=/grub (hd0)
+EOF
+    rc=$?
+    if [ $rc -ne 0 ]; then
+        printf "boot loader install failed\n"
+        return $rc
+    fi
+
+    # 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
+    sync; sync; sync
+    # caller decides when to reboot
+    rm -rf $tmpdir
+    printf "done.\n"
+}
+
+
+ovirt_boot_setup "$1" "$2" "$3"
+
-- 
1.6.0.4




More information about the ovirt-devel mailing list