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.
12 # On wheezy we debootstrap with extlinux instead of grub
13 if [ $SUITE = "wheezy" ]; then
23 if [ -z "$TARGET" -o ! -d "$TARGET" ]; then
24 echo "Missing target directory"
28 if [[ $BLOCKDEV == /dev/drbd* ]]; then
30 elif dmsetup info $BLOCKDEV > /dev/null 2>&1; then
33 echo "Unknown disk type"
37 mount -o bind /dev $TARGET/dev
38 CLEANUP+=("umount $TARGET/dev")
40 mount -t proc proc $TARGET/proc
41 CLEANUP+=("umount $TARGET/proc")
43 # For some reason, /dev/disk/by-uuid/<UUID> is not created. This results in
44 # grub refusing to specify the root fs uuid on the commandline, instead it
45 # will use $ROOTDEV which is not available in the VM...
46 ROOTUUID=$(blkid -o value -s UUID $FSYSDEV)
47 #ln -s $FSYSDEV /dev/disk/by-uuid/$ROOTUUID
48 CLEANUP+=("rm /dev/disk/by-uuid/$ROOTUUID")
50 chroot "$TARGET" apt-get update
51 chroot "$TARGET" /usr/bin/env DEBIAN_FRONTEND=noninteractive apt-get -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" install grub2
53 # install grub to make all the modules available ... serial.mod is not available otherwise
54 chroot "$TARGET" update-grub
59 # When using LVM, grub thinks we're installing to a partition. Using a loop dev fools it
60 LODEV=$(losetup --show -f $BLOCKDEV)
61 CLEANUP+=("losetup -d $LODEV")
64 # BLOCKDEV has the format /dev/<vgname>/<lvname>, but Grub will be looking
65 # for /dev/mapper/<vgname>-<mangled-lvname> ...
66 # This adds the mapper device to device.map, which is used to translate
67 # the root device node into grub-syntax (i.e., (hd0))
69 MAPPERDEV=/dev/mapper/$(dmsetup info -C --noheadings -o name $BLOCKDEV)
70 echo "(hd0) $MAPPERDEV" > $TARGET/boot/grub/device.map
71 chroot "$TARGET" grub-install $LODEV
74 chroot "$TARGET" grub-install $BLOCKDEV
78 cat >> $TARGET/etc/default/grub <<EOF
79 GRUB_CMDLINE_LINUX="text console=ttyS0,115200n8"
81 GRUB_SERIAL_COMMAND="serial --unit=0 --speed=115200 --word=8 --parity=no --stop=1"
84 # and do it again, serial.mod should now be available
85 chroot "$TARGET" update-grub
89 chroot "$TARGET" grub-install $LODEV
92 chroot "$TARGET" grub-install $BLOCKDEV
96 # For some reason, the loopback device is still busy/open if this sleep is removed ...