Subversion Repositories configs

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
192 - 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="/usr"
21
exec_prefix="/usr"
22
datarootdir="/usr/share"
23
 
24
. "$pkgdatadir/grub-mkconfig_lib"
25
 
26
export TEXTDOMAIN=grub
27
export TEXTDOMAINDIR="${datarootdir}/locale"
28
 
29
CLASS="--class gnu-linux --class gnu --class os --unrestricted"
30
 
31
if [ "x${GRUB_DISTRIBUTOR}" = "x" ] ; then
32
  OS="$(eval $(grep PRETTY_NAME /etc/os-release) ; echo ${PRETTY_NAME})"
33
  CLASS="--class $(eval $(grep '^ID_LIKE=\|^ID=' /etc/os-release) ; [ -n "${ID_LIKE}" ] && echo ${ID_LIKE} || echo ${ID}) ${CLASS}"
34
else
35
  OS="${GRUB_DISTRIBUTOR}"
36
  CLASS="--class $(echo ${GRUB_DISTRIBUTOR} | tr 'A-Z' 'a-z' | cut -d' ' -f1|LC_ALL=C sed 's,[^[:alnum:]_],_,g') ${CLASS}"
37
fi
38
 
39
# loop-AES arranges things so that /dev/loop/X can be our root device, but
40
# the initrds that Linux uses don't like that.
41
case ${GRUB_DEVICE} in
42
  /dev/loop/*|/dev/loop[0-9])
43
    GRUB_DEVICE=`losetup ${GRUB_DEVICE} | sed -e "s/^[^(]*(\([^)]\+\)).*/\1/"`
44
  ;;
45
esac
46
 
47
# Default to disabling partition uuid support to maintian compatibility with
48
# older kernels.
49
GRUB_DISABLE_LINUX_PARTUUID=${GRUB_DISABLE_LINUX_PARTUUID-true}
50
 
51
# btrfs may reside on multiple devices. We cannot pass them as value of root= parameter
52
# and mounting btrfs requires user space scanning, so force UUID in this case.
53
if ( [ "x${GRUB_DEVICE_UUID}" = "x" ] && [ "x${GRUB_DEVICE_PARTUUID}" = "x" ] ) \
54
    || ( [ "x${GRUB_DISABLE_LINUX_UUID}" = "xtrue" ] \
55
	&& [ "x${GRUB_DISABLE_LINUX_PARTUUID}" = "xtrue" ] ) \
56
    || ( ! test -e "/dev/disk/by-uuid/${GRUB_DEVICE_UUID}" \
57
	&& ! test -e "/dev/disk/by-partuuid/${GRUB_DEVICE_PARTUUID}" ) \
58
    || ( test -e "${GRUB_DEVICE}" && uses_abstraction "${GRUB_DEVICE}" lvm ); then
59
  LINUX_ROOT_DEVICE=${GRUB_DEVICE}
60
elif [ "x${GRUB_DEVICE_UUID}" = "x" ] \
61
    || [ "x${GRUB_DISABLE_LINUX_UUID}" = "xtrue" ]; then
62
  LINUX_ROOT_DEVICE=PARTUUID=${GRUB_DEVICE_PARTUUID}
63
else
64
  LINUX_ROOT_DEVICE=UUID=${GRUB_DEVICE_UUID}
65
fi
66
 
67
case x"$GRUB_FS" in
68
    xbtrfs)
69
	if [ "x${SUSE_BTRFS_SNAPSHOT_BOOTING}" = "xtrue" ]; then
70
	GRUB_CMDLINE_LINUX="${GRUB_CMDLINE_LINUX} \${extra_cmdline}"
71
	else
72
	rootsubvol="`make_system_path_relative_to_its_root /`"
73
	rootsubvol="${rootsubvol#/}"
74
	if [ "x${rootsubvol}" != x ]; then
75
	    GRUB_CMDLINE_LINUX="rootflags=subvol=${rootsubvol} ${GRUB_CMDLINE_LINUX}"
