]> git.ipfire.org Git - ipfire-2.x.git/blame - config/flash-images/grub/11_linux_scon
flash-images: Label serial console option as "serial"
[ipfire-2.x.git] / config / flash-images / grub / 11_linux_scon
CommitLineData
6b566244
AF
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="/usr"
21exec_prefix="${prefix}"
22datarootdir="${prefix}/share"
23
24. "${datarootdir}/grub/grub-mkconfig_lib"
25
26export TEXTDOMAIN=grub
27export TEXTDOMAINDIR="${datarootdir}/locale"
28
29CLASS="--class gnu-linux --class gnu --class os"
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) ${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 ;;
44esac
45
46if [ "x${GRUB_DEVICE_UUID}" = "x" ] || [ "x${GRUB_DISABLE_LINUX_UUID}" = "xtrue" ] \
47 || ! test -e "/dev/disk/by-uuid/${GRUB_DEVICE_UUID}" \
48 || uses_abstraction "${GRUB_DEVICE}" lvm; then
49 LINUX_ROOT_DEVICE=${GRUB_DEVICE}
50else
51 LINUX_ROOT_DEVICE=UUID=${GRUB_DEVICE_UUID}
52fi
53
54GRUBFS="`${grub_probe} --device ${GRUB_DEVICE} --target=fs 2>/dev/null || true`"
55
56if [ x"$GRUBFS" = x ]; then
57 GRUBFS="$(stat -f --printf=%T / || true)"
58fi
59
60case x"$GRUBFS" in
61 xbtrfs)
62 rootsubvol="`make_system_path_relative_to_its_root /`"
63 rootsubvol="${rootsubvol#/}"
64 if [ "x${rootsubvol}" != x ]; then
65 GRUB_CMDLINE_LINUX="rootflags=subvol=${rootsubvol} ${GRUB_CMDLINE_LINUX}"
66 fi;;
67 xzfs)
68 rpool=`${grub_probe} --device ${GRUB_DEVICE} --target=fs_label 2>/dev/null || true`
69 bootfs="`make_system_path_relative_to_its_root / | sed -e "s,@$,,"`"
70 LINUX_ROOT_DEVICE="ZFS=${rpool}${bootfs}"
71 ;;
72esac
73
74title_correction_code=
75
76linux_entry ()
77{
78 os="$1"
79 version="$2"
80 type="$3"
81 args="$4"
82
83 if [ -z "$boot_device_id" ]; then
84 boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")"
85 fi
86 if [ x$type != xsimple ] ; then
87 case $type in
88 recovery)
89 title="$(gettext_printf "%s, with Linux %s (recovery mode)" "${os}" "${version}")" ;;
90 *)
91 title="$(gettext_printf "%s, with Linux %s" "${os}" "${version}")" ;;
92 esac
93 if [ x"$title" = x"$GRUB_ACTUAL_DEFAULT" ] || [ x"Previous Linux versions>$title" = x"$GRUB_ACTUAL_DEFAULT" ]; then
94 replacement_title="$(echo "Advanced options for ${OS}" | sed 's,>,>>,g')>$(echo "$title" | sed 's,>,>>,g')"
95 quoted="$(echo "$GRUB_ACTUAL_DEFAULT" | grub_quote)"
96 title_correction_code="${title_correction_code}if [ \"x\$default\" = '$quoted' ]; then default='$(echo "$replacement_title" | grub_quote)'; fi;"
97 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")"
98 fi
99 echo "menuentry '$(echo "$title" | grub_quote)' ${CLASS} \$menuentry_id_option 'gnulinux-$version-$type-$boot_device_id' {" | sed "s/^/$submenu_indentation/"
100 else
101 echo "menuentry '$(echo "$os" | grub_quote)' ${CLASS} \$menuentry_id_option 'gnulinux-simple-$boot_device_id' {" | sed "s/^/$submenu_indentation/"
102 fi
103 if [ x$type != xrecovery ] ; then
104 save_default_entry | sed -e "s/^/\t/"
105 fi
106
107 # Use ELILO's generic "efifb" when it's known to be available.
108 # FIXME: We need an interface to select vesafb in case efifb can't be used.
109 if [ "x$GRUB_GFXPAYLOAD_LINUX" = x ]; then
110 echo " load_video" | sed "s/^/$submenu_indentation/"
111 if grep -qx "CONFIG_FB_EFI=y" "${config}" 2> /dev/null \
112 && grep -qx "CONFIG_VT_HW_CONSOLE_BINDING=y" "${config}" 2> /dev/null; then
113 echo " set gfxpayload=keep" | sed "s/^/$submenu_indentation/"
114 fi
115 else
116 if [ "x$GRUB_GFXPAYLOAD_LINUX" != xtext ]; then
117 echo " load_video" | sed "s/^/$submenu_indentation/"
118 fi
119 echo " set gfxpayload=$GRUB_GFXPAYLOAD_LINUX" | sed "s/^/$submenu_indentation/"
120 fi
121
122 echo " insmod gzio" | sed "s/^/$submenu_indentation/"
123
124 if [ x$dirname = x/ ]; then
125 if [ -z "${prepare_root_cache}" ]; then
126 prepare_root_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE} | sed -e "s/^/\t/")"
127 fi
128 printf '%s\n' "${prepare_root_cache}" | sed "s/^/$submenu_indentation/"
129 else
130 if [ -z "${prepare_boot_cache}" ]; then
131 prepare_boot_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | sed -e "s/^/\t/")"
132 fi
133 printf '%s\n' "${prepare_boot_cache}" | sed "s/^/$submenu_indentation/"
134 fi
135 message="$(gettext_printf "Loading Linux %s ..." ${version})"
136 sed "s/^/$submenu_indentation/" << EOF
137 echo '$message'
138 linux ${rel_dirname}/${basename} root=${linux_root_device_thisversion} ro ${args}
139EOF
140 if test -n "${initrd}" ; then
141 # TRANSLATORS: ramdisk isn't identifier. Should be translated.
142 message="$(gettext_printf "Loading initial ramdisk ...")"
143 sed "s/^/$submenu_indentation/" << EOF
144 echo '$message'
145 initrd ${rel_dirname}/${initrd}
146EOF
147 fi
148 sed "s/^/$submenu_indentation/" << EOF
149}
150EOF
151}
152
153machine=`uname -m`
154case "x$machine" in
155 xi?86 | xx86_64)
156 list=`for i in /boot/vmlinuz-* /vmlinuz-* /boot/kernel-* ; do
157 if grub_file_is_not_garbage "$i" ; then echo -n "$i " ; fi
158 done` ;;
159 *)
160 list=`for i in /boot/vmlinuz-* /boot/vmlinux-* /vmlinuz-* /vmlinux-* /boot/kernel-* ; do
161 if grub_file_is_not_garbage "$i" ; then echo -n "$i " ; fi
162 done` ;;
163esac
164
165case "$machine" in
166 i?86) GENKERNEL_ARCH="x86" ;;
167 mips|mips64) GENKERNEL_ARCH="mips" ;;
168 mipsel|mips64el) GENKERNEL_ARCH="mipsel" ;;
169 arm*) GENKERNEL_ARCH="arm" ;;
170 *) GENKERNEL_ARCH="$machine" ;;
171esac
172
173prepare_boot_cache=
174prepare_root_cache=
175boot_device_id=
176title_correction_code=
177
178# Extra indentation to add to menu entries in a submenu. We're not in a submenu
179# yet, so it's empty. In a submenu it will be equal to '\t' (one tab).
180submenu_indentation=""
181
182is_first_entry=true
183while [ "x$list" != "x" ] ; do
184 linux=`version_find_latest $list`
185 gettext_printf "Found linux image: %s\n" "$linux" >&2
186 basename=`basename $linux`
187 dirname=`dirname $linux`
188 rel_dirname=`make_system_path_relative_to_its_root $dirname`
189 version=`echo $basename | sed -e "s,^[^0-9]*-,,g"`
190 alt_version=`echo $version | sed -e "s,\.old$,,g"`
191 linux_root_device_thisversion="${LINUX_ROOT_DEVICE}"
192
193 initrd=
194 for i in "initrd.img-${version}" "initrd-${version}.img" "initrd-${version}.gz" \
195 "initrd-${version}" "initramfs-${version}.img" \
196 "initrd.img-${alt_version}" "initrd-${alt_version}.img" \
197 "initrd-${alt_version}" "initramfs-${alt_version}.img" \
198 "initramfs-genkernel-${version}" \
199 "initramfs-genkernel-${alt_version}" \
200 "initramfs-genkernel-${GENKERNEL_ARCH}-${version}" \
201 "initramfs-genkernel-${GENKERNEL_ARCH}-${alt_version}"; do
202 if test -e "${dirname}/${i}" ; then
203 initrd="$i"
204 break
205 fi
206 done
207
208 config=
209 for i in "${dirname}/config-${version}" "${dirname}/config-${alt_version}" "/etc/kernels/kernel-config-${version}" ; do
210 if test -e "${i}" ; then
211 config="${i}"
212 break
213 fi
214 done
215
216 initramfs=
217 if test -n "${config}" ; then
218 initramfs=`grep CONFIG_INITRAMFS_SOURCE= "${config}" | cut -f2 -d= | tr -d \"`
219 fi
220
221 if test -n "${initrd}" ; then
222 gettext_printf "Found initrd image: %s\n" "${dirname}/${initrd}" >&2
223 elif test -z "${initramfs}" ; then
224 # "UUID=" and "ZFS=" magic is parsed by initrd or initramfs. Since there's
225 # no initrd or builtin initramfs, it can't work here.
226 linux_root_device_thisversion=${GRUB_DEVICE}
227 fi
228
229 if [ "x$is_first_entry" = xtrue ]; then
ff1953f7 230 linux_entry "Serial Console: ${OS}" "${version}" serial \
6b566244
AF
231 "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT} console=ttyS0,115200n8"
232
233 submenu_indentation="\t"
234
235 if [ -z "$boot_device_id" ]; then
236 boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")"
237 fi
238 fi
239
240 list=`echo $list | tr ' ' '\n' | grep -vx $linux | tr '\n' ' '`
241done
242
243echo "$title_correction_code"