Statistics
| Branch: | Revision:

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

History | View | Annotate | Download (2.1 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" -a "${SCRIPT_NAME}" != "import" ] ; then
36
    log_error "Image type not \'tarball\', skipping setting up grub..."
37
    exit 0
38
fi
39

    
40
if [ -z "${TARGET}" -o -d "${TARGET}" ] ; then
41
    log_error "Missing target directory"
42
    exit 1
43
fi
44

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

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

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

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

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

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

    
77
# execute cleanups
78
cleanup
79
trap - EXIT
80

    
81
exit 0