#!/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. # # based on https://groups.google.com/forum/#!searchin/ganeti/debootstrap|sort:date/ganeti/N8_r8lKoA-k/8ExYRnPUAQAJ 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 DISKTYPE=unknown 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 --no-floppy $LODEV ;; *) chroot "$TARGET" grub-install --no-floppy $BLOCKDEV ;; esac cat >> $TARGET/etc/default/grub <