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