~ubuntu-branches/debian/stretch/grub2/stretch

« back to all changes in this revision

Viewing changes to util/grub.d/20_linux_xen.in

Tags: upstream-1.98+20100705
ImportĀ upstreamĀ versionĀ 1.98+20100705

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /bin/sh
 
2
set -e
 
3
 
 
4
# grub-mkconfig helper script.
 
5
# Copyright (C) 2006,2007,2008,2009,2010  Free Software Foundation, Inc.
 
6
#
 
7
# GRUB is free software: you can redistribute it and/or modify
 
8
# it under the terms of the GNU General Public License as published by
 
9
# the Free Software Foundation, either version 3 of the License, or
 
10
# (at your option) any later version.
 
11
#
 
12
# GRUB is distributed in the hope that it will be useful,
 
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
# GNU General Public License for more details.
 
16
#
 
17
# You should have received a copy of the GNU General Public License
 
18
# along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
 
19
 
 
20
prefix=@prefix@
 
21
exec_prefix=@exec_prefix@
 
22
bindir=@bindir@
 
23
libdir=@libdir@
 
24
. ${libdir}/grub/grub-mkconfig_lib
 
25
 
 
26
export TEXTDOMAIN=@PACKAGE@
 
27
export TEXTDOMAINDIR=@localedir@
 
28
 
 
29
CLASS="--class gnu-linux --class gnu --class os --class xen"
 
30
 
 
31
if [ "x${GRUB_DISTRIBUTOR}" = "x" ] ; then
 
32
  OS=GNU/Linux
 
33
else
 
34
  OS="${GRUB_DISTRIBUTOR} GNU/Linux"
 
35
  CLASS="--class $(echo ${GRUB_DISTRIBUTOR} | tr '[A-Z]' '[a-z]' | cut -d' ' -f1) ${CLASS}"
 
36
fi
 
37
 
 
38
# loop-AES arranges things so that /dev/loop/X can be our root device, but
 
39
# the initrds that Linux uses don't like that.
 
40
case ${GRUB_DEVICE} in
 
41
  /dev/loop/*|/dev/loop[0-9])
 
42
    GRUB_DEVICE=`losetup ${GRUB_DEVICE} | sed -e "s/^[^(]*(\([^)]\+\)).*/\1/"`
 
43
  ;;
 
44
esac
 
45
 
 
46
if [ "x${GRUB_DEVICE_UUID}" = "x" ] || [ "x${GRUB_DISABLE_LINUX_UUID}" = "xtrue" ] \
 
47
    || ! test -e "/dev/disk/by-uuid/${GRUB_DEVICE_UUID}" ; then
 
48
  LINUX_ROOT_DEVICE=${GRUB_DEVICE}
 
49
else
 
50
  LINUX_ROOT_DEVICE=UUID=${GRUB_DEVICE_UUID}
 
51
fi
 
52
 
 
53
linux_entry ()
 
54
{
 
55
  os="$1"
 
56
  version="$2"
 
57
  xen_version="$3"
 
58
  recovery="$4"
 
59
  args="$5"
 
60
  xen_args="$6"
 
61
  if ${recovery} ; then
 
62
    title="$(gettext_quoted "%s, with Linux %s and XEN %s (recovery mode)")"
 
63
  else
 
64
    title="$(gettext_quoted "%s, with Linux %s and XEN %s")"
 
65
  fi
 
66
  printf "menuentry '${title}' ${CLASS} {\n" "${os}" "${version}" "${xen_version}"
 
67
  save_default_entry | sed -e "s/^/\t/"
 
68
 
 
69
  if [ -z "${prepare_boot_cache}" ]; then
 
70
    prepare_boot_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | sed -e "s/^/\t/")"
 
71
  fi
 
72
  printf '%s\n' "${prepare_boot_cache}"
 
73
  cat << EOF
 
74
        echo    '$(printf "$(gettext_quoted "Loading Linux %s ...")" ${version})'
 
