root / example / instance-image.d / grub @ ad81a23e
History | View | Annotate | Download (3 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 [ -n "${INSTANCE_HV_kernel_path}" -a "${IMPORT_SCRIPT}" != "1" ] ; then |
36 |
log_error "Image doesn't require grub setup, skipping ..." |
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 |
# setup serial console |
78 |
if [ "${INSTANCE_HV_serial_console}" = "True" ] ; then |
79 |
boot_dir="${TARGET}/boot/grub" |
80 |
if [ -e "${boot_dir}/menu.lst" ] ; then |
81 |
# Grub 0.x |
82 |
sed -ie 's/^default.*/default 0\n\nserial --unit=0\nterminal --timeout=3 console serial/' \ |
83 |
${boot_dir}/menu.lst |
84 |
sed -ie 's/\(.*kernel.*\)/\1 console=ttyS0,115200n8/g' \ |
85 |
${boot_dir}/menu.lst |
86 |
elif [ -e "${boot_dir}/grub.cfg" -a -e "${target}/etc/default/grub" ] ; then |
87 |
# Grub 2.x |
88 |
sed -ie 's/.*GRUB_TERMINAL.*/GRUB_TERMINAL=serial/' ${target}/etc/default/grub |
89 |
sed -ie 's/.*GRUB_CMDLINE_LINUX.*/GRUB_CMDLINE_LINUX=\"console=ttyS0,115200n8\"/' \ |
90 |
${target}/etc/default/grub |
91 |
echo "GRUB_SERIAL_COMMAND=\"serial --speed=115200 --unit=0 --word=8 --parity=no --stop=1\"" \ |
92 |
>> ${target}/etc/default/grub |
93 |
chroot ${target} /usr/sbin/update-grub |
94 |
else |
95 |
echo "No grub bootloader found, skipping..." |
96 |
fi |
97 |
fi |
98 |
|
99 |
# execute cleanups |
100 |
cleanup |
101 |
trap - EXIT |
102 |
|
103 |
exit 0 |