Subversion Repositories ALCASAR

Rev

Details | Last modification | View Log

Rev Author Line No. Line
2432 richard 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
if [ -e /boot/grub2/user.cfg ] && grep -q GRUB2_PASSWORD /boot/grub2/user.cfg; then
30
    CLASS="--class gnu-linux --class gnu --class os --unrestricted"
31
fi
32
 
33
if [ "x${GRUB_DISTRIBUTOR}" = "x" ] ; then
34
  OS="$(eval $(grep PRETTY_NAME /etc/os-release) ; echo ${PRETTY_NAME})"
35
  CLASS="--class $(eval $(grep '^ID_LIKE=\|^ID=' /etc/os-release) ; [ -n "${ID_LIKE}" ] && echo ${ID_LIKE} || echo ${ID}) ${CLASS}"
36
else
37
  OS="${GRUB_DISTRIBUTOR}"
38
  CLASS="--class $(echo ${GRUB_DISTRIBUTOR} | tr 'A-Z' 'a-z' | cut -d' ' -f1|LC_ALL=C sed 's,[^[:alnum:]_],_,g') ${CLASS}"
39
fi
40
 
41
# loop-AES arranges things so that /dev/loop/X can be our root device, but
42
# the initrds that Linux uses don't like that.
43
case ${GRUB_DEVICE} in
44
  /dev/loop/*|/dev/loop[0-9])
45
    GRUB_DEVICE=`losetup ${GRUB_DEVICE} | sed -e "s/^[^(]*(\([^)]\+\)).*/\1/"`
46
  ;;
47
esac
48
 
49
# btrfs may reside on multiple devices. We cannot pass them as value of root= parameter
50
# and mounting btrfs requires user space scanning, so force UUID in this case.
51
if  [ "x${GRUB_DEVICE_UUID}" = "x" ] || [ "x${GRUB_DISABLE_LINUX_UUID}" = "xtrue" ] \
52
    || ( ! test -e "/dev/disk/by-uuid/${GRUB_DEVICE_UUID}" && [ "x${DURING_INSTALL}" != "x1" ] ) \
53
    || ( test -e "${GRUB_DEVICE}" && uses_abstraction "${GRUB_DEVICE}" lvm ); then
54
  LINUX_ROOT_DEVICE=${GRUB_DEVICE}
55
else
56
  LINUX_ROOT_DEVICE=UUID=${GRUB_DEVICE_UUID}
57
fi
58
 
59
case x"$GRUB_FS" in
60
    xbtrfs)
61
	rootsubvol="`make_system_path_relative_to_its_root /`"
62
	rootsubvol="${rootsubvol#/}"
63
	if [ "x${rootsubvol}" != x ]; then
64
	    GRUB_CMDLINE_LINUX="rootflags=subvol=${rootsubvol} ${GRUB_CMDLINE_LINUX}"
65
	fi;;
66
    xzfs)
67
	rpool=`${grub_probe} --device ${GRUB_DEVICE} --target=fs_label 2>/dev/null || true`
68
	bootfs="`make_system_path_relative_to_its_root / | sed -e "s,@$,,"`"
69
	LINUX_ROOT_DEVICE="ZFS=${rpool}${bootfs}"
70
	;;
71
esac
72
 
73
mktitle ()
74
{
75
  local OS_NAME="$(eval $(grep ^NAME= /etc/os-release) ; echo ${NAME})"
76
  local OS_VERS="$(eval $(grep ^VERSION= /etc/os-release) ; echo ${VERSION})"
77
 
78
  local titlestr="${OS_NAME} (%s) ${OS_VERS}"
79
  echo -n ${titlestr}
80
}
81
 
82
title_correction_code=
83
 
84
linux_entry ()
85
{
86
  os="$1"
87
  version="$2"
88
  type="$3"
89
  args="$4"
90
 
91
  sixteenbit=""
92
  linuxefi="linux"
93
  initrdefi="initrd"
94
  case "$machine" in
95
    i?86|x86_64)
96
	sixteenbit="16"
97
	linuxefi="linuxefi"
98
	initrdefi="initrdefi"
99
	;;
100
    aarch64)
101
	linuxefi="linux"
102
	initrdefi="initrd"
103
	;;
104
  esac
105
 
106
  if [ -z "$boot_device_id" ]; then
107
      boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")"
108
  fi
109
  if [ x$type != xsimple ] ; then
110
      case $type in
