root / example / instance-image.d / grub @ c2fca018
History | View | Annotate | Download (4.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 [ -z "${TARGET}" -o ! -d "${TARGET}" ] ; then |
36 |
log_error "Missing target directory" |
37 |
exit 1 |
38 |
fi |
39 |
|
40 |
# Set disk based on type of hypervisor |
41 |
disk="" |
42 |
if [ "${HYPERVISOR}" = "kvm" ] ; then |
43 |
disk="vda" |
44 |
else |
45 |
disk="xda" |
46 |
fi |
47 |
|
48 |
boot_dir="${TARGET}/boot/grub" |
49 |
|
50 |
setup_disk_devs() { |
51 |
root_part="${ROOT_DEV/*-/}" |
52 |
boot_part="${BOOT_DEV/*-/}" |
53 |
|
54 |
mknod ${TARGET}/dev/${disk} b $(stat -L -c "0x%t 0x%T" $BLOCKDEV) |
55 |
CLEANUP+=("rm -f ${TARGET}/dev/$disk") |
56 |
|
57 |
mknod ${TARGET}/dev/${disk}${root_part} b $(stat -L -c "0x%t 0x%T" $ROOT_DEV) |
58 |
CLEANUP+=("rm -f ${TARGET}/dev/${disk}${root_part}") |
59 |
|
60 |
if [ -n "$BOOT_DEV" ] ; then |
61 |
mknod ${TARGET}/dev/${disk}${boot_part} b $(stat -L -c "0x%t 0x%T" $BOOT_DEV) |
62 |
CLEANUP+=("rm -f ${TARGET}/dev/${disk}${boot_part}") |
63 |
fi |
64 |
} |
65 |
|
66 |
add_devicemap() { |
67 |
cat > "${TARGET}/boot/grub/device.map" <<EOF |
68 |
(hd0) /dev/${disk} |
69 |
EOF |
70 |
} |
71 |
|
72 |
if [ "${IMAGE_TYPE}" != "qemu" ] && \ |
73 |
[ -z "${INSTANCE_HV_kernel_path}" -o "${IMPORT_SCRIPT}" = "1" ] ; then |
74 |
setup_disk_devs |
75 |
|
76 |
if [ -e "${boot_dir}/menu.lst" ] ; then |
77 |
add_devicemap |
78 |
# install grub to the block device |
79 |
chroot ${TARGET} grub --batch --no-floppy \ |
80 |
--device-map=/boot/grub/device.map <<EOF |
81 |
root (hd0,0) |
82 |
setup (hd0) |
83 |
quit |
84 |
EOF |
85 |
# check to see if grub is using UUID's and replace if so |
86 |
if [ -n "$(grep 'root=UUID' ${boot_dir}/menu.lst)" ] ; then |
87 |
root_uuid="$($VOL_ID $ROOT_DEV)" |
88 |
sed --follow-symlinks -ie "s/\(root=UUID=\)\([a-z0-9-]*\)/\1${root_uuid}/g" \ |
89 |
${boot_dir}/menu.lst |
90 |
fi |
91 |
elif [ -e "${boot_dir}/grub.cfg" -a -e "${TARGET}/etc/default/grub" ] ; then |
92 |
echo "No support for grub 2 currently" |
93 |
#chroot ${TARGET} grub2-install /dev/${disk} |
94 |
# check to see if grub is using UUID's and replace if so |
95 |
#if [ -n "$(grep 'root=UUID' ${boot_dir}/grub.cfg)" ] ; then |
96 |
# root_uuid="$($VOL_ID $ROOT_DEV)" |
97 |
# sed --follow-symlinks -ie "s/\(root=UUID=\)\([a-z0-9-]*\)/\1${root_uuid}/g" \ |
98 |
# ${boot_dir}/grub.cfg |
99 |
#fi |
100 |
fi |
101 |
fi |
102 |
|
103 |
# setup serial console |
104 |
if [ "${INSTANCE_HV_serial_console}" = "True" ] ; then |
105 |
if [ ! -e ${TARGET}/dev/${disk} ] ; then |
106 |
setup_disk_devs |
107 |
fi |
108 |
if [ -e "${boot_dir}/menu.lst" ] ; then |
109 |
# grub 0.x |
110 |
sed --follow-symlinks -ie 's/^default.*/default 0\n\nserial --unit=0\nterminal --timeout=3 console serial/' \ |
111 |
${boot_dir}/menu.lst |
112 |
sed --follow-symlinks -ie 's/\(.*kernel.*\)/\1 console=ttyS0,115200n8/g' \ |
113 |
${boot_dir}/menu.lst |
114 |
elif [ -e "${boot_dir}/grub.cfg" -a -e "${TARGET}/etc/default/grub" ] ; then |
115 |
# grub 2.x |
116 |
add_devicemap |
117 |
sed -ie 's/.*GRUB_TERMINAL.*/GRUB_TERMINAL=serial/' ${TARGET}/etc/default/grub |
118 |
sed -ie 's/.*GRUB_CMDLINE_LINUX.*/GRUB_CMDLINE_LINUX=\"console=ttyS0,115200n8\"/' \ |
119 |
${TARGET}/etc/default/grub |
120 |
echo "GRUB_SERIAL_COMMAND=\"serial --speed=115200 --unit=0 --word=8 --parity=no --stop=1\"" \ |
121 |
>> ${TARGET}/etc/default/grub |
122 |
chroot ${TARGET} update-grub |
123 |
else |
124 |
echo "No grub bootloader found, skipping..." |
125 |
fi |
126 |
fi |
127 |
|
128 |
# execute cleanups |
129 |
cleanup |
130 |
trap - EXIT |
131 |
|
132 |
exit 0 |