76
	fi
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
	;;
83
esac
84
 
85
populate_header_warn()
86
{
87
cat <<EOF
88
 
89
# This section was generated by a script. Do not modify the generated file - all changes
90
# will be lost the next time file is regenerated. Instead edit the BootLoaderSpec files.
91
#
92
# The blscfg command parses the BootLoaderSpec files stored in /boot/loader/entries and
93
# populates the boot menu. Please refer to the Boot Loader Specification documentation
94
# for the files format: https://www.freedesktop.org/wiki/Specifications/BootLoaderSpec/.
95
 
96
EOF
97
}
98
 
99
mktitle ()
100
{
101
  local title_type
102
  local version
103
  local OS_NAME
104
  local OS_VERS
105
 
106
  title_type=$1 && shift
107
  version=$1 && shift
108
 
109
  OS_NAME="$(eval $(grep ^NAME= /etc/os-release) ; echo ${NAME})"
110
  OS_VERS="$(eval $(grep ^VERSION= /etc/os-release) ; echo ${VERSION})"
111
 
112
  case $title_type in
113
    recovery)
114
      title=$(printf '%s (%s) %s (recovery mode)' \
115
                     "${OS_NAME}" "${version}" "${OS_VERS}")
116
      ;;
117
    *)
118
      title=$(printf '%s (%s) %s' \
119
                     "${OS_NAME}" "${version}" "${OS_VERS}")
120
      ;;
121
  esac
122
  echo -n ${title}
123
}
124
 
125
title_correction_code=
126
 
