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 .
"$pkgdatadir/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|LC_ALL=C sed 's,[^[:alnum:]_],_,g') --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}") | grub_add_tab)"
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 | grub_add_tab | sed "s/^/$submenu_indentation/"
96 if [ -z "${prepare_boot_cache}" ]; then
97 prepare_boot_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | grub_add_tab)"
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
103 echo '$
(echo "$message" | grub_quote
)'
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 "/boot/zfs/zpool.cache" > /dev/null
126 printf '%s
\n' "${prepare_boot_cache}"
127 sed "s/^/$submenu_indentation/" << EOF
128 kfreebsd_module $(make_system_path_relative_to_its_root /boot)/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
147 for i in /boot/kfreebsd-* /boot/kernel/kernel ; do
148 if grub_file_is_not_garbage "$i" ; then
154 title_correction_code=
156 # Extra indentation to add to menu entries in a submenu. We're not
in a submenu
157 # yet, so it's empty. In a submenu it will be equal to '\t' (one tab).
158 submenu_indentation
=""
162 while [ "x$list" != "x" ] ; do
163 kfreebsd
=`version_find_latest $list`
164 gettext_printf
"Found kernel of FreeBSD: %s\n" "$kfreebsd" >&2
165 basename=`basename $kfreebsd`
166 dirname=`dirname $kfreebsd`
167 rel_dirname
=`make_system_path_relative_to_its_root $dirname`
169 if [ -f /boot
/device.hints
] ; then
170 devices
=/boot
/device.hints
171 devices_basename
=`basename $devices`
172 devices_dirname
=`dirname $devices`
173 devices_rel_dirname
=`make_system_path_relative_to_its_root $devices_dirname`
177 ufs1 | ufs2
) kfreebsd_fs
=ufs
;;
178 ext2
) kfreebsd_fs
=ext2fs
;;
179 *) kfreebsd_fs
=${GRUB_FS} ;;
185 kfreebsd_device
=$
(${grub_probe} -t fs_label
--device ${GRUB_DEVICE})
186 # filesystem name (empty string for the main filesystem)
187 kfreebsd_device
="${kfreebsd_device}$(${grub_mkrelpath} / | sed -e "s
,/*@$
,,")"
190 kfreebsd_device
=${kfreebsd_fs}id
/${GRUB_DEVICE_UUID}
191 # Debian GNU/kFreeBSD can't remount root if it's supplied as UUID but
193 if [ "x${GRUB_DISTRIBUTOR}" = "xDebian" ] \
194 && ! (cat /etc
/fstab |
awk '!/^[[:space:]]*#/ && $2=="/" { print $1; }' \
195 |
grep "${kfreebsd_fs}id/${GRUB_DEVICE_UUID}" > /dev
/null
); then
196 kfreebsd_device
=${GRUB_DEVICE}
201 version
=`echo $basename | sed -e "s,^[^0-9]*-,,g;s/\.gz$//g"`
202 alt_version
=`echo $version | sed -e "s,\.old$,,g"`
205 for i
in "/lib/modules/${version}" "/lib/modules/${alt_version}" \
207 if test -e "$i" ; then
212 if test -n "${module_dir}" ; then
213 gettext_printf
"Found kernel module directory: %s\n" "${module_dir}" >&2
214 module_dir_rel
=$
(make_system_path_relative_to_its_root
$module_dir)
217 if [ "x$is_top_level" = xtrue
] && [ "x${GRUB_DISABLE_SUBMENU}" != xy
]; then
218 kfreebsd_entry
"${OS}" "${version}" simple
219 submenu_indentation
="$grub_tab"
221 if [ -z "$boot_device_id" ]; then
222 boot_device_id
="$(grub_get_device_id "${GRUB_DEVICE}")"
224 # TRANSLATORS: %s is replaced with an OS name
225 echo "submenu '$(gettext_printf "Advanced options
for %s
" "${OS}" | grub_quote)' \$menuentry_id_option 'kfreebsd-advanced-$boot_device_id' {"
229 kfreebsd_entry
"${OS}" "${version}" advanced
230 if [ "x${GRUB_DISABLE_RECOVERY}" != "xtrue" ]; then
231 kfreebsd_entry
"${OS}" "${version}" recovery
"-s"
234 list
=`echo $list | tr ' ' '\n' | fgrep -vx "$kfreebsd" | tr '\n' ' '`
237 # If at least one kernel was found, then we need to
238 # add a closing '}' for the submenu command.
239 if [ x
"$is_top_level" != xtrue
]; then
243 echo "$title_correction_code"