4 # grub-mkconfig helper script.
5 # Copyright (C) 2006,2007,2008,2009,2010,2011 Free Software Foundation, Inc.
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.
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.
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/>.
21 exec_prefix
="@exec_prefix@"
22 datarootdir
="@datarootdir@"
23 .
"@datadir@/@PACKAGE@/grub-mkconfig_lib"
25 export TEXTDOMAIN
=@PACKAGE@
26 export TEXTDOMAINDIR
="@localedir@"
30 case "${GRUB_DISTRIBUTOR}" in
32 OS
="${GRUB_DISTRIBUTOR} GNU/kFreeBSD"
33 CLASS
="--class $(echo ${GRUB_DISTRIBUTOR} | tr 'A-Z' 'a-z' | cut -d' ' -f1) --class gnu-kfreebsd --class gnu ${CLASS}"
37 CLASS
="--class freebsd --class bsd ${CLASS}"
41 load_kfreebsd_module
()
46 if ! test -e "${module_dir}/${mod}.ko" ; then
47 if [ "${allow_fail}" = "true" ] ; then
51 # Print an error and fail.
52 ls "${module_dir}/${mod}.ko" > /dev
/null
56 if [ -z "${prepare_module_dir_cache}" ]; then
57 prepare_module_dir_cache
="$(prepare_grub_to_access_device $(grub-probe -t device "${module_dir}") | sed -e "s
/^
/\t/")"
60 printf '%s\n' "${prepare_module_dir_cache}"
62 kfreebsd_module_elf ${module_dir_rel}/${mod}.ko
66 title_correction_code
=
74 if [ -z "$boot_device_id" ]; then
75 boot_device_id
="$(grub_get_device_id "${GRUB_DEVICE}")"
77 if [ x
$type != xsimple
] ; then
78 if [ x
$type = xrecovery
] ; then
79 title
="$(gettext_printf "%s
, with kFreeBSD
%s
(recovery mode
)" "${os}" "${version}")"
81 title
="$(gettext_printf "%s
, with kFreeBSD
%s
" "${os}" "${version}")"
83 replacement_title
="$(echo "Advanced options
for ${OS}" | sed 's,>,>>,g')>$(echo "$title" | sed 's,>,>>,g')"
84 if [ x
"$title" = x
"$GRUB_ACTUAL_DEFAULT" ]; then
85 quoted
="$(echo "$GRUB_ACTUAL_DEFAULT" | grub_quote)"
86 title_correction_code
="${title_correction_code}if [ \"x\$default\" = '$quoted' ]; then default='$(echo "$replacement_title" | grub_quote)'; fi;"
87 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" "kfreebsd-advanced-$boot_device_id>kfreebsd-$version-$type-$boot_device_id")"
89 echo "menuentry '$
(echo "$title" | grub_quote
)' ${CLASS} \$menuentry_id_option 'kfreebsd-
$version-$type-$boot_device_id' {" | sed "s/^/$submenu_indentation/"
91 echo "menuentry '$
(echo "$OS" | grub_quote
)' ${CLASS} \$menuentry_id_option 'kfreebsd-simple-
$boot_device_id' {" | sed "s/^/$submenu_indentation/"
93 if [ x$type != xrecovery ] ; then
94 save_default_entry | sed -e "s/^/\t/" | sed "s/^/$submenu_indentation/"
96 if [ -z "${prepare_boot_cache}" ]; then
97 prepare_boot_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | sed -e "s/^/\t/")"
100 printf '%s
\n' "${prepare_boot_cache}" | sed "s/^/$submenu_indentation/"
101 message="$(gettext_printf "Loading kernel of FreeBSD %s ..." ${version})"
102 sed "s/^/$submenu_indentation/" << EOF
104 kfreebsd ${rel_dirname}/${basename} ${args}
107 if test -n "${devices}" ; then
108 sed "s/^/$submenu_indentation/" << EOF
109 kfreebsd_loadenv ${devices_rel_dirname}/${devices_basename}
113 load_kfreebsd_module acpi true
115 for abstraction in dummy $(grub-probe -t abstraction --device ${GRUB_DEVICE}) ; do
117 lvm) load_kfreebsd_module geom_linux_lvm false ;;
121 case "${kfreebsd_fs}" in
123 load_kfreebsd_module opensolaris false
125 ls "${dirname}/zfs/zpool.cache" > /dev/null
126 printf '%s
\n' "${prepare_boot_cache}"
127 sed "s/^/$submenu_indentation/" << EOF
128 kfreebsd_module ${rel_dirname}/zfs/zpool.cache type=/boot/zfs/zpool.cache
133 if [ x${kfreebsd_fs} = xufs ]; then
134 load_kfreebsd_module ${kfreebsd_fs} true | sed "s/^/$submenu_indentation/"
136 load_kfreebsd_module ${kfreebsd_fs} false | sed "s/^/$submenu_indentation/"
139 sed "s/^/$submenu_indentation/" << EOF
140 set kFreeBSD.vfs.root.mountfrom=${kfreebsd_fs}:${kfreebsd_device}
141 set kFreeBSD.vfs.root.mountfrom.options=rw
146 list=`for i in /boot/kfreebsd-* /boot/kernel/kernel ; do
147 if grub_file_is_not_garbage "$i" ; then echo -n "$i " ; fi
151 title_correction_code=
153 # Extra indentation to add to menu entries in a submenu. We're not
in a submenu
154 # yet, so it's empty. In a submenu it will be equal to '\t' (one tab).
155 submenu_indentation
=""
159 while [ "x$list" != "x" ] ; do
160 kfreebsd
=`version_find_latest $list`
161 gettext_printf
"Found kernel of FreeBSD: %s\n" "$kfreebsd" >&2
162 basename=`basename $kfreebsd`
163 dirname=`dirname $kfreebsd`
164 rel_dirname
=`make_system_path_relative_to_its_root $dirname`
166 if [ -f /boot
/device.hints
] ; then
167 devices
=/boot
/device.hints
168 devices_basename
=`basename $devices`
169 devices_dirname
=`dirname $devices`
170 devices_rel_dirname
=`make_system_path_relative_to_its_root $devices_dirname`
174 ufs1 | ufs2
) kfreebsd_fs
=ufs
;;
175 ext2
) kfreebsd_fs
=ext2fs
;;
176 *) kfreebsd_fs
=${GRUB_FS} ;;
182 kfreebsd_device
=$
(grub-probe
-t fs_label
--device ${GRUB_DEVICE})
183 # filesystem name (empty string for the main filesystem)
184 kfreebsd_device
="${kfreebsd_device}$(${grub_mkrelpath} / | sed -e "s
,/*@$
,,")"
187 kfreebsd_device
=${kfreebsd_fs}id
/${GRUB_DEVICE_UUID}
188 # Debian GNU/kFreeBSD can't remount root if it's supplied as UUID but
190 if [ "x${GRUB_DISTRIBUTOR}" = "xDebian" ] \
191 && ! (cat /etc
/fstab |
awk '!/^[[:space:]]*#/ && $2=="/" { print $1; }' \
192 |
grep "${kfreebsd_fs}id/${GRUB_DEVICE_UUID}" > /dev
/null
); then
193 kfreebsd_device
=${GRUB_DEVICE}
198 version
=`echo $basename | sed -e "s,^[^0-9]*-,,g;s/\.gz$//g"`
199 alt_version
=`echo $version | sed -e "s,\.old$,,g"`
202 for i
in "/lib/modules/${version}" "/lib/modules/${alt_version}" \
204 if test -e "$i" ; then
209 if test -n "${module_dir}" ; then
210 gettext_printf
"Found kernel module directory: %s\n" "${module_dir}" >&2
211 module_dir_rel
=$
(make_system_path_relative_to_its_root
$module_dir)
214 if [ "x$is_first_entry" = xtrue
]; then
215 kfreebsd_entry
"${OS}" "${version}" simple
216 submenu_indentation
="\t"
218 if [ -z "$boot_device_id" ]; then
219 boot_device_id
="$(grub_get_device_id "${GRUB_DEVICE}")"
221 # TRANSLATORS: %s is replaced with an OS name
222 echo "submenu '$(gettext_printf "Advanced options
for %s
" "${OS}" | grub_quote)' \$menuentry_id_option 'kfreebsd-advanced-$boot_device_id' {"
225 kfreebsd_entry
"${OS}" "${version}" advanced
226 if [ "x${GRUB_DISABLE_RECOVERY}" != "xtrue" ]; then
227 kfreebsd_entry
"${OS}" "${version}" recovery
"-s"
230 list
=`echo $list | tr ' ' '\n' | grep -vx $kfreebsd | tr '\n' ' '`
234 # If at least one kernel was found, then we need to
235 # add a closing '}' for the submenu command.
236 if [ x
"$is_first_entry" != xtrue
]; then
240 echo "$title_correction_code"