3 # This is an example script that install and configure grub after installation.
4 # To use it put it in your CUSTOMIZE_DIR and make it executable.
6 # Do not include grub in EXTRA_PKGS of
7 # $sysconfdir/default/ganeti-instance-debootstrap because it will
8 # cause error of debootstrap.
10 # based on https://groups.google.com/forum/#!searchin/ganeti/debootstrap|sort:date/ganeti/N8_r8lKoA-k/8ExYRnPUAQAJ
14 # On wheezy we debootstrap with extlinux instead of grub
15 if [ $SUITE = "wheezy" ]; then
25 if [ -z "$TARGET" -o ! -d "$TARGET" ]; then
26 echo "Missing target directory"
30 if [[ $BLOCKDEV == /dev/drbd* ]]; then
32 elif dmsetup info $BLOCKDEV > /dev/null 2>&1; then
35 echo "Unknown disk type"
40 mount -o bind /dev $TARGET/dev
41 CLEANUP+=("umount $TARGET/dev")
43 mount -t proc proc $TARGET/proc
44 CLEANUP+=("umount $TARGET/proc")
46 # For some reason, /dev/disk/by-uuid/<UUID> is not created. This results in
47 # grub refusing to specify the root fs uuid on the commandline, instead it
48 # will use $ROOTDEV which is not available in the VM...
49 ROOTUUID=$(blkid -o value -s UUID $FSYSDEV)
50 #ln -s $FSYSDEV /dev/disk/by-uuid/$ROOTUUID
51 CLEANUP+=("rm /dev/disk/by-uuid/$ROOTUUID")
53 chroot "$TARGET" apt-get update
54 chroot "$TARGET" /usr/bin/env DEBIAN_FRONTEND=noninteractive apt-get -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" install grub2
56 # install grub to make all the modules available ... serial.mod is not available otherwise
57 chroot "$TARGET" update-grub
62 # When using LVM, grub thinks we're installing to a partition. Using a loop dev fools it
63 LODEV=$(losetup --show -f $BLOCKDEV)
64 CLEANUP+=("losetup -d $LODEV")
67 # BLOCKDEV has the format /dev/<vgname>/<lvname>, but Grub will be looking
68 # for /dev/mapper/<vgname>-<mangled-lvname> ...
69 # This adds the mapper device to device.map, which is used to translate
70 # the root device node into grub-syntax (i.e., (hd0))
72 MAPPERDEV=/dev/mapper/$(dmsetup info -C --noheadings -o name $BLOCKDEV)
73 echo "(hd0) $MAPPERDEV" > $TARGET/boot/grub/device.map
74 chroot "$TARGET" grub-install --no-floppy $LODEV
77 chroot "$TARGET" grub-install --no-floppy $BLOCKDEV
81 cat >> $TARGET/etc/default/grub <<EOF
82 GRUB_CMDLINE_LINUX="text console=ttyS0,115200n8"
84 GRUB_SERIAL_COMMAND="serial --unit=0 --speed=115200 --word=8 --parity=no --stop=1"
87 # and do it again, serial.mod should now be available
88 chroot "$TARGET" update-grub
92 chroot "$TARGET" grub-install $LODEV
95 chroot "$TARGET" grub-install $BLOCKDEV
99 # For some reason, the loopback device is still busy/open if this sleep is removed ...