Revision f7959feb example/instance-debootstrap.d/grub

b/example/instance-debootstrap.d/grub
1 1
#!/bin/bash
2
# This is an example script that configures, grub after installation. This
3
# script assumes that grub has been installed onto the image already and a
4
# working grub.conf exists. To use, make it executable and edit your settings
5
# to the following:
2 6
#
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.
7
# GRUB_SETUP="yes"
15 8

  
16 9
set -e
17 10

  
......
21 14

  
22 15
trap cleanup EXIT
23 16

  
24
if [ -z "$TARGET" -o ! -d "$TARGET" ]; then
25
  echo "Missing target directory"
26
  exit 1
17
if [ -z "${TARGET}" -o -d "${TARGET}" ] ; then
18
    echo "Missing target directory"
19
    exit 1
27 20
fi
28 21

  
29
# install grub
30
LANG=C
31
chroot "$TARGET" apt-get -y --force-yes install grub grub-common
22
# Set disk based on type of hypervisor
23
disk=""
24
if [ "${HYPERVISOR}" = "kvm" ] ; then
25
  disk="vda"
26
else
27
  disk="xda"
28
fi
32 29

  
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")
30
# make /dev/$disk
31
mknod ${TARGET}/dev/${disk} b $(stat -L -c "0x%t 0x%T" $BLOCKDEV)
32
CLEANUP+=("rm -f ${TARGET}/dev/$disk")
36 33

  
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")
34
# make /dev/${disk}1
35
mknod ${TARGET}/dev/${disk}1 b $(stat -L -c "0x%t 0x%T" $BOOT_DEV)
36
CLEANUP+=("rm -f ${TARGET}/dev/${disk}1")
40 37

  
41
# create grub directory
42
mkdir -p "$TARGET/boot/grub"
38
# make /dev/${disk}1
39
mknod ${TARGET}/dev/${disk}3 b $(stat -L -c "0x%t 0x%T" $ROOT_DEV)
40
CLEANUP+=("rm -f ${TARGET}/dev/${disk}3")
43 41

  
44 42
# create device.map
45
cat > "$TARGET/boot/grub/device.map" <<EOF
46
(hd0) /dev/sda
43
cat > "${TARGET}/boot/grub/device.map" <<EOF
44
(hd0) /dev/${disk}
47 45
EOF
48 46

  
49
# execute update-grub
50
chroot "$TARGET" update-grub
51

  
52 47
# install grub to the block device
53
grub-install --no-floppy --root-directory="$TARGET" "$BLOCKDEV"
48
chroot ${TARGET} grub --batch --no-floppy --device-map=/boot/grub/device.map <<EOF
49
root (hd0,0)
50
setup (hd0)
51
quit
52
EOF
54 53

  
55 54
# execute cleanups
56 55
cleanup

Also available in: Unified diff