Make release 0.8
[ext/instance-debootstrap.git] / example / instance-debootstrap.d / 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, make it executable, and edit EXTRAPKGS
5 # of your $sysconfdir/default/ganeti-instance-debootstrap.
6 #
7 # Xen, for etch/lenny i386:
8 #   EXTRA_PKGS="linux-image-xen-686,libc6-xen"
9 # Xen, for etch/lenny amd64:
10 #   EXTRA_PKGS="linux-image-xen-amd64"
11 # KVM:
12 #   no extra packages needed besides the normal suggested ones
13 #
14 # Do not include grub in EXTRA_PKGS because it will cause error of debootstrap.
15
16 set -e
17
18 . common.sh
19
20 CLEANUP=( )
21
22 trap cleanup EXIT
23
24 if [ -z "$TARGET" -o ! -d "$TARGET" ]; then
25   echo "Missing target directory"
26   exit 1
27 fi
28
29 # install grub
30 LANG=C
31 chroot "$TARGET" apt-get -y --force-yes install grub grub-common
32
33 # make /dev/sda
34 mknod $TARGET/dev/sda b $(stat -L -c "0x%t 0x%T" $BLOCKDEV)
35 CLEANUP+=("rm -f $TARGET/dev/sda")
36
37 # make /dev/sda1
38 mknod $TARGET/dev/sda1 b $(stat -L -c "0x%t 0x%T" $FSYSDEV)
39 CLEANUP+=("rm -f $TARGET/dev/sda1")
40
41 # create grub directory
42 mkdir -p "$TARGET/boot/grub"
43
44 # create device.map
45 cat > "$TARGET/boot/grub/device.map" <<EOF
46 (hd0) /dev/sda
47 EOF
48
49 # execute update-grub
50 chroot "$TARGET" update-grub
51
52 # install grub to the block device
53 grub-install --no-floppy --root-directory="$TARGET" "$BLOCKDEV"
54
55 # execute cleanups
56 cleanup
57 trap - EXIT
58
59 exit 0