/
grub
executable file
·102 lines (79 loc) · 2.78 KB
/
grub
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/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/<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/<vgname>/<lvname>, but Grub will be looking
# for /dev/mapper/<vgname>-<mangled-lvname> ...
# 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 <<EOF
GRUB_CMDLINE_LINUX="text console=ttyS0,115200n8"
GRUB_TERMINAL=serial
GRUB_SERIAL_COMMAND="serial --unit=0 --speed=115200 --word=8 --parity=no --stop=1"
EOF
# and do it again, serial.mod should now be available
chroot "$TARGET" update-grub
case $DISKTYPE in
lvm)
chroot "$TARGET" grub-install $LODEV
;;
drbd)
chroot "$TARGET" grub-install $BLOCKDEV
;;
esac
# For some reason, the loopback device is still busy/open if this sleep is removed ...
sleep 2
# execute cleanups
cleanup
trap - EXIT