127
linux_entry ()
128
{
129
  os="$1"
130
  version="$2"
131
  type="$3"
132
  isdebug="$4"
133
  args="$5"
134
 
135
  if [ -z "$boot_device_id" ]; then
136
      boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")"
137
  fi
138
 
139
  if [ "x${GRUB_ENABLE_BLSCFG}" = "xtrue" ]; then
140
    if [ x$dirname = x/ ]; then
141
      if [ -z "${prepare_root_cache}" ]; then
142
        prepare_grub_to_access_device ${GRUB_DEVICE}
143
      fi
144
    else
145
      if [ -z "${prepare_boot_cache}" ]; then
146
        prepare_grub_to_access_device ${GRUB_DEVICE_BOOT}
147
      fi
148
    fi
149
 
150
    if [ -d /sys/firmware/efi ]; then
151
        bootefi_device="`${grub_probe} --target=device /boot/efi/`"
152
        prepare_grub_to_access_device ${bootefi_device} boot
153
    else
154
        boot_device="`${grub_probe} --target=device /boot/`"
155
        prepare_grub_to_access_device ${boot_device} boot
156
    fi
157
 
158
    populate_header_warn
159
 
160
    cat << EOF
161
# The kernelopts variable should be defined in the grubenv file. But to ensure that menu
162
# entries populated from BootLoaderSpec files that use this variable work correctly even
163
# without a grubenv file, define a fallback kernelopts variable if this has not been set.
164
#
165
# The kernelopts variable in the grubenv file can be modified using the grubby tool or by
166
# executing the grub2-mkconfig tool. For the latter, the values of the GRUB_CMDLINE_LINUX
167
# and GRUB_CMDLINE_LINUX_DEFAULT options from /etc/default/grub file are used to set both
168
# the kernelopts variable in the grubenv file and the fallback kernelopts variable.
169
if [ -z "\${kernelopts}" ]; then
170
  set kernelopts="root=${linux_root_device_thisversion} ro ${args}"
171
fi
172
 
173
insmod blscfg
174
blscfg
175
EOF
176
 
177
    if [ "x${GRUB_GRUBENV_UPDATE}" = "xyes" ]; then
178
	${grub_editenv} - set kernelopts="root=${linux_root_device_thisversion} ro ${args}"
179
    fi
180
 
181
    exit 0
182
  fi
183
 
184
  if [ x$type != xsimple ] ; then
185
      title=$(mktitle "$type" "$version")
186
      if [ x"$title" = x"$GRUB_ACTUAL_DEFAULT" ] || [ x"Previous Linux versions>$title" = x"$GRUB_ACTUAL_DEFAULT" ]; then
187
	  replacement_title="$(echo "Advanced options for ${OS}" | sed 's,>,>>,g')>$(echo "$title" | sed 's,>,>>,g')"
188
	  quoted="$(echo "$GRUB_ACTUAL_DEFAULT" | grub_quote)"
189
	  title_correction_code="${title_correction_code}if [ \"x\$default\" = '$quoted' ]; then default='$(echo "$replacement_title" | grub_quote)'; fi;"
190
      fi
191
      if [ x$isdebug = xdebug ]; then
192
	  title="$title${GRUB_LINUX_DEBUG_TITLE_POSTFIX}"
193
      fi
194
      echo "menuentry '$(echo "$title" | grub_quote)' ${CLASS} \$menuentry_id_option 'gnulinux-$version-$type-$boot_device_id' {" | sed "s/^/$submenu_indentation/"
195
  else
196
      echo "menuentry '$(echo "$os" | grub_quote)' ${CLASS} \$menuentry_id_option 'gnulinux-simple-$boot_device_id' {" | sed "s/^/$submenu_indentation/"
197
  fi
198
  if [ x$type != xrecovery ] ; then
199
      save_default_entry | grub_add_tab
200
  fi
201
 
202
  # Use ELILO's generic "efifb" when it's known to be available.
203
  # FIXME: We need an interface to select vesafb in case efifb can't be used.
204
  if [ "x$GRUB_GFXPAYLOAD_LINUX" = x ]; then
205
      echo "	load_video" | sed "s/^/$submenu_indentation/"
206
      if grep -qx "CONFIG_FB_EFI=y" "${config}" 2> /dev/null \
207
	  && grep -qx "CONFIG_VT_HW_CONSOLE_BINDING=y" "${config}" 2> /dev/null; then
208
	  echo "	set gfxpayload=keep" | sed "s/^/$submenu_indentation/"
209
      fi
210
  else
211
      if [ "x$GRUB_GFXPAYLOAD_LINUX" != xtext ]; then
212
	  echo "	load_video" | sed "s/^/$submenu_indentation/"
213
      fi
214
      echo "	set gfxpayload=$GRUB_GFXPAYLOAD_LINUX" | sed "s/^/$submenu_indentation/"
215
  fi
216
 
217
  echo "	insmod gzio" | sed "s/^/$submenu_indentation/"
218
 
219
  if [ x$dirname = x/ ]; then
220
    if [ -z "${prepare_root_cache}" ]; then
221
      prepare_root_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE} | grub_add_tab)"
222
    fi
223
    printf '%s\n' "${prepare_root_cache}" | sed "s/^/$submenu_indentation/"
224
  else
225
    if [ -z "${prepare_boot_cache}" ]; then
226
      prepare_boot_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | grub_add_tab)"
227
    fi
228
    printf '%s\n' "${prepare_boot_cache}" | sed "s/^/$submenu_indentation/"
229
  fi
230
  sed "s/^/$submenu_indentation/" << EOF
231
	linux	${rel_dirname}/${basename} root=${linux_root_device_thisversion} ro ${args}
232
EOF
233
  if test -n "${initrd}" ; then
234
    initrd_path=
235
    for i in ${initrd}; do
236
      initrd_path="${initrd_path} ${rel_dirname}/${i}"
237
    done
238
    sed "s/^/$submenu_indentation/" << EOF
239
	initrd	$(echo $initrd_path)
240
EOF
241
  fi
242
  if test -n "${fdt}" ; then
243
    sed "s/^/$submenu_indentation/" << EOF
244
	devicetree	${rel_dirname}/${fdt}
245
EOF
246
  fi
247
  sed "s/^/$submenu_indentation/" << EOF