111
	  recovery)
112
	      title="$(printf "$(mktitle) (recovery mode)" "${version}")" ;;
113
	  *)
114
	      title="$(printf "$(mktitle)" "${version}")" ;;
115
      esac
116
      if [ x"$title" = x"$GRUB_ACTUAL_DEFAULT" ] || [ x"Previous Linux versions>$title" = x"$GRUB_ACTUAL_DEFAULT" ]; then
117
	  replacement_title="$(echo "Advanced options for ${OS}" | sed 's,>,>>,g')>$(echo "$title" | sed 's,>,>>,g')"
118
	  quoted="$(echo "$GRUB_ACTUAL_DEFAULT" | grub_quote)"
119
	  title_correction_code="${title_correction_code}if [ \"x\$default\" = '$quoted' ]; then default='$(echo "$replacement_title" | grub_quote)'; fi;"
120
      fi
121
      echo "menuentry '$(echo "$title" | grub_quote)' ${CLASS} \$menuentry_id_option 'gnulinux-$version-$type-$boot_device_id' {" | sed "s/^/$submenu_indentation/"
122
  else
123
      echo "menuentry '$(echo "$os" | grub_quote)' ${CLASS} \$menuentry_id_option 'gnulinux-simple-$boot_device_id' {" | sed "s/^/$submenu_indentation/"
124
  fi      
125
  if [ x$type != xrecovery ] ; then
126
      save_default_entry | grub_add_tab
127
  fi
128
 
129
  # Use ELILO's generic "efifb" when it's known to be available.
130
  # FIXME: We need an interface to select vesafb in case efifb can't be used.
131
  if [ "x$GRUB_GFXPAYLOAD_LINUX" = x ]; then
132
      echo "	load_video" | sed "s/^/$submenu_indentation/"
133
      if grep -qx "CONFIG_FB_EFI=y" "${config}" 2> /dev/null \
134
	  && grep -qx "CONFIG_VT_HW_CONSOLE_BINDING=y" "${config}" 2> /dev/null; then
135
	  echo "	set gfxpayload=keep" | sed "s/^/$submenu_indentation/"
136
      fi
137
  else
138
      if [ "x$GRUB_GFXPAYLOAD_LINUX" != xtext ]; then
139
	  echo "	load_video" | sed "s/^/$submenu_indentation/"
140
      fi
141
      echo "	set gfxpayload=$GRUB_GFXPAYLOAD_LINUX" | sed "s/^/$submenu_indentation/"
142
  fi
143
 
144
  echo "	insmod gzio" | sed "s/^/$submenu_indentation/"
145
 
146
  if [ x$dirname = x/ ]; then
147
    if [ -z "${prepare_root_cache}" ]; then
148
      prepare_root_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE} | grub_add_tab)"
149
    fi
150
    printf '%s\n' "${prepare_root_cache}" | sed "s/^/$submenu_indentation/"
151
  else
152
    if [ -z "${prepare_boot_cache}" ]; then
153
      prepare_boot_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | grub_add_tab)"
154
    fi
155
    printf '%s\n' "${prepare_boot_cache}" | sed "s/^/$submenu_indentation/"
156
  fi
157
  if [ -d /sys/firmware/efi ]; then
158
    sed "s/^/$submenu_indentation/" << EOF
159
	${linuxefi} ${rel_dirname}/${basename} root=${linux_root_device_thisversion} ro ${args}
160
EOF
161
  else
162
    sed "s/^/$submenu_indentation/" << EOF
163
	linux${sixteenbit} ${rel_dirname}/${basename} root=${linux_root_device_thisversion} ro ${args}
164
EOF
165
  fi
166
  if test -n "${initrd}" ; then
167
    if [ -d /sys/firmware/efi ]; then
168
      sed "s/^/$submenu_indentation/" << EOF
169
	${initrdefi} ${rel_dirname}/${initrd}
170
EOF
171
    else
172
      sed "s/^/$submenu_indentation/" << EOF
173
	initrd${sixteenbit} ${rel_dirname}/${initrd}
174
EOF
175
    fi
176
  fi
177
  if test -n "${fdt}" ; then
178
    sed "s/^/$submenu_indentation/" << EOF
179
	devicetree	${rel_dirname}/${fdt}
180
EOF
181
  fi
182
  sed "s/^/$submenu_indentation/" << EOF
183
}
184
EOF
185
}
186
 
