]> git.proxmox.com Git - grub2.git/blob - util/grub.d/10_kfreebsd.in
Import grub2_2.02+dfsg1.orig.tar.xz
[grub2.git] / util / grub.d / 10_kfreebsd.in
1 #! /bin/sh
2 set -e
3
4 # grub-mkconfig helper script.
5 # Copyright (C) 2006,2007,2008,2009,2010,2011 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="@prefix@"
21 exec_prefix="@exec_prefix@"
22 datarootdir="@datarootdir@"
23 . "$pkgdatadir/grub-mkconfig_lib"
24
25 export TEXTDOMAIN=@PACKAGE@
26 export TEXTDOMAINDIR="@localedir@"
27
28 CLASS="--class os"
29
30 case "${GRUB_DISTRIBUTOR}" in
31 Debian)
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}"
34 ;;
35 *)
36 OS="FreeBSD"
37 CLASS="--class freebsd --class bsd ${CLASS}"
38 ;;
39 esac
40
41 load_kfreebsd_module ()
42 {
43 mod="$1"
44 allow_fail="$2"
45
46 if ! test -e "${module_dir}/${mod}.ko" ; then
47 if [ "${allow_fail}" = "true" ] ; then
48 # Return silently
49 return
50 else
51 # Print an error and fail.
52 ls "${module_dir}/${mod}.ko" > /dev/null
53 fi
54 fi
55
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)"
58 fi
59
60 printf '%s\n' "${prepare_module_dir_cache}"
61 cat << EOF
62 kfreebsd_module_elf ${module_dir_rel}/${mod}.ko
63 EOF
64 }
65
66 title_correction_code=
67
68 kfreebsd_entry ()
69 {
70 os="$1"
71 version="$2"
72 type="$3"
73 args="$4"
74 if [ -z "$boot_device_id" ]; then
75 boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")"
76 fi
77 if [ x$type != xsimple ] ; then
78 if [ x$type = xrecovery ] ; then
79 title="$(gettext_printf "%s, with kFreeBSD %s (recovery mode)" "${os}" "${version}")"
80 else
81 title="$(gettext_printf "%s, with kFreeBSD %s" "${os}" "${version}")"
82 fi
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")"
88 fi
89 echo "menuentry '$(echo "$title" | grub_quote)' ${CLASS} \$menuentry_id_option 'kfreebsd-$version-$type-$boot_device_id' {" | sed "s/^/$submenu_indentation/"
90 else
91 echo "menuentry '$(echo "$OS" | grub_quote)' ${CLASS} \$menuentry_id_option 'kfreebsd-simple-$boot_device_id' {" | sed "s/^/$submenu_indentation/"
92 fi
93 if [ x$type != xrecovery ] ; then
94 save_default_entry | grub_add_tab | sed "s/^/$submenu_indentation/"
95 fi
96 if [ -z "${prepare_boot_cache}" ]; then
97 prepare_boot_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | grub_add_tab)"
98 fi
99
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}
105 EOF
106
107 if test -n "${devices}" ; then
108 sed "s/^/$submenu_indentation/" << EOF
109 kfreebsd_loadenv ${devices_rel_dirname}/${devices_basename}
110 EOF
111 fi
112
113 load_kfreebsd_module acpi true
114
115 for abstraction in dummy $(${grub_probe} -t abstraction --device ${GRUB_DEVICE}) ; do
116 case $abstraction in
117 lvm) load_kfreebsd_module geom_linux_lvm false ;;
118 esac
119 done
120
121 case "${kfreebsd_fs}" in
122 zfs)
123 load_kfreebsd_module opensolaris false
124
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
129 EOF
130 ;;
131 esac
132
133 if [ x${kfreebsd_fs} = xufs ]; then
134 load_kfreebsd_module ${kfreebsd_fs} true | sed "s/^/$submenu_indentation/"
135 else
136 load_kfreebsd_module ${kfreebsd_fs} false | sed "s/^/$submenu_indentation/"
137 fi
138
139 sed "s/^/$submenu_indentation/" << EOF
140 set kFreeBSD.vfs.root.mountfrom=${kfreebsd_fs}:${kfreebsd_device}
141 set kFreeBSD.vfs.root.mountfrom.options=rw
142 }
143 EOF
144 }
145
146 list=
147 for i in /boot/kfreebsd-* /boot/kernel/kernel ; do
148 if grub_file_is_not_garbage "$i" ; then
149 list="$list $i"
150 fi
151 done
152 prepare_boot_cache=
153 boot_device_id=
154 title_correction_code=
155
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=""
159
160 is_top_level=true
161
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`
168
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`
174 fi
175
176 case ${GRUB_FS} in
177 ufs1 | ufs2) kfreebsd_fs=ufs ;;
178 ext2) kfreebsd_fs=ext2fs ;;
179 *) kfreebsd_fs=${GRUB_FS} ;;
180 esac
181
182 case ${GRUB_FS} in
183 zfs)
184 # zpool name
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,/*@$,,")"
188 ;;
189 *)
190 kfreebsd_device=${kfreebsd_fs}id/${GRUB_DEVICE_UUID}
191 # Debian GNU/kFreeBSD can't remount root if it's supplied as UUID but
192 # as an UUID
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}
197 fi
198 ;;
199 esac
200
201 version=`echo $basename | sed -e "s,^[^0-9]*-,,g;s/\.gz$//g"`
202 alt_version=`echo $version | sed -e "s,\.old$,,g"`
203
204 module_dir=
205 for i in "/lib/modules/${version}" "/lib/modules/${alt_version}" \
206 "/boot/kernel"; do
207 if test -e "$i" ; then
208 module_dir="$i"
209 break
210 fi
211 done
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)
215 fi
216
217 if [ "x$is_top_level" = xtrue ] && [ "x${GRUB_DISABLE_SUBMENU}" != xy ]; then
218 kfreebsd_entry "${OS}" "${version}" simple
219 submenu_indentation="$grub_tab"
220
221 if [ -z "$boot_device_id" ]; then
222 boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")"
223 fi
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' {"
226 is_top_level=false
227 fi
228
229 kfreebsd_entry "${OS}" "${version}" advanced
230 if [ "x${GRUB_DISABLE_RECOVERY}" != "xtrue" ]; then
231 kfreebsd_entry "${OS}" "${version}" recovery "-s"
232 fi
233
234 list=`echo $list | tr ' ' '\n' | fgrep -vx "$kfreebsd" | tr '\n' ' '`
235 done
236
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
240 echo '}'
241 fi
242
243 echo "$title_correction_code"
244