updated on Mon Jan 23 00:00:36 UTC 2012
[aur-mirror.git] / xen-4.2 / 09_xen
blob0251c240088d7d131d8fc6d7bb7706b3b7bc8779
1 #! /bin/sh -e
3 if [ -f /usr/lib/grub/grub-mkconfig_lib ]; then
4 . /usr/lib/grub/grub-mkconfig_lib
5 else
6 # no grub file, so we notify and exit gracefully
7 echo "Cannot find grub config file, exiting." >&2
8 exit 0
9 fi
11 XEN_HYPERVISOR_CMDLINE=
12 XEN_LINUX_CMDLINE="console=tty0"
13 [ -r /etc/xen/grub.conf ] && . /etc/xen/grub.conf
15 CLASS="--class gnu-linux --class gnu --class os"
17 if [ "x${GRUB_DISTRIBUTOR}" = "x" ] ; then
18 OS=GNU/Linux
19 else
20 OS="${GRUB_DISTRIBUTOR} GNU/Linux"
21 CLASS="--class $(echo ${GRUB_DISTRIBUTOR} | tr '[A-Z]' '[a-z]' | cut -d' ' -f1) ${CLASS}"
24 # loop-AES arranges things so that /dev/loop/X can be our root device, but
25 # the initrds that Linux uses don't like that.
26 case ${GRUB_DEVICE} in
27 /dev/loop/*|/dev/loop[0-9])
28 GRUB_DEVICE=`losetup ${GRUB_DEVICE} | sed -e "s/^[^(]*(\([^)]\+\)).*/\1/"`
30 esac
32 if [ "x${GRUB_DEVICE_UUID}" = "x" ] || [ "x${GRUB_DISABLE_LINUX_UUID}" = "xtrue" ] \
33 || ! test -e "/dev/disk/by-uuid/${GRUB_DEVICE_UUID}" \
34 || [ "`grub-probe -t abstraction --device ${GRUB_DEVICE} | sed -e 's,.*\(lvm\).*,\1,'`" = "lvm" ] ; then
35 LINUX_ROOT_DEVICE=${GRUB_DEVICE}
36 else
37 LINUX_ROOT_DEVICE=UUID=${GRUB_DEVICE_UUID}
40 xen_entry ()
42 os="$1"
43 xen_version="$2"
44 version="$3"
45 xen_args="$4"
46 args="$5"
47 printf "menuentry 'Xen %s / %s, with Linux %s' --class xen ${CLASS} {\n" "${xen_version}" "${os}" "${version}"
48 save_default_entry | sed -e "s/^/\t/"
50 if [ -z "${prepare_boot_cache}" ]; then
51 prepare_boot_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | sed -e "s/^/\t/")"
53 printf '%s\n' "${prepare_boot_cache}"
54 cat << EOF
55 echo '$(printf "Loading Xen %s ..." ${xen_version})'
56 multiboot ${rel_dirname}/${xen_basename} ${rel_dirname}/${xen_basename} ${xen_args}
57 echo $(printf "$(gettext "Loading Linux %s ...")" ${version})
58 module ${rel_dirname}/${basename} ${rel_dirname}/${basename} root=${linux_root_device_thisversion} ro ${args}
59 EOF
60 if test -n "${initrd}" ; then
61 cat << EOF
62 echo "Loading initial ramdisk ..."
63 module ${rel_dirname}/${initrd}
64 EOF
66 cat << EOF
68 EOF
71 xen_list=`for i in /boot/xen-*.gz /xen-*.gz ; do
72 if grub_file_is_not_garbage "$i" ; then echo -n "$i "; fi
73 done`
74 prepare_boot_cache=
76 while [ "x$xen_list" != "x" ] ; do
77 xen=`version_find_latest $xen_list`
78 echo "Found Xen hypervisor image: $xen" >&2
79 xen_basename=`basename $xen`
80 xen_dirname=`dirname $xen`
81 rel_xen_dirname=`make_system_path_relative_to_its_root $xen_dirname`
82 xen_version=`echo $xen_basename | sed -e "s,^[^0-9]*-,,g" | sed -e "s,.gz,,g"`
83 alt_xen_version=`echo $xen_version | sed -e "s,\.old$,,g"`
85 xen_configfiles=`grep -l 'CONFIG_XEN_PRIVILEGED_GUEST=y' /boot/config-*`
87 list="/boot/vmlinuz-linux";
89 while [ "x$list" != "x" ] ; do
90 linux=`version_find_latest $list`
91 echo -e "\tFound linux image: $linux" >&2
92 basename=`basename $linux`
93 dirname=`dirname $linux`
94 rel_dirname=`make_system_path_relative_to_its_root $dirname`
95 version=`echo $basename | sed -e "s,^[^0-9]*-,,g"`
96 base_init=`echo $basename | sed -e "s,vmlinuz,initramfs,g"`
97 alt_version="${base_init}-fallback"
98 linux_root_device_thisversion="${LINUX_ROOT_DEVICE}"
99 initrd=
101 for i in "${base_init}.img"; do
102 if test -e "${dirname}/${i}" ; then
103 initrd="$i"
104 break
106 done
107 if test -n "${initrd}" ; then
108 echo -e "\tFound initrd image: ${dirname}/${initrd}" >&2
109 else
110 # "UUID=" magic is parsed by initrds. Since there's no initrd, it can't work here.
111 linux_root_device_thisversion=${GRUB_DEVICE}
114 xen_entry "${OS}" "${xen_version}" "${version}" \
115 "${XEN_HYPERVISOR_CMDLINE}" \
116 "${XEN_LINUX_CMDLINE}"
118 list=`echo $list | tr ' ' '\n' | grep -vx $linux | tr '\n' ' '`
119 done
121 xen_list=`echo $xen_list | tr ' ' '\n' | grep -vx $xen | tr '\n' ' '`
122 done