1 | #!/bin/bash |
---|
2 | # |
---|
3 | # This script sets up the ParaVM to use pygrub |
---|
4 | # |
---|
5 | |
---|
6 | prefix=$1 |
---|
7 | |
---|
8 | # |
---|
9 | # Source our common functions |
---|
10 | # |
---|
11 | if [ -e /usr/lib/xen-tools/common.sh ]; then |
---|
12 | . /usr/lib/xen-tools/common.sh |
---|
13 | else |
---|
14 | . ./hooks/common.sh |
---|
15 | fi |
---|
16 | |
---|
17 | echo SCRIPT = $0 |
---|
18 | dir=`dirname "$0"` |
---|
19 | |
---|
20 | |
---|
21 | logMessage Script $0 starting |
---|
22 | |
---|
23 | # |
---|
24 | # Install the xen kernel. linux-image-xen is in ubuntu, |
---|
25 | # linux-image-xen-{amd64,686} in debian. |
---|
26 | # |
---|
27 | |
---|
28 | installDebianPackage ${prefix} lsb-release |
---|
29 | |
---|
30 | if [ "$(chroot ${prefix} lsb_release -is)" = "Ubuntu" ]; then |
---|
31 | if dpkg --compare-versions "$(chroot ${prefix} lsb_release -rs)" ge 8.10; then |
---|
32 | installDebianPackage ${prefix} linux-image-virtual |
---|
33 | else |
---|
34 | installDebianPackage ${prefix} linux-image-xen |
---|
35 | fi |
---|
36 | else |
---|
37 | installDebianPackage ${prefix} linux-image-xen-amd64 |
---|
38 | installDebianPackage ${prefix} linux-image-xen-686 |
---|
39 | fi |
---|
40 | |
---|
41 | installDebianPackage ${prefix} grub |
---|
42 | |
---|
43 | # |
---|
44 | # Make the /boot/grub directory |
---|
45 | # |
---|
46 | mkdir -p ${prefix}/boot/grub |
---|
47 | |
---|
48 | # |
---|
49 | # Create stock menu.lst |
---|
50 | # |
---|
51 | chroot ${prefix} /usr/sbin/update-grub -y |
---|
52 | |
---|
53 | # |
---|
54 | # Patches to add xen kernels, use serial console, etc. |
---|
55 | # |
---|
56 | for patch in $dir/patches/*; do |
---|
57 | patch -l -d ${prefix} -p1 < $patch |
---|
58 | done |
---|
59 | |
---|
60 | # |
---|
61 | # If this is a pv_ops kernel, then we need to make some more changes |
---|
62 | # to make the console work right |
---|
63 | # |
---|
64 | if [ "$(chroot ${prefix} lsb_release -is)" = "Ubuntu" ] && \ |
---|
65 | dpkg --compare-versions "$(chroot ${prefix} lsb_release -rs)" ge 8.10; then |
---|
66 | sed -i -e 's/xvc0/hvc0/' ${prefix}/etc/event.d/tty1 |
---|
67 | sed -i -e 's/console=ttyS0[^ ]*/console=hvc0/' ${prefix}/boot/grub/menu.lst |
---|
68 | fi |
---|
69 | |
---|
70 | # |
---|
71 | # Since pv_ops kernels force block device names to xvda, xvdb, etc, |
---|
72 | # the default root value of root=/dev/hda won't actually help us. |
---|
73 | # |
---|
74 | # To work around that, find a UUID for the swap and root partitions |
---|
75 | # and use that in the grub config (and also in /etc/fstab) |
---|
76 | # |
---|
77 | ROOT_DEV="$(perl -e 'print $ENV{"image-dev"}')" |
---|
78 | SWAP_DEV="$(perl -e 'print $ENV{"swap-dev"}')" |
---|
79 | ROOT_UUID="$(vol_id --uuid "$ROOT_DEV")" |
---|
80 | SWAP_UUID="$(vol_id --uuid "$SWAP_DEV")" |
---|
81 | for i in $(seq 1 "$NUMPARTITIONS"); do |
---|
82 | var="PARTITION${i}" |
---|
83 | case "$(echo ${!var} | cut -f1 -d:)" in |
---|
84 | disk) ROOT_GUEST="$(echo ${!var} | cut -f8 -d:)";; |
---|
85 | swap) SWAP_GUEST="$(echo ${!var} | cut -f8 -d:)";; |
---|
86 | esac |
---|
87 | done |
---|
88 | sed -i -e "s#root=[^ ]*#root=UUID=$ROOT_UUID#" ${prefix}/boot/grub/menu.lst |
---|
89 | sed -i -e "s#${ROOT_GUEST}#UUID=${ROOT_UUID}#" ${prefix}/etc/fstab |
---|
90 | sed -i -e "s#${SWAP_GUEST}#UUID=${SWAP_UUID}#" ${prefix}/etc/fstab |
---|
91 | |
---|
92 | # |
---|
93 | # Regenerate automagic kernels list, saving our changes |
---|
94 | # |
---|
95 | chroot ${prefix} env UCF_FORCE_CONFFOLD=1 /usr/sbin/update-grub -y |
---|
96 | |
---|
97 | # |
---|
98 | # Log our finish |
---|
99 | # |
---|
100 | logMessage Script $0 finished |
---|
101 | |
---|