source: grub-pc/trunk/fuentes/.pc/mkconfig-kernels-infloop.patch/util/grub.d/20_linux_xen.in @ 22

Last change on this file since 22 was 22, checked in by mabarracus, 4 years ago

updated version and apply net.ifnames=0 into debian/rules

File size: 10.2 KB
Line 
1#! /bin/sh
2set -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
20prefix="@prefix@"
21exec_prefix="@exec_prefix@"
22datarootdir="@datarootdir@"
23
24. "@datadir@/@PACKAGE@/grub-mkconfig_lib"
25
26export TEXTDOMAIN=@PACKAGE@
27export TEXTDOMAINDIR="@localedir@"
28
29CLASS="--class gnu-linux --class gnu --class os --class xen"
30
31if [ "x${GRUB_DISTRIBUTOR}" = "x" ] ; then
32  OS=GNU/Linux
33else
34  OS="${GRUB_DISTRIBUTOR} GNU/Linux"
35  CLASS="--class $(echo ${GRUB_DISTRIBUTOR} | tr 'A-Z' 'a-z' | cut -d' ' -f1|LC_ALL=C sed 's,[^[:alnum:]_],_,g') ${CLASS}"
36fi
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.
40case ${GRUB_DEVICE} in
41  /dev/loop/*|/dev/loop[0-9])
42    GRUB_DEVICE=`losetup ${GRUB_DEVICE} | sed -e "s/^[^(]*(\([^)]\+\)).*/\1/"`
43    # We can't cope with devices loop-mounted from files here.
44    case ${GRUB_DEVICE} in
45      /dev/*) ;;
46      *) exit 0 ;;
47    esac
48  ;;
49esac
50
51if [ "x${GRUB_DEVICE_UUID}" = "x" ] || [ "x${GRUB_DISABLE_LINUX_UUID}" = "xtrue" ] \
52    || ! test -e "/dev/disk/by-uuid/${GRUB_DEVICE_UUID}" \
53    || uses_abstraction "${GRUB_DEVICE}" lvm; then
54  LINUX_ROOT_DEVICE=${GRUB_DEVICE}
55else
56  LINUX_ROOT_DEVICE=UUID=${GRUB_DEVICE_UUID}
57fi
58
59# Allow overriding GRUB_CMDLINE_LINUX and GRUB_CMDLINE_LINUX_DEFAULT.
60if [ "${GRUB_CMDLINE_LINUX_XEN_REPLACE}" ]; then
61  GRUB_CMDLINE_LINUX="${GRUB_CMDLINE_LINUX_XEN_REPLACE}"
62fi
63if [ "${GRUB_CMDLINE_LINUX_XEN_REPLACE_DEFAULT}" ]; then
64  GRUB_CMDLINE_LINUX_DEFAULT="${GRUB_CMDLINE_LINUX_XEN_REPLACE_DEFAULT}"
65fi
66
67case x"$GRUB_FS" in
68    xbtrfs)
69        rootsubvol="`make_system_path_relative_to_its_root /`"
70        rootsubvol="${rootsubvol#/}"
71        if [ "x${rootsubvol}" != x ]; then
72            GRUB_CMDLINE_LINUX="rootflags=subvol=${rootsubvol} ${GRUB_CMDLINE_LINUX}"
73        fi;;
74    xzfs)
75        rpool=`${grub_probe} --device ${GRUB_DEVICE} --target=fs_label 2>/dev/null || true`
76        bootfs="`make_system_path_relative_to_its_root / | sed -e "s,@$,,"`"
77        LINUX_ROOT_DEVICE="ZFS=${rpool}${bootfs}"
78        ;;
79esac
80
81title_correction_code=
82
83linux_entry ()
84{
85  os="$1"
86  version="$2"
87  xen_version="$3"
88  type="$4"
89  args="$5"
90  xen_args="$6"
91  if [ -z "$boot_device_id" ]; then
92      boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")"
93  fi
94  if [ x$type != xsimple ] ; then
95      if [ x$type = xrecovery ] ; then
96          title="$(gettext_printf "%s, with Xen %s and Linux %s (%s)" "${os}" "${xen_version}" "${version}" "$(gettext "${GRUB_RECOVERY_TITLE}")")"
97      else
98          title="$(gettext_printf "%s, with Xen %s and Linux %s" "${os}" "${xen_version}" "${version}")"
99      fi
100      replacement_title="$(echo "Advanced options for ${OS}" | sed 's,>,>>,g')>$(echo "$title" | sed 's,>,>>,g')"
101      if [ x"Xen ${xen_version}>$title" = x"$GRUB_ACTUAL_DEFAULT" ]; then
102         quoted="$(echo "$GRUB_ACTUAL_DEFAULT" | grub_quote)"
103         title_correction_code="${title_correction_code}if [ \"x\$default\" = '$quoted' ]; then default='$(echo "$replacement_title" | grub_quote)'; fi;"
104         grub_warn "$(gettext_printf "Please don't use old title \`%s' for GRUB_DEFAULT, use \`%s' (for versions before 2.00) or \`%s' (for 2.00 or later)" "$GRUB_ACTUAL_DEFAULT" "$replacement_title" "gnulinux-advanced-$boot_device_id>gnulinux-$version-$type-$boot_device_id")"
105      fi
106      echo "menuentry '$(echo "$title" | grub_quote)' ${CLASS} \$menuentry_id_option 'xen-gnulinux-$version-$type-$boot_device_id' {" | sed "s/^/$submenu_indentation/"
107  else
108      title="$(gettext_printf "%s, with Xen hypervisor" "${os}")"
109      echo "menuentry '$(echo "$title" | grub_quote)' ${CLASS} \$menuentry_id_option 'xen-gnulinux-simple-$boot_device_id' {" | sed "s/^/$submenu_indentation/"
110  fi
111  if [ x$type != xrecovery ] ; then
112      save_default_entry | grub_add_tab | sed "s/^/$submenu_indentation/"
113  fi
114
115  if [ -z "${prepare_boot_cache}" ]; then
116    prepare_boot_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | grub_add_tab)"
117  fi
118  printf '%s\n' "${prepare_boot_cache}" | sed "s/^/$submenu_indentation/"
119  xmessage="$(gettext_printf "Loading Xen %s ..." ${xen_version})"
120  lmessage="$(gettext_printf "Loading Linux %s ..." ${version})"
121  sed "s/^/$submenu_indentation/" << EOF
122        echo    '$(echo "$xmessage" | grub_quote)'
123        if [ "\$grub_platform" = "pc" -o "\$grub_platform" = "" ]; then
124            xen_rm_opts=
125        else
126            xen_rm_opts="no-real-mode edd=off"
127        fi
128        multiboot       ${rel_xen_dirname}/${xen_basename} placeholder ${xen_args} \${xen_rm_opts}
129        echo    '$(echo "$lmessage" | grub_quote)'
130        module  ${rel_dirname}/${basename} placeholder root=${linux_root_device_thisversion} ro ${args}
131EOF
132  if test -n "${initrd}" ; then
133    # TRANSLATORS: ramdisk isn't identifier. Should be translated.
134    message="$(gettext_printf "Loading initial ramdisk ...")"
135    sed "s/^/$submenu_indentation/" << EOF
136        echo    '$(echo "$message" | grub_quote)'
137        module  --nounzip   ${rel_dirname}/${initrd}
138EOF
139  fi
140  sed "s/^/$submenu_indentation/" << EOF
141}
142EOF
143}
144
145linux_list=`for i in /boot/vmlinu[xz]-* /vmlinu[xz]-* /boot/kernel-*; do
146    if grub_file_is_not_garbage "$i"; then
147        basename=$(basename $i)
148        version=$(echo $basename | sed -e "s,^[^0-9]*-,,g")
149        dirname=$(dirname $i)
150        config=
151        for j in "${dirname}/config-${version}" "${dirname}/config-${alt_version}" "/etc/kernels/kernel-config-${version}" ; do
152            if test -e "${j}" ; then
153                config="${j}"
154                break
155            fi
156        done
157        if (grep -qx "CONFIG_XEN_DOM0=y" "${config}" 2> /dev/null || grep -qx "CONFIG_XEN_PRIVILEGED_GUEST=y" "${config}" 2> /dev/null); then echo -n "$i " ; fi
158    fi
159    done`
160if [ "x${linux_list}" = "x" ] ; then
161    exit 0
162fi
163
164file_is_not_sym () {
165    case "$1" in
166        */xen-syms-*)
167            return 1;;
168        *)
169            return 0;;
170    esac
171}
172
173xen_list=`for i in /boot/xen*; do
174        if grub_file_is_not_garbage "$i" && file_is_not_sym "$i" ; then echo -n "$i " ; fi
175      done`
176prepare_boot_cache=
177boot_device_id=
178
179title_correction_code=
180
181machine=`uname -m`
182
183case "$machine" in
184    i?86) GENKERNEL_ARCH="x86" ;;
185    mips|mips64) GENKERNEL_ARCH="mips" ;;
186    mipsel|mips64el) GENKERNEL_ARCH="mipsel" ;;
187    arm*) GENKERNEL_ARCH="arm" ;;
188    *) GENKERNEL_ARCH="$machine" ;;
189esac
190
191# Extra indentation to add to menu entries in a submenu. We're not in a submenu
192# yet, so it's empty. In a submenu it will be equal to '\t' (one tab).
193submenu_indentation=""
194
195is_top_level=true
196
197while [ "x${xen_list}" != "x" ] ; do
198    list="${linux_list}"
199    current_xen=`version_find_latest $xen_list`
200    xen_basename=`basename ${current_xen}`
201    xen_dirname=`dirname ${current_xen}`
202    rel_xen_dirname=`make_system_path_relative_to_its_root $xen_dirname`
203    xen_version=`echo $xen_basename | sed -e "s,.gz$,,g;s,^xen-,,g"`
204    if [ -z "$boot_device_id" ]; then
205        boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")"
206    fi
207    if [ "x$is_top_level" != xtrue ]; then
208        echo "  submenu '$(gettext_printf "Xen hypervisor, version %s" "${xen_version}" | grub_quote)' \$menuentry_id_option 'xen-hypervisor-$xen_version-$boot_device_id' {"
209    fi
210    while [ "x$list" != "x" ] ; do
211        linux=`version_find_latest $list`
212        gettext_printf "Found linux image: %s\n" "$linux" >&2
213        basename=`basename $linux`
214        dirname=`dirname $linux`
215        rel_dirname=`make_system_path_relative_to_its_root $dirname`
216        version=`echo $basename | sed -e "s,^[^0-9]*-,,g"`
217        alt_version=`echo $version | sed -e "s,\.old$,,g"`
218        linux_root_device_thisversion="${LINUX_ROOT_DEVICE}"
219
220        initrd=
221        for i in "initrd.img-${version}" "initrd-${version}.img" "initrd-${version}.gz" \
222           "initrd-${version}" "initramfs-${version}.img" \
223           "initrd.img-${alt_version}" "initrd-${alt_version}.img" \
224           "initrd-${alt_version}" "initramfs-${alt_version}.img" \
225           "initramfs-genkernel-${version}" \
226           "initramfs-genkernel-${alt_version}" \
227           "initramfs-genkernel-${GENKERNEL_ARCH}-${version}" \
228           "initramfs-genkernel-${GENKERNEL_ARCH}-${alt_version}" ; do
229            if test -e "${dirname}/${i}" ; then
230                initrd="$i"
231                break
232            fi
233        done
234        if test -n "${initrd}" ; then
235            gettext_printf "Found initrd image: %s\n" "${dirname}/${initrd}" >&2
236        else
237    # "UUID=" magic is parsed by initrds.  Since there's no initrd, it can't work here.
238            linux_root_device_thisversion=${GRUB_DEVICE}
239        fi
240
241        if [ "x$is_top_level" = xtrue ] && [ "x${GRUB_DISABLE_SUBMENU}" != xy ]; then
242            linux_entry "${OS}" "${version}" "${xen_version}" simple \
243                "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}" "${GRUB_CMDLINE_XEN} ${GRUB_CMDLINE_XEN_DEFAULT}"
244
245            submenu_indentation="$grub_tab$grub_tab"
246   
247            if [ -z "$boot_device_id" ]; then
248                boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")"
249            fi
250            # TRANSLATORS: %s is replaced with an OS name
251            echo "submenu '$(gettext_printf "Advanced options for %s (with Xen hypervisor)" "${OS}" | grub_quote)' \$menuentry_id_option 'gnulinux-advanced-$boot_device_id' {"
252        echo "  submenu '$(gettext_printf "Xen hypervisor, version %s" "${xen_version}" | grub_quote)' \$menuentry_id_option 'xen-hypervisor-$xen_version-$boot_device_id' {"
253           is_top_level=false
254        fi
255
256        linux_entry "${OS}" "${version}" "${xen_version}" advanced \
257            "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}" "${GRUB_CMDLINE_XEN} ${GRUB_CMDLINE_XEN_DEFAULT}"
258        if [ "x${GRUB_DISABLE_RECOVERY}" != "xtrue" ]; then
259            linux_entry "${OS}" "${version}" "${xen_version}" recovery \
260                "single ${GRUB_CMDLINE_LINUX}" "${GRUB_CMDLINE_XEN}"
261        fi
262
263        list=`echo $list | tr ' ' '\n' | grep -vx $linux | tr '\n' ' '`
264    done
265    if [ x"$is_top_level" != xtrue ]; then
266        echo '  }'
267    fi
268    xen_list=`echo $xen_list | tr ' ' '\n' | grep -vx $current_xen | tr '\n' ' '`
269done
270
271# If at least one kernel was found, then we need to
272# add a closing '}' for the submenu command.
273if [ x"$is_top_level" != xtrue ]; then
274  echo '}'
275fi
276
277echo "$title_correction_code"
Note: See TracBrowser for help on using the repository browser.