source: grub-pc/trunk/fuentes/.pc/quick_boot.patch/util/grub.d/10_linux.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.0 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@"
23ubuntu_recovery="@UBUNTU_RECOVERY@"
24quiet_boot="@QUIET_BOOT@"
25
26. "@datadir@/@PACKAGE@/grub-mkconfig_lib"
27
28export TEXTDOMAIN=@PACKAGE@
29export TEXTDOMAINDIR="@localedir@"
30
31CLASS="--class gnu-linux --class gnu --class os"
32
33if [ "x${GRUB_DISTRIBUTOR}" = "x" ] ; then
34  OS=GNU/Linux
35else
36  case ${GRUB_DISTRIBUTOR} in
37    Ubuntu|Kubuntu)
38      OS="${GRUB_DISTRIBUTOR}"
39      ;;
40    *)
41      OS="${GRUB_DISTRIBUTOR} GNU/Linux"
42      ;;
43  esac
44  CLASS="--class $(echo ${GRUB_DISTRIBUTOR} | tr 'A-Z' 'a-z' | cut -d' ' -f1|LC_ALL=C sed 's,[^[:alnum:]_],_,g') ${CLASS}"
45fi
46
47# loop-AES arranges things so that /dev/loop/X can be our root device, but
48# the initrds that Linux uses don't like that.
49case ${GRUB_DEVICE} in
50  /dev/loop/*|/dev/loop[0-9])
51    GRUB_DEVICE=`losetup ${GRUB_DEVICE} | sed -e "s/^[^(]*(\([^)]\+\)).*/\1/"`
52    # We can't cope with devices loop-mounted from files here.
53    case ${GRUB_DEVICE} in
54      /dev/*) ;;
55      *) exit 0 ;;
56    esac
57  ;;
58esac
59
60if [ "x${GRUB_DEVICE_UUID}" = "x" ] || [ "x${GRUB_DISABLE_LINUX_UUID}" = "xtrue" ] \
61    || ! test -e "/dev/disk/by-uuid/${GRUB_DEVICE_UUID}" \
62    || uses_abstraction "${GRUB_DEVICE}" lvm; then
63  LINUX_ROOT_DEVICE=${GRUB_DEVICE}
64else
65  LINUX_ROOT_DEVICE=UUID=${GRUB_DEVICE_UUID}
66fi
67
68case x"$GRUB_FS" in
69    xbtrfs)
70        rootsubvol="`make_system_path_relative_to_its_root /`"
71        rootsubvol="${rootsubvol#/}"
72        if [ "x${rootsubvol}" != x ]; then
73            GRUB_CMDLINE_LINUX="rootflags=subvol=${rootsubvol} ${GRUB_CMDLINE_LINUX}"
74        fi;;
75    xzfs)
76        rpool=`${grub_probe} --device ${GRUB_DEVICE} --target=fs_label 2>/dev/null || true`
77        bootfs="`make_system_path_relative_to_its_root / | sed -e "s,@$,,"`"
78        LINUX_ROOT_DEVICE="ZFS=${rpool}${bootfs}"
79        ;;
80esac
81
82title_correction_code=
83
84if [ -x /lib/recovery-mode/recovery-menu ]; then
85    GRUB_CMDLINE_LINUX_RECOVERY=recovery
86else
87    GRUB_CMDLINE_LINUX_RECOVERY=single
88fi
89if [ "$ubuntu_recovery" = 1 ]; then
90    GRUB_CMDLINE_LINUX_RECOVERY="$GRUB_CMDLINE_LINUX_RECOVERY nomodeset"
91fi
92
93linux_entry ()
94{
95  os="$1"
96  version="$2"
97  type="$3"
98  args="$4"
99
100  if [ -z "$boot_device_id" ]; then
101      boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")"
102  fi
103  if [ x$type != xsimple ] ; then
104      case $type in
105          recovery)
106              title="$(gettext_printf "%s, with Linux %s (recovery mode)" "${os}" "${version}")" ;;
107          *)
108              title="$(gettext_printf "%s, with Linux %s" "${os}" "${version}")" ;;
109      esac
110      if [ x"$title" = x"$GRUB_ACTUAL_DEFAULT" ] || [ x"Previous Linux versions>$title" = x"$GRUB_ACTUAL_DEFAULT" ]; then
111          replacement_title="$(echo "Advanced options for ${OS}" | sed 's,>,>>,g')>$(echo "$title" | sed 's,>,>>,g')"
112          quoted="$(echo "$GRUB_ACTUAL_DEFAULT" | grub_quote)"
113          title_correction_code="${title_correction_code}if [ \"x\$default\" = '$quoted' ]; then default='$(echo "$replacement_title" | grub_quote)'; fi;"
114          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")"
115      fi
116      echo "menuentry '$(echo "$title" | grub_quote)' ${CLASS} \$menuentry_id_option 'gnulinux-$version-$type-$boot_device_id' {" | sed "s/^/$submenu_indentation/"
117  else
118      echo "menuentry '$(echo "$os" | grub_quote)' ${CLASS} \$menuentry_id_option 'gnulinux-simple-$boot_device_id' {" | sed "s/^/$submenu_indentation/"
119  fi     
120  if [ x$type != xrecovery ] ; then
121      save_default_entry | grub_add_tab
122  fi
123
124  # Use ELILO's generic "efifb" when it's known to be available.
125  # FIXME: We need an interface to select vesafb in case efifb can't be used.
126  if [ "x$GRUB_GFXPAYLOAD_LINUX" = x ]; then
127      echo "    load_video" | sed "s/^/$submenu_indentation/"
128  else
129      if [ "x$GRUB_GFXPAYLOAD_LINUX" != xtext ]; then
130          echo "        load_video" | sed "s/^/$submenu_indentation/"
131      fi
132      if [ "$ubuntu_recovery" = 0 ] || [ x$type != xrecovery ]; then
133          echo "        set gfxpayload=$GRUB_GFXPAYLOAD_LINUX" | sed "s/^/$submenu_indentation/"
134      fi
135  fi
136
137  echo "        insmod gzio" | sed "s/^/$submenu_indentation/"
138
139  if [ x$dirname = x/ ]; then
140    if [ -z "${prepare_root_cache}" ]; then
141      prepare_root_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE} | grub_add_tab)"
142    fi
143    printf '%s\n' "${prepare_root_cache}" | sed "s/^/$submenu_indentation/"
144  else
145    if [ -z "${prepare_boot_cache}" ]; then
146      prepare_boot_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | grub_add_tab)"
147    fi
148    printf '%s\n' "${prepare_boot_cache}" | sed "s/^/$submenu_indentation/"
149  fi
150  if [ x"$quiet_boot" = x0 ] || [ x"$type" != xsimple ]; then
151    message="$(gettext_printf "Loading Linux %s ..." ${version})"
152    sed "s/^/$submenu_indentation/" << EOF
153        echo    '$(echo "$message" | grub_quote)'
154EOF
155  fi
156  if test -d /sys/firmware/efi && test -e "${linux}.efi.signed"; then
157    sed "s/^/$submenu_indentation/" << EOF
158        linux   ${rel_dirname}/${basename}.efi.signed root=${linux_root_device_thisversion} ro ${args}
159EOF
160  else
161    sed "s/^/$submenu_indentation/" << EOF
162        linux   ${rel_dirname}/${basename} root=${linux_root_device_thisversion} ro ${args}
163EOF
164  fi
165  if test -n "${initrd}" ; then
166    # TRANSLATORS: ramdisk isn't identifier. Should be translated.
167    if [ x"$quiet_boot" = x0 ] || [ x"$type" != xsimple ]; then
168      message="$(gettext_printf "Loading initial ramdisk ...")"
169      sed "s/^/$submenu_indentation/" << EOF
170        echo    '$(echo "$message" | grub_quote)'
171EOF
172    fi
173    sed "s/^/$submenu_indentation/" << EOF
174        initrd  ${rel_dirname}/${initrd}
175EOF
176  fi
177  sed "s/^/$submenu_indentation/" << EOF
178}
179EOF
180}
181
182machine=`uname -m`
183case "x$machine" in
184    xi?86 | xx86_64)
185        list=`for i in /boot/vmlinuz-* /vmlinuz-* /boot/kernel-* ; do
186                  if grub_file_is_not_garbage "$i" ; then echo -n "$i " ; fi
187              done` ;;
188    *)
189        list=`for i in /boot/vmlinuz-* /boot/vmlinux-* /vmlinuz-* /vmlinux-* /boot/kernel-* ; do
190                  if grub_file_is_not_garbage "$i" ; then echo -n "$i " ; fi
191             done` ;;
192esac
193
194case "$machine" in
195    i?86) GENKERNEL_ARCH="x86" ;;
196    mips|mips64) GENKERNEL_ARCH="mips" ;;
197    mipsel|mips64el) GENKERNEL_ARCH="mipsel" ;;
198    arm*) GENKERNEL_ARCH="arm" ;;
199    *) GENKERNEL_ARCH="$machine" ;;
200esac
201
202prepare_boot_cache=
203prepare_root_cache=
204boot_device_id=
205title_correction_code=
206
207# Extra indentation to add to menu entries in a submenu. We're not in a submenu
208# yet, so it's empty. In a submenu it will be equal to '\t' (one tab).
209submenu_indentation=""
210
211is_top_level=true
212while [ "x$list" != "x" ] ; do
213  linux=`version_find_latest $list`
214  case $linux in
215    *.efi.signed)
216      # We handle these in linux_entry.
217      list=`echo $list | tr ' ' '\n' | grep -vx $linux | tr '\n' ' '`
218      continue
219      ;;
220  esac
221  gettext_printf "Found linux image: %s\n" "$linux" >&2
222  basename=`basename $linux`
223  dirname=`dirname $linux`
224  rel_dirname=`make_system_path_relative_to_its_root $dirname`
225  version=`echo $basename | sed -e "s,^[^0-9]*-,,g"`
226  alt_version=`echo $version | sed -e "s,\.old$,,g"`
227  linux_root_device_thisversion="${LINUX_ROOT_DEVICE}"
228
229  initrd=
230  for i in "initrd.img-${version}" "initrd-${version}.img" "initrd-${version}.gz" \
231           "initrd-${version}" "initramfs-${version}.img" \
232           "initrd.img-${alt_version}" "initrd-${alt_version}.img" \
233           "initrd-${alt_version}" "initramfs-${alt_version}.img" \
234           "initramfs-genkernel-${version}" \
235           "initramfs-genkernel-${alt_version}" \
236           "initramfs-genkernel-${GENKERNEL_ARCH}-${version}" \
237           "initramfs-genkernel-${GENKERNEL_ARCH}-${alt_version}"; do
238    if test -e "${dirname}/${i}" ; then
239      initrd="$i"
240      break
241    fi
242  done
243
244  config=
245  for i in "${dirname}/config-${version}" "${dirname}/config-${alt_version}" "/etc/kernels/kernel-config-${version}" ; do
246    if test -e "${i}" ; then
247      config="${i}"
248      break
249    fi
250  done
251
252  initramfs=
253  if test -n "${config}" ; then
254      initramfs=`grep CONFIG_INITRAMFS_SOURCE= "${config}" | cut -f2 -d= | tr -d \"`
255  fi
256
257  if test -n "${initrd}" ; then
258    gettext_printf "Found initrd image: %s\n" "${dirname}/${initrd}" >&2
259  elif test -z "${initramfs}" ; then
260    # "UUID=" and "ZFS=" magic is parsed by initrd or initramfs.  Since there's
261    # no initrd or builtin initramfs, it can't work here.
262    linux_root_device_thisversion=${GRUB_DEVICE}
263  fi
264
265  if [ "x$is_top_level" = xtrue ] && [ "x${GRUB_DISABLE_SUBMENU}" != xy ]; then
266    linux_entry "${OS}" "${version}" simple \
267    "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}"
268
269    submenu_indentation="$grub_tab"
270   
271    if [ -z "$boot_device_id" ]; then
272        boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")"
273    fi
274    # TRANSLATORS: %s is replaced with an OS name
275    echo "submenu '$(gettext_printf "Advanced options for %s" "${OS}" | grub_quote)' \$menuentry_id_option 'gnulinux-advanced-$boot_device_id' {"
276    is_top_level=false
277  fi
278
279  linux_entry "${OS}" "${version}" advanced \
280              "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}"
281  if [ "x${GRUB_DISABLE_RECOVERY}" != "xtrue" ]; then
282    linux_entry "${OS}" "${version}" recovery \
283                "${GRUB_CMDLINE_LINUX_RECOVERY} ${GRUB_CMDLINE_LINUX}"
284  fi
285
286  list=`echo $list | tr ' ' '\n' | grep -vx $linux | tr '\n' ' '`
287done
288
289# If at least one kernel was found, then we need to
290# add a closing '}' for the submenu command.
291if [ x"$is_top_level" != xtrue ]; then
292  echo '}'
293fi
294
295echo "$title_correction_code"
Note: See TracBrowser for help on using the repository browser.