75
        multiboot       ${rel_xen_dirname}/${xen_basename} placeholder ${xen_args}
 
76
        module  ${rel_dirname}/${basename} placeholder root=${linux_root_device_thisversion} ro ${args}
 
77
EOF
 
78
  if test -n "${initrd}" ; then
 
79
    cat << EOF
 
80
        echo    '$(gettext_quoted "Loading initial ramdisk ...")'
 
81
        module  ${rel_dirname}/${initrd}
 
82
EOF
 
83
  fi
 
84
  cat << EOF
 
85
}
 
86
EOF
 
87
}
 
88
 
 
89
linux_list=`for i in /boot/vmlinu[xz]-* /vmlinu[xz]-* ; do
 
90
        basename=$(basename $i)
 
91
        version=$(echo $basename | sed -e "s,^[^0-9]*-,,g")
 
92
        if grub_file_is_not_garbage "$i" && grep -qx "CONFIG_XEN_DOM0=y" /boot/config-${version} 2> /dev/null ; then echo -n "$i " ; fi
 
93
      done`
 
94
xen_list=`for i in /boot/xen*; do
 
95
        if grub_file_is_not_garbage "$i" ; then echo -n "$i " ; fi
 
96
      done`
 
97
prepare_boot_cache=
 
98
 
 
99
while [ "x${xen_list}" != "x" ] ; do
 
100
    list="${linux_list}"
 
101
    current_xen=`version_find_latest $xen_list`
 
102
    xen_basename=`basename ${current_xen}`
 
103
    xen_dirname=`dirname ${current_xen}`
 
104
    rel_xen_dirname=`make_system_path_relative_to_its_root $xen_dirname`
 
105
    xen_version=`echo $xen_basename | sed -e "s,.gz$,,g;s,^xen-,,g"`
 
106
    while [ "x$list" != "x" ] ; do
 
107
        linux=`version_find_latest $list`
 
108
        echo "Found linux image: $linux" >&2
 
109
        basename=`basename $linux`
 
110
        dirname=`dirname $linux`
 
111
        rel_dirname=`make_system_path_relative_to_its_root $dirname`
 
112
        version=`echo $basename | sed -e "s,^[^0-9]*-,,g"`
 
113
        alt_version=`echo $version | sed -e "s,\.old$,,g"`
 
114
        linux_root_device_thisversion="${LINUX_ROOT_DEVICE}"
 
115
 
 
116
        initrd=
 
117
        for i in "initrd.img-${version}" "initrd-${version}.img" \
 
118
            "initrd-${version}" "initrd.img-${alt_version}" \
 
119
            "initrd-${alt_version}.img" "initrd-${alt_version}"; do
 
120
            if test -e "${dirname}/${i}" ; then
 
121
                initrd="$i"
 
122
                break
 
123
            fi
 
124
        done
 
125
        if test -n "${initrd}" ; then
 
126
            echo "Found initrd image: ${dirname}/${initrd}" >&2
 
127
        else
 
128
    # "UUID=" magic is parsed by initrds.  Since there's no initrd, it can't work here.
 
129
            linux_root_device_thisversion=${GRUB_DEVICE}
 
130
        fi
 
131
 
 
132
        linux_entry "${OS}" "${version}" "${xen_version}" false \
 
133
            "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}" "${GRUB_CMDLINE_XEN} ${GRUB_CMDLINE_XEN_DEFAULT}"
 
134
        if [ "x${GRUB_DISABLE_LINUX_RECOVERY}" != "xtrue" ]; then
 
135
            linux_entry "${OS}" "${version}" "${xen_version}" true \
 
136
                "single ${GRUB_CMDLINE_LINUX}" "${GRUB_CMDLINE_XEN}"
 
137
        fi
 
138
 
 
139
        list=`echo $list | tr ' ' '\n' | grep -vx $linux | tr '\n' ' '`
 
140
    done
 
141
    xen_list=`echo $xen_list | tr ' ' '\n' | grep -vx $current_xen | tr '\n' ' '`
 
142
done