Fix a few issues with the grub hook
[ext/instance-debootstrap.git] / examples / hooks / grub
1 #!/bin/bash
2 #
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.
5 #
6 # Do not include grub in EXTRA_PKGS of
7 # $sysconfdir/default/ganeti-instance-debootstrap because it will
8 # cause error of debootstrap.
9
10 set -e
11
12 . common.sh
13
14 CLEANUP=( )
15
16 trap cleanup EXIT
17
18 if [ -z "$TARGET" -o ! -d "$TARGET" ]; then
19   echo "Missing target directory"
20   exit 1
21 fi
22
23 # install grub
24 export LANG=C
25 if [ "$PROXY" ]; then
26   export http_proxy="$PROXY"
27 fi
28 export DEBIAN_FRONTEND=noninteractive
29 chroot "$TARGET" apt-get -y --force-yes install grub grub-common
30
31 # make /dev/sda
32 mknod $TARGET/dev/sda b $(stat -L -c "0x%t 0x%T" $BLOCKDEV)
33 CLEANUP+=("rm -f $TARGET/dev/sda")
34
35 # make /dev/sda1
36 mknod $TARGET/dev/sda1 b $(stat -L -c "0x%t 0x%T" $FSYSDEV)
37 CLEANUP+=("rm -f $TARGET/dev/sda1")
38
39 # create grub directory
40 mkdir -p "$TARGET/boot/grub"
41
42 # create device.map
43 cat > "$TARGET/boot/grub/device.map" <<EOF
44 (hd0) /dev/sda
45 EOF
46
47 # execute update-grub
48 chroot "$TARGET" update-grub
49
50 # install grub to the block device
51 grub-install --no-floppy --root-directory="$TARGET" "$BLOCKDEV"
52
53 # execute cleanups
54 cleanup
55 trap - EXIT
56
57 exit 0