Statistics
| Branch: | Revision:

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

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
if [ "${DEBUG_LEVEL} " = 1 ] ; then
12
    set -x
13
fi
14

    
15
CLEANUP=( )
16

    
17
trap cleanup EXIT
18

    
19
if [ "${IMAGE_TYPE}" != "tarball" ] ; then
20
    echo "Image type not \'tarball\', skipping setting up grub..."
21
    exit 0
22
fi
23

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

    
29
# Set disk based on type of hypervisor
30
disk=""
31
if [ "${HYPERVISOR}" = "kvm" ] ; then
32
  disk="vda"
33
else
34
  disk="xda"
35
fi
36

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

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

    
45
# make /dev/${disk}1
46
mknod ${TARGET}/dev/${disk}3 b $(stat -L -c "0x%t 0x%T" $ROOT_DEV)
47
CLEANUP+=("rm -f ${TARGET}/dev/${disk}3")
48

    
49
# create device.map
50
cat > "${TARGET}/boot/grub/device.map" <<EOF
51
(hd0) /dev/${disk}
52
EOF
53

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

    
61
# execute cleanups
62
cleanup
63
trap - EXIT
64

    
65
exit 0