Statistics
| Branch: | Revision:

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

History | View | Annotate | Download (2.2 kB)

1
#!/bin/bash
2

    
3
# Copyright (C) 2010 Oregon State University
4
#
5
# This program is free software; you can redistribute it and/or modify
6
# it under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 2 of the License, or
8
# (at your option) any later version.
9
#
10
# This program is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
# General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with this program; if not, write to the Free Software
17
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18
# 02110-1301, USA.
19
#
20
# This is an example script that configures, grub after installation. This
21
# script assumes that grub has been installed onto the image already and a
22
# working grub.conf exists. This is only enabled if using the tarball image
23
# type. 
24

    
25
set -e
26

    
27
. common.sh
28

    
29
debug set -x
30

    
31
CLEANUP=( )
32

    
33
trap cleanup EXIT
34

    
35
if [ "${IMAGE_TYPE}" != "tarball" \
36
        -a "${IMPORT_SCRIPT}" != "1" \
37
        -a "${IMAGE_TYPE}" != "dump" \
38
        -a -z "${INSTANCE_HV_kernel_path}" ] ; then
39
    log_error "Image doesn't require grub setup, skipping ..."
40
    exit 0
41
fi
42

    
43
if [ -z "${TARGET}" -o -d "${TARGET}" ] ; then
44
    log_error "Missing target directory"
45
    exit 1
46
fi
47

    
48
# Set disk based on type of hypervisor
49
disk=""
50
if [ "${HYPERVISOR}" = "kvm" ] ; then
51
  disk="vda"
52
else
53
  disk="xda"
54
fi
55

    
56
# make /dev/$disk
57
mknod ${TARGET}/dev/${disk} b $(stat -L -c "0x%t 0x%T" $BLOCKDEV)
58
CLEANUP+=("rm -f ${TARGET}/dev/$disk")
59

    
60
# make /dev/${disk}1
61
mknod ${TARGET}/dev/${disk}1 b $(stat -L -c "0x%t 0x%T" $BOOT_DEV)
62
CLEANUP+=("rm -f ${TARGET}/dev/${disk}1")
63

    
64
# make /dev/${disk}1
65
mknod ${TARGET}/dev/${disk}3 b $(stat -L -c "0x%t 0x%T" $ROOT_DEV)
66
CLEANUP+=("rm -f ${TARGET}/dev/${disk}3")
67

    
68
# create device.map
69
cat > "${TARGET}/boot/grub/device.map" <<EOF
70
(hd0) /dev/${disk}
71
EOF
72

    
73
# install grub to the block device
74
chroot ${TARGET} grub --batch --no-floppy --device-map=/boot/grub/device.map <<EOF
75
root (hd0,0)
76
setup (hd0)
77
quit
78
EOF
79

    
80
# execute cleanups
81
cleanup
82
trap - EXIT
83

    
84
exit 0