187
machine=`uname -m`
188
case "x$machine" in
189
    xi?86 | xx86_64)
190
	list=
191
	for i in /boot/vmlinuz-* /vmlinuz-* /boot/kernel-* ; do
192
	    if grub_file_is_not_garbage "$i" ; then list="$list $i" ; fi
193
	done ;;
194
    *) 
195
	list=
196
	for i in /boot/vmlinuz-* /boot/vmlinux-* /vmlinuz-* /vmlinux-* /boot/kernel-* ; do
197
                  if grub_file_is_not_garbage "$i" ; then list="$list $i" ; fi
198
	done ;;
199
esac
200
 
201
case "$machine" in
202
    i?86) GENKERNEL_ARCH="x86" ;;
203
    mips|mips64) GENKERNEL_ARCH="mips" ;;
204
    mipsel|mips64el) GENKERNEL_ARCH="mipsel" ;;
205
    arm*) GENKERNEL_ARCH="arm" ;;
206
    *) GENKERNEL_ARCH="$machine" ;;
207
esac
208
 
209
prepare_boot_cache=
210
prepare_root_cache=
211
boot_device_id=
212
title_correction_code=
213
 
214
# Extra indentation to add to menu entries in a submenu. We're not in a submenu
215
# yet, so it's empty. In a submenu it will be equal to '\t' (one tab).
216
submenu_indentation=""
217
 
218
is_top_level=true
219
while [ "x$list" != "x" ] ; do
220
  linux=`version_find_latest $list`
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
  fdt=
245
  for i in "dtb-${version}" "dtb-${alt_version}"; do
246
    if test -f "${dirname}/${i}/${GRUB_DEFAULT_DTB}" ; then
247
      fdt="${i}/${GRUB_DEFAULT_DTB}"
248
      break
249
    fi
250
  done
251
 
252
  config=
253
  for i in "${dirname}/config-${version}" "${dirname}/config-${alt_version}" "/etc/kernels/kernel-config-${version}" ; do
254
    if test -e "${i}" ; then
255
      config="${i}"
256
      break
257
    fi
258
  done
259
 
260
  initramfs=
261
  if test -n "${config}" ; then
262
      initramfs=`grep CONFIG_INITRAMFS_SOURCE= "${config}" | cut -f2 -d= | tr -d \"`
263
  fi
264
 
265
  if test -n "${initrd}" ; then
266
    gettext_printf "Found initrd image: %s\n" "${dirname}/${initrd}" >&2
267
  elif test -z "${initramfs}" ; then
268
    # "UUID=" and "ZFS=" magic is parsed by initrd or initramfs.  Since there's
269
    # no initrd or builtin initramfs, it can't work here.
270
    linux_root_device_thisversion=${GRUB_DEVICE}
271
  fi
272
 
273
  if [ "x${GRUB_DISABLE_SUBMENU}" = "xyes" ] || [ "x${GRUB_DISABLE_SUBMENU}" = "xy" ]; then
274
    GRUB_DISABLE_SUBMENU="true"
275
  fi
276
 
277
  if [ "x$is_top_level" = xtrue ] && [ "x${GRUB_DISABLE_SUBMENU}" != xtrue ]; then
278
    linux_entry "${OS}" "${version}" simple \
279
    "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}"
280
 
281
    submenu_indentation="$grub_tab"
282
 
283
    if [ -z "$boot_device_id" ]; then
284
	boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")"
285
    fi
286
    # TRANSLATORS: %s is replaced with an OS name
287
    echo "submenu '$(gettext_printf "Advanced options for %s" "${OS}" | grub_quote)' \$menuentry_id_option 'gnulinux-advanced-$boot_device_id' {"
288
    is_top_level=false
289
  fi
290
 
291
  linux_entry "${OS}" "${version}" advanced \
292
              "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}"
293
  if [ "x${GRUB_DISABLE_RECOVERY}" != "xtrue" ]; then
294
    linux_entry "${OS}" "${version}" recovery \
295
                "failsafe ${GRUB_CMDLINE_LINUX}"
296
  fi
297
 
298
  list=`echo $list | tr ' ' '\n' | fgrep -vx "$linux" | tr '\n' ' '`
299
done
300
 
301
# If at least one kernel was found, then we need to
302
# add a closing '}' for the submenu command.
303
if [ x"$is_top_level" != xtrue ]; then
304
  echo '}'
305
fi
306
 
307
echo "$title_correction_code"