Statistics
| Branch: | Revision:

root / example / instance-image.d / grub @ c3e07762

History | View | Annotate | Download (1.3 kB)

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. This is only enabled if using the tarball image
5
# type. 
6

    
7
set -e
8

    
9
. common.sh
10

    
11
CLEANUP=( )
12

    
13
trap cleanup EXIT
14

    
15
if [ "${IMAGE_TYPE}" != "tarball" ] ; then
16
    echo "Image type not \'tarball\', skipping setting up grub..."
17
    exit 0
18
fi
19

    
20
if [ -z "${TARGET}" -o -d "${TARGET}" ] ; then
21
    echo "Missing target directory"
22
    exit 1
23
fi
24

    
25
# Set disk based on type of hypervisor
26
disk=""
27
if [ "${HYPERVISOR}" = "kvm" ] ; then
28
  disk="vda"
29
else
30
  disk="xda"
31
fi
32

    
33
# make /dev/$disk
34
mknod ${TARGET}/dev/${disk} b $(stat -L -c "0x%t 0x%T" $BLOCKDEV)
35
CLEANUP+=("rm -f ${TARGET}/dev/$disk")
36

    
37
# make /dev/${disk}1
38
mknod ${TARGET}/dev/${disk}1 b $(stat -L -c "0x%t 0x%T" $BOOT_DEV)
39
CLEANUP+=("rm -f ${TARGET}/dev/${disk}1")
40

    
41
# make /dev/${disk}1
42
mknod ${TARGET}/dev/${disk}3 b $(stat -L -c "0x%t 0x%T" $ROOT_DEV)
43
CLEANUP+=("rm -f ${TARGET}/dev/${disk}3")
44

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

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

    
57
# execute cleanups
58
cleanup
59
trap - EXIT
60

    
61
exit 0