root / example / instance-image.d / grub @ c3e07762
History | View | Annotate | Download (1.3 kB)
1 | 79224631 | Lance Albertson | #!/bin/bash |
---|---|---|---|
2 | f7959feb | Lance Albertson | # This is an example script that configures, grub after installation. This |
3 | f7959feb | Lance Albertson | # script assumes that grub has been installed onto the image already and a |
4 | c3e07762 | Lance Albertson | # working grub.conf exists. This is only enabled if using the tarball image |
5 | c3e07762 | Lance Albertson | # type. |
6 | 79224631 | Lance Albertson | |
7 | 79224631 | Lance Albertson | set -e |
8 | 79224631 | Lance Albertson | |
9 | 79224631 | Lance Albertson | . common.sh |
10 | 79224631 | Lance Albertson | |
11 | 79224631 | Lance Albertson | CLEANUP=( ) |
12 | 79224631 | Lance Albertson | |
13 | 79224631 | Lance Albertson | trap cleanup EXIT |
14 | 79224631 | Lance Albertson | |
15 | c3e07762 | Lance Albertson | if [ "${IMAGE_TYPE}" != "tarball" ] ; then |
16 | c3e07762 | Lance Albertson | echo "Image type not \'tarball\', skipping setting up grub..." |
17 | c3e07762 | Lance Albertson | exit 0 |
18 | c3e07762 | Lance Albertson | fi |
19 | c3e07762 | Lance Albertson | |
20 | f7959feb | Lance Albertson | if [ -z "${TARGET}" -o -d "${TARGET}" ] ; then |
21 | f7959feb | Lance Albertson | echo "Missing target directory" |
22 | f7959feb | Lance Albertson | exit 1 |
23 | 79224631 | Lance Albertson | fi |
24 | 79224631 | Lance Albertson | |
25 | f7959feb | Lance Albertson | # Set disk based on type of hypervisor |
26 | f7959feb | Lance Albertson | disk="" |
27 | f7959feb | Lance Albertson | if [ "${HYPERVISOR}" = "kvm" ] ; then |
28 | f7959feb | Lance Albertson | disk="vda" |
29 | f7959feb | Lance Albertson | else |
30 | f7959feb | Lance Albertson | disk="xda" |
31 | f7959feb | Lance Albertson | fi |
32 | 79224631 | Lance Albertson | |
33 | f7959feb | Lance Albertson | # make /dev/$disk |
34 | f7959feb | Lance Albertson | mknod ${TARGET}/dev/${disk} b $(stat -L -c "0x%t 0x%T" $BLOCKDEV) |
35 | f7959feb | Lance Albertson | CLEANUP+=("rm -f ${TARGET}/dev/$disk") |
36 | 79224631 | Lance Albertson | |
37 | f7959feb | Lance Albertson | # make /dev/${disk}1 |
38 | f7959feb | Lance Albertson | mknod ${TARGET}/dev/${disk}1 b $(stat -L -c "0x%t 0x%T" $BOOT_DEV) |
39 | f7959feb | Lance Albertson | CLEANUP+=("rm -f ${TARGET}/dev/${disk}1") |
40 | 79224631 | Lance Albertson | |
41 | f7959feb | Lance Albertson | # make /dev/${disk}1 |
42 | f7959feb | Lance Albertson | mknod ${TARGET}/dev/${disk}3 b $(stat -L -c "0x%t 0x%T" $ROOT_DEV) |
43 | f7959feb | Lance Albertson | CLEANUP+=("rm -f ${TARGET}/dev/${disk}3") |
44 | 79224631 | Lance Albertson | |
45 | 79224631 | Lance Albertson | # create device.map |
46 | f7959feb | Lance Albertson | cat > "${TARGET}/boot/grub/device.map" <<EOF |
47 | f7959feb | Lance Albertson | (hd0) /dev/${disk} |
48 | 79224631 | Lance Albertson | EOF |
49 | 79224631 | Lance Albertson | |
50 | 79224631 | Lance Albertson | # install grub to the block device |
51 | f7959feb | Lance Albertson | chroot ${TARGET} grub --batch --no-floppy --device-map=/boot/grub/device.map <<EOF |
52 | f7959feb | Lance Albertson | root (hd0,0) |
53 | f7959feb | Lance Albertson | setup (hd0) |
54 | f7959feb | Lance Albertson | quit |
55 | f7959feb | Lance Albertson | EOF |
56 | 79224631 | Lance Albertson | |
57 | 79224631 | Lance Albertson | # execute cleanups |
58 | 79224631 | Lance Albertson | cleanup |
59 | 79224631 | Lance Albertson | trap - EXIT |
60 | 79224631 | Lance Albertson | |
61 | 79224631 | Lance Albertson | exit 0 |