Add grub-mkconfig support for NetBSD.

This commit is contained in:
Grégoire Sutre 2010-04-19 21:25:41 +02:00
parent bc4a2d832b
commit 0d2c20c6f1
5 changed files with 106 additions and 1 deletions

View file

@ -1,3 +1,12 @@
2010-04-19 Grégoire Sutre <gregoire.sutre@gmail.com>
Add grub-mkconfig support for NetBSD.
* util/grub.d/10_netbsd.in: grub-mkconfig helper script for NetBSD.
* util/grub-mkconfig.in: export new NetBSD specific variables.
* po/POTFILES-shell: added 10_netbsd.in.
* util/grub-mkconfig_lib.in: check for gettext binary, default to echo.
2010-04-19 BVK Chaitanya <bvk.groups@gmail.com>
Fix emu build with grub-emu-pci and grub-emu-modules.

View file

@ -2,3 +2,4 @@
# Shell language are included here.
util/grub.d/10_kfreebsd.in
util/grub.d/10_linux.in
util/grub.d/10_netbsd.in

View file

@ -239,11 +239,14 @@ export GRUB_DEFAULT \
GRUB_DISTRIBUTOR \
GRUB_CMDLINE_LINUX \
GRUB_CMDLINE_LINUX_DEFAULT \
GRUB_CMDLINE_NETBSD \
GRUB_CMDLINE_NETBSD_DEFAULT \
GRUB_TERMINAL_INPUT \
GRUB_TERMINAL_OUTPUT \
GRUB_SERIAL_COMMAND \
GRUB_DISABLE_LINUX_UUID \
GRUB_DISABLE_LINUX_RECOVERY \
GRUB_DISABLE_NETBSD_RECOVERY \
GRUB_GFXMODE \
GRUB_BACKGROUND \
GRUB_THEME \

View file

@ -31,6 +31,12 @@ if test "x$grub_mkrelpath" = x; then
grub_mkrelpath=${bindir}/`echo grub-mkrelpath | sed ${transform}`
fi
if $(which gettext >/dev/null 2>/dev/null) ; then
gettext="gettext"
else
gettext="echo"
fi
grub_warn ()
{
echo "Warning: $@" >&2
@ -190,5 +196,5 @@ version_find_latest ()
}
gettext_quoted () {
gettext "$@" | sed "s/'/'\\\\''/g"
$gettext "$@" | sed "s/'/'\\\\''/g"
}

86
util/grub.d/10_netbsd.in Normal file
View file

@ -0,0 +1,86 @@
#! /bin/sh -e
# grub-mkconfig helper script.
# Copyright (C) 2006,2007,2008,2009,2010 Free Software Foundation, Inc.
#
# GRUB is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# GRUB is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GRUB. If not, see <http://www.gnu.org/licenses/>.
prefix=@prefix@
exec_prefix=@exec_prefix@
bindir=@bindir@
libdir=@libdir@
. ${libdir}/grub/grub-mkconfig_lib
export TEXTDOMAIN=@PACKAGE@
export TEXTDOMAINDIR=@localedir@
if [ "x${GRUB_DISTRIBUTOR}" = "x" ] ; then
OS=NetBSD
else
OS="${GRUB_DISTRIBUTOR} NetBSD"
fi
netbsd_entry ()
{
loader="$1" # "knetbsd" or "multiboot"
kernel="$2" # absolute path to the kernel file
recovery="$3" # is this is a recovery entry?
args="$4" # extra arguments appended to loader command
kroot_device="$(echo ${GRUB_DEVICE} | sed -e 's,^/dev/r,,')"
if ${recovery} ; then
title="$(gettext_quoted "%s, with kernel %s (via %s, recovery mode)")"
else
title="$(gettext_quoted "%s, with kernel %s (via %s)")"
fi
printf "menuentry \"${title}\" {\n" \
"${OS}" "$(echo ${kernel} | sed -e 's,^.*/,,')" "${loader}"
printf "%s\n" "${prepare_boot_cache}"
case "${loader}" in
knetbsd)
printf "\tknetbsd %s -r %s %s\n" \
"${kernel}" "${kroot_device}" "${GRUB_CMDLINE_NETBSD} ${args}"
;;
multiboot)
printf "\tmultiboot %s %s root=%s %s\n" \
"${kernel}" "${kernel}" "${kroot_device}" "${GRUB_CMDLINE_NETBSD} ${args}"
;;
esac
printf "}\n"
}
prepare_boot_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE} | sed -e 's,^, ,')"
# We look for NetBSD kernels in / but not in subdirectories. We simply
# pick all statically linked ELF executable files (or links) in / with a
# name that starts with `netbsd'.
pattern="^ELF[^,]*executable.*statically linked"
for k in $(ls -t /netbsd*) ; do
if ! grub_file_is_not_garbage "$k" ; then
continue
fi
if ! ((file -bL "$k" | grep -q "${pattern}") ||
(zcat "$k" | file -bL - | grep -q "${pattern}")) 2>/dev/null ; then
continue
fi
echo "Found NetBSD kernel: $k" >&2
netbsd_entry "knetbsd" "$k" false "${GRUB_CMDLINE_NETBSD_DEFAULT}"
netbsd_entry "multiboot" "$k" false "${GRUB_CMDLINE_NETBSD_DEFAULT}"
if [ "x${GRUB_DISABLE_NETBSD_RECOVERY}" != "xtrue" ]; then
netbsd_entry "knetbsd" "$k" true "-s"
netbsd_entry "multiboot" "$k" true "-s"
fi
done