Statistics
| Branch: | Revision:

root / example / instance-image.d / grub @ 775f4f72

History | View | Annotate | Download (1.2 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. To use, make it executable and edit your settings
5
# to the following:
6
#
7
# GRUB_SETUP="yes"
8

    
9
set -e
10

    
11
. common.sh
12

    
13
CLEANUP=( )
14

    
15
trap cleanup EXIT
16

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

    
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
29

    
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")
33

    
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")
37

    
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")
41

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

    
47
# install grub to the block device
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
53

    
54
# execute cleanups
55
cleanup
56
trap - EXIT
57

    
58
exit 0