From 7d4ea81a4f77b7cee4ff91cf6d672db7e7078d81 Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Wed, 3 Oct 2018 12:48:15 +0200 Subject: [PATCH] grub hook from ganeti list https://groups.google.com/forum/#!searchin/ganeti/debootstrap|sort:date/ganeti/N8_r8lKoA-k/8ExYRnPUAQAJ --- hooks/grub | 102 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100755 hooks/grub diff --git a/hooks/grub b/hooks/grub new file mode 100755 index 0000000..022f8f3 --- /dev/null +++ b/hooks/grub @@ -0,0 +1,102 @@ +#!/bin/bash -x +# +# This is an example script that install and configure grub after installation. +# To use it put it in your CUSTOMIZE_DIR and make it executable. +# +# Do not include grub in EXTRA_PKGS of +# $sysconfdir/default/ganeti-instance-debootstrap because it will +# cause error of debootstrap. + +set -e + +# On wheezy we debootstrap with extlinux instead of grub +if [ $SUITE = "wheezy" ]; then + exit 0 +fi + +. common.sh + +CLEANUP=( ) + +trap cleanup EXIT + +if [ -z "$TARGET" -o ! -d "$TARGET" ]; then + echo "Missing target directory" + exit 1 +fi + +if [[ $BLOCKDEV == /dev/drbd* ]]; then + DISKTYPE=drbd +elif dmsetup info $BLOCKDEV > /dev/null 2>&1; then + DISKTYPE=lvm +else + echo "Unknown disk type" + exit 1 +fi + +mount -o bind /dev $TARGET/dev +CLEANUP+=("umount $TARGET/dev") + +mount -t proc proc $TARGET/proc +CLEANUP+=("umount $TARGET/proc") + +# For some reason, /dev/disk/by-uuid/ is not created. This results in +# grub refusing to specify the root fs uuid on the commandline, instead it +# will use $ROOTDEV which is not available in the VM... +ROOTUUID=$(blkid -o value -s UUID $FSYSDEV) +#ln -s $FSYSDEV /dev/disk/by-uuid/$ROOTUUID +CLEANUP+=("rm /dev/disk/by-uuid/$ROOTUUID") + +chroot "$TARGET" apt-get update +chroot "$TARGET" /usr/bin/env DEBIAN_FRONTEND=noninteractive apt-get -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" install grub2 + +# install grub to make all the modules available ... serial.mod is not available otherwise +chroot "$TARGET" update-grub + +case $DISKTYPE in + lvm) + + # When using LVM, grub thinks we're installing to a partition. Using a loop dev fools it + LODEV=$(losetup --show -f $BLOCKDEV) + CLEANUP+=("losetup -d $LODEV") + + + # BLOCKDEV has the format /dev//, but Grub will be looking + # for /dev/mapper/- ... + # This adds the mapper device to device.map, which is used to translate + # the root device node into grub-syntax (i.e., (hd0)) + + MAPPERDEV=/dev/mapper/$(dmsetup info -C --noheadings -o name $BLOCKDEV) + echo "(hd0) $MAPPERDEV" > $TARGET/boot/grub/device.map + chroot "$TARGET" grub-install $LODEV + ;; + drbd) + chroot "$TARGET" grub-install $BLOCKDEV + ;; +esac + +cat >> $TARGET/etc/default/grub <