248
}
249
EOF
250
}
251
 
252
machine=`uname -m`
253
case "x$machine" in
254
    xi?86 | xx86_64)
255
	list=
256
	for i in /boot/vmlinuz-* /vmlinuz-* /boot/kernel-* ; do
257
	    if grub_file_is_not_garbage "$i" ; then list="$list $i" ; fi
258
	done ;;
259
    *)
260
	list=
261
	for i in /boot/vmlinuz-* /boot/vmlinux-* /vmlinuz-* /vmlinux-* /boot/kernel-* ; do
262
                  if grub_file_is_not_garbage "$i" ; then list="$list $i" ; fi
263
	done ;;
264
esac
265
 
266
if [ "x${GRUB_ENABLE_BLSCFG}" = "xtrue" ]; then
267
    for i in /boot/ostree/*/vmlinuz-* ; do
268
        if grub_file_is_not_garbage "$i" ; then list="$list $i" ; fi
269
    done
270
fi
271
 
272
case "$machine" in
273
    i?86) GENKERNEL_ARCH="x86" ;;
274
    mips|mips64) GENKERNEL_ARCH="mips" ;;
275
    mipsel|mips64el) GENKERNEL_ARCH="mipsel" ;;
276
    arm*) GENKERNEL_ARCH="arm" ;;
277
    *) GENKERNEL_ARCH="$machine" ;;
278
esac
279
 
280
prepare_boot_cache=
281
prepare_root_cache=
282
boot_device_id=
283
title_correction_code=
284
 
285
# Extra indentation to add to menu entries in a submenu. We're not in a submenu
286
# yet, so it's empty. In a submenu it will be equal to '\t' (one tab).
287
submenu_indentation=""
288
 
289
is_top_level=true
290
while [ "x$list" != "x" ] ; do
291
  linux=`version_find_latest $list`
292
  if [ "x${GRUB_ENABLE_BLSCFG}" != "xtrue" ]; then
293
    gettext_printf "Found linux image: %s\n" "$linux" >&2
294
  fi
295
 
296
  basename=`basename $linux`
297
  dirname=`dirname $linux`
298
  rel_dirname=`make_system_path_relative_to_its_root $dirname`
299
  version=`echo $basename | sed -e "s,^[^0-9]*-,,g"`
300
  alt_version=`echo $version | sed -e "s,\.old$,,g"`
301
  linux_root_device_thisversion="${LINUX_ROOT_DEVICE}"
302
 
303
  initrd_early=
304
  for i in ${GRUB_EARLY_INITRD_LINUX_STOCK} \
305
	   ${GRUB_EARLY_INITRD_LINUX_CUSTOM}; do
306
    if test -e "${dirname}/${i}" ; then
307
      initrd_early="${initrd_early} ${i}"
308
    fi
309
  done
310
 
311
  initrd_real=
312
  for i in "initrd.img-${version}" "initrd-${version}.img" "initrd-${version}.gz" \
313
	   "initrd-${version}" "initramfs-${version}.img" \
314
	   "initrd.img-${alt_version}" "initrd-${alt_version}.img" \
315
	   "initrd-${alt_version}" "initramfs-${alt_version}.img" \
316
	   "initramfs-genkernel-${version}" \
317
	   "initramfs-genkernel-${alt_version}" \
318
	   "initramfs-genkernel-${GENKERNEL_ARCH}-${version}" \
319
	   "initramfs-genkernel-${GENKERNEL_ARCH}-${alt_version}"; do
320
    if test -e "${dirname}/${i}" ; then
321
      initrd_real="${i}"
322
      break
323
    fi
324
  done
325
 
326
  initrd=
327
  if test -n "${initrd_early}" || test -n "${initrd_real}"; then
328
    initrd="${initrd_early} ${initrd_real}"
329
 
330
    initrd_display=
331
    for i in ${initrd}; do
332
      initrd_display="${initrd_display} ${dirname}/${i}"
333
    done
334
    if [ "x${GRUB_ENABLE_BLSCFG}" != "xtrue" ]; then
335
      gettext_printf "Found initrd image: %s\n" "$(echo $initrd_display)" >&2
336
    fi
337
  fi
338
 
339
  fdt=
340
  for i in "dtb-${version}" "dtb-${alt_version}"; do
341
    if test -f "${dirname}/${i}/${GRUB_DEFAULT_DTB}" ; then
342
      fdt="${i}/${GRUB_DEFAULT_DTB}"
343
      break
344
    fi
345
  done
346
 
347
  config=
348
  for i in "${dirname}/config-${version}" "${dirname}/config-${alt_version}" "/etc/kernels/kernel-config-${version}" ; do
349
    if test -e "${i}" ; then
350
      config="${i}"
351
      break
352
    fi
353
  done
354
 
355
  initramfs=
356
  if test -n "${config}" ; then
357
      initramfs=`grep CONFIG_INITRAMFS_SOURCE= "${config}" | cut -f2 -d= | tr -d \"`
358
  fi
359
 
360
  if test -z "${initramfs}" && test -z "${initrd_real}" ; then
361
    # "UUID=" and "ZFS=" magic is parsed by initrd or initramfs.  Since there's
362
    # no initrd or builtin initramfs, it can't work here.
363
    if [ "x${GRUB_DEVICE_PARTUUID}" = "x" ] \
364
	|| [ "x${GRUB_DISABLE_LINUX_PARTUUID}" = "xtrue" ]; then
365
 
366
	linux_root_device_thisversion=${GRUB_DEVICE}
367
    else
368
	linux_root_device_thisversion=PARTUUID=${GRUB_DEVICE_PARTUUID}
369
    fi
370
  fi
371
 
372
  if [ "x${GRUB_DISABLE_SUBMENU}" = "xyes" ] || [ "x${GRUB_DISABLE_SUBMENU}" = "xy" ]; then
373
    GRUB_DISABLE_SUBMENU="true"
374
  fi
375
 
376
  if [ "x$is_top_level" = xtrue ] && [ "x${GRUB_DISABLE_SUBMENU}" != xtrue ]; then
377
    linux_entry "${OS}" "${version}" simple standard \
378
    "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}"
379
    if [ "x$GRUB_LINUX_MAKE_DEBUG" = "xtrue" ]; then
380
      linux_entry "${OS}" "${version}" simple debug \
381
        "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT} ${GRUB_CMDLINE_LINUX_DEBUG}"
382
    fi
383
 
384
    submenu_indentation="$grub_tab"
385
 
386
    if [ -z "$boot_device_id" ]; then
387
	boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")"
388
    fi
389
    # TRANSLATORS: %s is replaced with an OS name
390
    echo "submenu '$(gettext_printf "Advanced options for %s" "${OS}" | grub_quote)' \$menuentry_id_option 'gnulinux-advanced-$boot_device_id' {"
391
    is_top_level=false
392
  fi
393
 
394
  linux_entry "${OS}" "${version}" advanced standard \
395
              "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}"
396
  if [ "x$GRUB_LINUX_MAKE_DEBUG" = "xtrue" ]; then
397
    linux_entry "${OS}" "${version}" advanced debug \
398
                "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT} ${GRUB_CMDLINE_LINUX_DEBUG}"
399
  fi
400
 
401
  if [ "x${GRUB_DISABLE_RECOVERY}" != "xtrue" ]; then
402
    linux_entry "${OS}" "${version}" recovery standard \
403
                "single ${GRUB_CMDLINE_LINUX}"
404
  fi
405
 
406
  list=`echo $list | tr ' ' '\n' | fgrep -vx "$linux" | tr '\n' ' '`
407
done
408
 
409
# If at least one kernel was found, then we need to
410
# add a closing '}' for the submenu command.
411
if [ x"$is_top_level" != xtrue ]; then
412
  echo '}'
413
fi
414
 
415
echo "$title_correction_code"