Implement grub_file tool and use it to implement generating of config
in separate root.
This commit is contained in:
parent
296f76068d
commit
ec824e0f2a
26 changed files with 1113 additions and 122 deletions
107
util/grub-file.c
Normal file
107
util/grub-file.c
Normal file
|
@ -0,0 +1,107 @@
|
|||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2010,2012,2013 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/>.
|
||||
*/
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <grub/util/misc.h>
|
||||
#include <grub/i18n.h>
|
||||
#include <grub/term.h>
|
||||
#include <grub/font.h>
|
||||
#include <grub/gfxmenu_view.h>
|
||||
#include <grub/color.h>
|
||||
#include <grub/util/install.h>
|
||||
#include <grub/command.h>
|
||||
#include <grub/env.h>
|
||||
|
||||
#define _GNU_SOURCE 1
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <argp.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "progname.h"
|
||||
|
||||
void grub_file_init (void);
|
||||
void grub_host_init (void);
|
||||
void grub_hostfs_init (void);
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
char **argv2;
|
||||
int i;
|
||||
int had_file = 0, had_separator = 0;
|
||||
grub_command_t cmd;
|
||||
grub_err_t err;
|
||||
|
||||
grub_util_host_init (&argc, &argv);
|
||||
|
||||
argv2 = xmalloc (argc * sizeof (argv));
|
||||
|
||||
if (argc == 2 && strcmp (argv[1], "--version") == 0)
|
||||
{
|
||||
printf ("%s (%s) %s\n", program_name, PACKAGE_NAME, PACKAGE_VERSION);
|
||||
}
|
||||
|
||||
for (i = 1; i < argc; i++)
|
||||
{
|
||||
if (argv[i][0] == '-' && argv[i][1] == '-'
|
||||
&& argv[i][2] == '\0' && !had_separator)
|
||||
{
|
||||
had_separator = 1;
|
||||
argv2[i - 1] = xstrdup (argv[i]);
|
||||
continue;
|
||||
}
|
||||
if (argv[i][0] == '-' && !had_separator)
|
||||
{
|
||||
argv2[i - 1] = xstrdup (argv[i]);
|
||||
continue;
|
||||
}
|
||||
if (had_file)
|
||||
grub_util_error ("multiple files specified");
|
||||
argv2[i - 1] = canonicalize_file_name (argv[i]);
|
||||
if (!argv2[i - 1])
|
||||
{
|
||||
grub_util_error (_("cannot open `%s': %s"), argv[i],
|
||||
strerror (errno));
|
||||
}
|
||||
had_file = 1;
|
||||
}
|
||||
argv2[i - 1] = NULL;
|
||||
|
||||
/* Initialize all modules. */
|
||||
grub_init_all ();
|
||||
grub_file_init ();
|
||||
grub_hostfs_init ();
|
||||
grub_host_init ();
|
||||
|
||||
grub_env_set ("root", "host");
|
||||
|
||||
cmd = grub_command_find ("file");
|
||||
if (! cmd)
|
||||
grub_util_error (_("can't find command `%s'"), "file");
|
||||
|
||||
err = (cmd->func) (cmd, argc - 1, argv2);
|
||||
if (err && err != GRUB_ERR_TEST_FAILURE)
|
||||
grub_print_error ();
|
||||
return err;
|
||||
}
|
|
@ -39,6 +39,7 @@ grub_mkconfig_dir="${sysconfdir}"/grub.d
|
|||
self=`basename $0`
|
||||
|
||||
grub_probe="${sbindir}/@grub_probe@"
|
||||
grub_file="${bindir}/@grub_file@"
|
||||
grub_editenv="${bindir}/@grub_editenv@"
|
||||
grub_script_check="${bindir}/@grub_script_check@"
|
||||
|
||||
|
@ -54,6 +55,7 @@ usage () {
|
|||
gettext "Generate a grub config file"; echo
|
||||
echo
|
||||
print_option_help "-o, --output=$(gettext FILE)" "$(gettext "output generated config to FILE [default=stdout]")"
|
||||
print_option_help "-r, --root-directory=$(gettext DIR)" "$(gettext "use DIR as root directory [default=/]")"
|
||||
print_option_help "-h, --help" "$(gettext "print this message and exit")"
|
||||
print_option_help "-v, --version" "$(gettext "print the version information and exit")"
|
||||
echo
|
||||
|
@ -71,6 +73,8 @@ argument () {
|
|||
echo $1
|
||||
}
|
||||
|
||||
GRUB_ROOT=
|
||||
|
||||
# Check the arguments.
|
||||
while test $# -gt 0
|
||||
do
|
||||
|
@ -89,6 +93,11 @@ do
|
|||
--output=*)
|
||||
grub_cfg=`echo "$option" | sed 's/--output=//'`
|
||||
;;
|
||||
-r | --root-directory)
|
||||
GRUB_ROOT=`argument $option "$@"`; shift;;
|
||||
--root-directory=*)
|
||||
GRUB_ROOT=`echo "$option" | sed 's/--output=//'`
|
||||
;;
|
||||
-*)
|
||||
gettext_printf "Unrecognized option \`%s'\n" "$option" 1>&2
|
||||
usage
|
||||
|
@ -128,19 +137,19 @@ else
|
|||
fi
|
||||
|
||||
# Device containing our userland. Typically used for root= parameter.
|
||||
GRUB_DEVICE="`${grub_probe} --target=device /`"
|
||||
GRUB_DEVICE="`${grub_probe} --target=device "$GRUB_ROOT"/`"
|
||||
GRUB_DEVICE_UUID="`${grub_probe} --device ${GRUB_DEVICE} --target=fs_uuid 2> /dev/null`" || true
|
||||
|
||||
# Device containing our /boot partition. Usually the same as GRUB_DEVICE.
|
||||
GRUB_DEVICE_BOOT="`${grub_probe} --target=device /boot`"
|
||||
GRUB_DEVICE_BOOT="`${grub_probe} --target=device "$GRUB_ROOT"/boot`"
|
||||
GRUB_DEVICE_BOOT_UUID="`${grub_probe} --device ${GRUB_DEVICE_BOOT} --target=fs_uuid 2> /dev/null`" || true
|
||||
|
||||
# Filesystem for the device containing our userland. Used for stuff like
|
||||
# choosing Hurd filesystem module.
|
||||
GRUB_FS="`${grub_probe} --device ${GRUB_DEVICE} --target=fs 2> /dev/null || echo unknown`"
|
||||
|
||||
if [ x"$GRUB_FS" = xunknown ]; then
|
||||
GRUB_FS="$(stat -f --printf=%T / || echo unknown)"
|
||||
if [ x"$GRUB_FS" = x ] || [ x"$GRUB_FS" = xunknown ]; then
|
||||
GRUB_FS="$(stat -f --printf=%T "$GRUB_ROOT"/ || echo unknown)"
|
||||
fi
|
||||
|
||||
if test -f ${sysconfdir}/default/grub ; then
|
||||
|
@ -177,6 +186,7 @@ if [ "x${GRUB_ACTUAL_DEFAULT}" = "xsaved" ] ; then GRUB_ACTUAL_DEFAULT="`"${grub
|
|||
# These are defined in this script, export them here so that user can
|
||||
# override them.
|
||||
export GRUB_DEVICE \
|
||||
GRUB_ROOT \
|
||||
GRUB_DEVICE_UUID \
|
||||
GRUB_DEVICE_BOOT \
|
||||
GRUB_DEVICE_BOOT_UUID \
|
||||
|
@ -243,18 +253,46 @@ cat << EOF
|
|||
#
|
||||
EOF
|
||||
|
||||
for i in ${grub_mkconfig_dir}/* ; do
|
||||
|
||||
for i in "${grub_mkconfig_dir}"/* ; do
|
||||
case "$i" in
|
||||
"${grub_mkconfig_dir}"/00_header \
|
||||
| "${grub_mkconfig_dir}"/30_os-prober \
|
||||
| "${grub_mkconfig_dir}"/40_custom \
|
||||
| "${grub_mkconfig_dir}"/41_custom)
|
||||
echo
|
||||
echo "### BEGIN $i ###"
|
||||
"$i"
|
||||
echo "### END $i ###"
|
||||
;;
|
||||
# emacsen backup files. FIXME: support other editors
|
||||
*~) ;;
|
||||
# emacsen autosave files. FIXME: support other editors
|
||||
*/\#*\#) ;;
|
||||
*)
|
||||
if grub_file_is_not_garbage "$i" && test -x "$i" ; then
|
||||
echo
|
||||
echo "### BEGIN $i ###"
|
||||
"$i"
|
||||
echo "### END $i ###"
|
||||
for platform in x86 i386-xen-pae x86_64-xen mips mipsel sparc64 powerpc ia64 arm; do
|
||||
GRUB_PLATFORM=$platform
|
||||
export GRUB_PLATFORM
|
||||
buf="$($i)"
|
||||
if [ x"$buf" != x ]; then
|
||||
echo
|
||||
echo "### BEGIN $i ($platform) ###"
|
||||
case x$platform in
|
||||
xx86)
|
||||
echo "if [ x\"\$grub_platform\" != xxen \\( x\"\$grub_cpu\" = xi386 -o x\"\$grub_cpu\" = xx86_64 -o x\"\$grub_platform\" = x \\) ]; then" ;;
|
||||
xi386-xen-pae)
|
||||
echo "if [ x\"\$grub_cpu-\$grub_platform\" = xi386-xen -o x\"\$grub_cpu-\$grub_platform\" = x ]; then" ;;
|
||||
xx86_64-xen)
|
||||
echo "if [ x\"\$grub_cpu-\$grub_platform\" = xx86_64-xen -o x\"\$grub_cpu-\$grub_platform\" = x ]; then" ;;
|
||||
*)
|
||||
echo "if [ x\"\$grub_cpu\" = x$platform -o x\"\$grub_platform\" = x ]; then" ;;
|
||||
esac
|
||||
echo "$buf"
|
||||
echo "fi"
|
||||
echo "### END $i ($platform) ###"
|
||||
fi
|
||||
done
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
|
|
@ -27,6 +27,9 @@ fi
|
|||
if test "x$grub_probe" = x; then
|
||||
grub_probe="${sbindir}/@grub_probe@"
|
||||
fi
|
||||
if test "x$grub_file" = x; then
|
||||
grub_file="${bindir}/@grub_file@"
|
||||
fi
|
||||
if test "x$grub_mkrelpath" = x; then
|
||||
grub_mkrelpath="${bindir}/@grub_mkrelpath@"
|
||||
fi
|
||||
|
|
|
@ -50,19 +50,9 @@
|
|||
|
||||
#if GRUB_TARGET_WORDSIZE == 64
|
||||
typedef Elf64_Rela elf_reloc_t;
|
||||
typedef Elf64_Ehdr Elf_Ehdr;
|
||||
typedef Elf64_Shdr Elf_Shdr;
|
||||
typedef Elf64_Sym Elf_Sym;
|
||||
#define ELF_R_INFO ELF64_R_INFO
|
||||
#define ELF_ST_INFO ELF64_ST_INFO
|
||||
#define GRUB_PE32_MACHINE GRUB_PE32_MACHINE_X86_64
|
||||
#else
|
||||
typedef Elf32_Rel elf_reloc_t;
|
||||
typedef Elf32_Ehdr Elf_Ehdr;
|
||||
typedef Elf32_Shdr Elf_Shdr;
|
||||
typedef Elf32_Sym Elf_Sym;
|
||||
#define ELF_R_INFO ELF32_R_INFO
|
||||
#define ELF_ST_INFO ELF32_ST_INFO
|
||||
#define GRUB_PE32_MACHINE GRUB_PE32_MACHINE_I386
|
||||
#endif
|
||||
|
||||
|
|
|
@ -152,7 +152,7 @@ if [ "x$gfxterm" = x1 ]; then
|
|||
if loadfont `make_system_path_relative_to_its_root "${GRUB_FONT}"` ; then
|
||||
EOF
|
||||
else
|
||||
for dir in "${pkgdatadir}" "`echo '/@bootdirname@/@grubdirname@' | sed "s,//*,/,g"`" /usr/share/grub ; do
|
||||
for dir in "${pkgdatadir}" "`echo "$GRUB_ROOT"'/@bootdirname@/@grubdirname@' | sed "s,//*,/,g"`" "`echo "$GRUB_ROOT"'/usr/share/grub' | sed "s,//*,/,g"`" ; do
|
||||
for basename in unicode unifont ascii; do
|
||||
path="${dir}/${basename}.pf2"
|
||||
if is_path_readable_by_grub "${path}" > /dev/null ; then
|
||||
|
|
|
@ -21,6 +21,16 @@ prefix="@prefix@"
|
|||
exec_prefix="@exec_prefix@"
|
||||
datarootdir="@datarootdir@"
|
||||
|
||||
if [ x$GRUB_PLATFORM = xx86 ]; then
|
||||
check=--is-x86-multiboot
|
||||
elif [ x$GRUB_PLATFORM = xi386-xen-pae ]; then
|
||||
check=--is-i386-xen-pae-domu
|
||||
elif [ x$GRUB_PLATFORM = xx86_64-xen ]; then
|
||||
check=--is-x86_64-xen-domu
|
||||
else
|
||||
exit 0
|
||||
fi
|
||||
|
||||
export TEXTDOMAIN=@PACKAGE@
|
||||
export TEXTDOMAINDIR="@localedir@"
|
||||
|
||||
|
@ -40,11 +50,11 @@ all_of_them=true
|
|||
|
||||
# FIXME: add l4 here?
|
||||
kernel=
|
||||
for i in /boot/gnumach* ; do
|
||||
if test -e $i ; then
|
||||
basename=`basename $i`
|
||||
dirname=`dirname $i`
|
||||
rel_dirname=`make_system_path_relative_to_its_root $dirname`
|
||||
for i in "$GRUB_ROOT"/boot/gnumach* ; do
|
||||
if test -f "$i" && "${grub_file}" $check "$i" ; then
|
||||
basename=`basename "$i"`
|
||||
dirname=`dirname "$i"`
|
||||
rel_dirname=`make_system_path_relative_to_its_root "$dirname"`
|
||||
gettext_printf "Found GNU Mach: %s" "$i" >&2
|
||||
echo >&2
|
||||
kernels="${kernels} ${rel_dirname}/${basename}"
|
||||
|
@ -58,8 +68,8 @@ case "${GRUB_FS}" in
|
|||
*) hurd_fs="${GRUB_FS}fs" ;;
|
||||
esac
|
||||
|
||||
for i in /hurd/${hurd_fs}.static /hurd/exec ; do
|
||||
if test -e "$i" ; then
|
||||
for i in "$GRUB_ROOT"/hurd/${hurd_fs}.static "$GRUB_ROOT"/hurd/exec ; do
|
||||
if test -f "$i" ; then
|
||||
gettext_printf "Found Hurd module: %s" "$i" >&2
|
||||
echo >&2
|
||||
at_least_one=true
|
||||
|
@ -73,7 +83,7 @@ if ${at_least_one} ; then : ; else
|
|||
exit 0
|
||||
fi
|
||||
|
||||
if ${all_of_them} && test -e /lib/ld.so.1 ; then : ; else
|
||||
if ${all_of_them} && test -f "$GRUB_ROOT"/lib/ld.so.1 ; then : ; else
|
||||
gettext "Some Hurd stuff found, but not enough to boot." >&2
|
||||
echo >&2
|
||||
exit 1
|
||||
|
|
|
@ -27,6 +27,21 @@ export TEXTDOMAINDIR="@localedir@"
|
|||
|
||||
CLASS="--class os"
|
||||
|
||||
if [ x$GRUB_PLATFORM = xx86 ]; then
|
||||
check=--is-x86-multiboot
|
||||
elif [ x$GRUB_PLATFORM = xi386-xen-pae ]; then
|
||||
check=--is-i386-xen-pae-domu
|
||||
elif [ x$GRUB_PLATFORM = xx86_64-xen ]; then
|
||||
check=--is-x86_64-xen-domu
|
||||
else
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if ! test -f "$GRUB_ROOT"/platform/i86pc/kernel || ! "${grub_file}" $check "$GRUB_ROOT"/platform/i86pc/kernel; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
|
||||
case "${GRUB_DISTRIBUTOR}" in
|
||||
*)
|
||||
OS="Illumos"
|
||||
|
@ -45,7 +60,7 @@ message="$(gettext_printf "Loading kernel of Illumos ...")"
|
|||
else
|
||||
ISADIR=
|
||||
fi
|
||||
zfs-bootfs $($grub_mkrelpath /) ZFS_BOOTFS
|
||||
zfs-bootfs $($grub_mkrelpath "$GRUB_ROOT"/) ZFS_BOOTFS
|
||||
echo '$(echo "$message" | grub_quote)'
|
||||
multiboot $($grub_mkrelpath /platform/i86pc/kernel)/\$ISADIR/unix /platform/i86pc/kernel/\$ISADIR/unix -B \$ZFS_BOOTFS,console=text
|
||||
module $($grub_mkrelpath /platform/i86pc)/\$ISADIR/boot_archive /platform/i86pc/\$ISADIR/boot_archive
|
||||
|
|
|
@ -27,6 +27,16 @@ export TEXTDOMAINDIR="@localedir@"
|
|||
|
||||
CLASS="--class os"
|
||||
|
||||
if [ x$GRUB_PLATFORM = xx86 ]; then
|
||||
check=--is-x86-kfreebsd
|
||||
elif [ x$GRUB_PLATFORM = xi386-xen-pae ]; then
|
||||
check=--is-i386-xen-pae-domu
|
||||
elif [ x$GRUB_PLATFORM = xx86_64-xen ]; then
|
||||
check=--is-x86_64-xen-domu
|
||||
else
|
||||
exit 0
|
||||
fi
|
||||
|
||||
case "${GRUB_DISTRIBUTOR}" in
|
||||
Debian)
|
||||
OS="${GRUB_DISTRIBUTOR} GNU/kFreeBSD"
|
||||
|
@ -122,10 +132,10 @@ EOF
|
|||
zfs)
|
||||
load_kfreebsd_module opensolaris false
|
||||
|
||||
ls "/boot/zfs/zpool.cache" > /dev/null
|
||||
ls "$GRUB_ROOT/boot/zfs/zpool.cache" > /dev/null
|
||||
printf '%s\n' "${prepare_boot_cache}"
|
||||
sed "s/^/$submenu_indentation/" << EOF
|
||||
kfreebsd_module $(make_system_path_relative_to_its_root /boot)/zfs/zpool.cache type=/boot/zfs/zpool.cache
|
||||
kfreebsd_module $(make_system_path_relative_to_its_root $GRUB_ROOT/boot)/zfs/zpool.cache type=/boot/zfs/zpool.cache
|
||||
EOF
|
||||
;;
|
||||
esac
|
||||
|
@ -143,8 +153,8 @@ EOF
|
|||
EOF
|
||||
}
|
||||
|
||||
list=`for i in /boot/kfreebsd-* /boot/kernel/kernel ; do
|
||||
if grub_file_is_not_garbage "$i" ; then echo -n "$i " ; fi
|
||||
list=`for i in $GRUB_ROOT/boot/kfreebsd-* $GRUB_ROOT/boot/kernel/kernel ; do
|
||||
if grub_file_is_not_garbage "$i" && ${grub_file} $check "$i"; then echo -n "$i " ; fi
|
||||
done`
|
||||
prepare_boot_cache=
|
||||
boot_device_id=
|
||||
|
@ -163,8 +173,8 @@ while [ "x$list" != "x" ] ; do
|
|||
dirname=`dirname $kfreebsd`
|
||||
rel_dirname=`make_system_path_relative_to_its_root $dirname`
|
||||
|
||||
if [ -f /boot/device.hints ] ; then
|
||||
devices=/boot/device.hints
|
||||
if [ -f "$GRUB_ROOT"/boot/device.hints ] ; then
|
||||
devices="$GRUB_ROOT"/boot/device.hints
|
||||
devices_basename=`basename $devices`
|
||||
devices_dirname=`dirname $devices`
|
||||
devices_rel_dirname=`make_system_path_relative_to_its_root $devices_dirname`
|
||||
|
@ -181,14 +191,14 @@ while [ "x$list" != "x" ] ; do
|
|||
# zpool name
|
||||
kfreebsd_device=$(${grub_probe} -t fs_label --device ${GRUB_DEVICE})
|
||||
# filesystem name (empty string for the main filesystem)
|
||||
kfreebsd_device="${kfreebsd_device}$(${grub_mkrelpath} / | sed -e "s,/*@$,,")"
|
||||
kfreebsd_device="${kfreebsd_device}$(${grub_mkrelpath} "$GRUB_ROOT"/ | sed -e "s,/*@$,,")"
|
||||
;;
|
||||
*)
|
||||
kfreebsd_device=${kfreebsd_fs}id/${GRUB_DEVICE_UUID}
|
||||
# Debian GNU/kFreeBSD can't remount root if it's supplied as UUID but
|
||||
# as an UUID
|
||||
if [ "x${GRUB_DISTRIBUTOR}" = "xDebian" ] \
|
||||
&& ! (cat /etc/fstab | awk '!/^[[:space:]]*#/ && $2=="/" { print $1; }' \
|
||||
&& ! (cat "$GRUB_ROOT"/etc/fstab | awk '!/^[[:space:]]*#/ && $2=="/" { print $1; }' \
|
||||
| grep "${kfreebsd_fs}id/${GRUB_DEVICE_UUID}" > /dev/null); then
|
||||
kfreebsd_device=${GRUB_DEVICE}
|
||||
fi
|
||||
|
@ -199,8 +209,8 @@ while [ "x$list" != "x" ] ; do
|
|||
alt_version=`echo $version | sed -e "s,\.old$,,g"`
|
||||
|
||||
module_dir=
|
||||
for i in "/lib/modules/${version}" "/lib/modules/${alt_version}" \
|
||||
"/boot/kernel"; do
|
||||
for i in "$GRUB_ROOT/lib/modules/${version}" "$GRUB_ROOT/lib/modules/${alt_version}" \
|
||||
"$GRUB_ROOT/boot/kernel"; do
|
||||
if test -e "$i" ; then
|
||||
module_dir="$i"
|
||||
break
|
||||
|
|
|
@ -26,6 +26,31 @@ datarootdir="@datarootdir@"
|
|||
export TEXTDOMAIN=@PACKAGE@
|
||||
export TEXTDOMAINDIR="@localedir@"
|
||||
|
||||
if [ x$GRUB_PLATFORM = xx86 ]; then
|
||||
check=--is-x86-linux32
|
||||
elif [ x$GRUB_PLATFORM = xi386-xen-pae ]; then
|
||||
check=--is-i386-xen-pae-domu
|
||||
elif [ x$GRUB_PLATFORM = xx86_64-xen ]; then
|
||||
check=--is-x86_64-xen-domu
|
||||
else
|
||||
check=--is-${GRUB_PLATFORM}-linux
|
||||
fi
|
||||
|
||||
case "x$GRUB_PLATFORM" in
|
||||
xx86)
|
||||
list=`for i in "$GRUB_ROOT"/boot/vmlinuz-* "$GRUB_ROOT"/vmlinuz-* "$GRUB_ROOT"/boot/kernel-* ; do
|
||||
if grub_file_is_not_garbage "$i" && "${grub_file}" $check "$i" ; then echo -n "$i " ; fi
|
||||
done` ;;
|
||||
*)
|
||||
list=`for i in "$GRUB_ROOT"/boot/vmlinuz-* "$GRUB_ROOT"/boot/vmlinux-* "$GRUB_ROOT"/vmlinuz-* "$GRUB_ROOT"/vmlinux-* "$GRUB_ROOT"/boot/kernel-* ; do
|
||||
if grub_file_is_not_garbage "$i" && "${grub_file}" $check "$i" ; then echo -n "$i " ; fi
|
||||
done` ;;
|
||||
esac
|
||||
|
||||
if [ x"$list" = x ]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
CLASS="--class gnu-linux --class gnu --class os"
|
||||
|
||||
if [ "x${GRUB_DISTRIBUTOR}" = "x" ] ; then
|
||||
|
@ -53,14 +78,14 @@ fi
|
|||
|
||||
case x"$GRUB_FS" in
|
||||
xbtrfs)
|
||||
rootsubvol="`make_system_path_relative_to_its_root /`"
|
||||
rootsubvol="`make_system_path_relative_to_its_root "$GRUB_ROOT"/`"
|
||||
rootsubvol="${rootsubvol#/}"
|
||||
if [ "x${rootsubvol}" != x ]; then
|
||||
GRUB_CMDLINE_LINUX="rootflags=subvol=${rootsubvol} ${GRUB_CMDLINE_LINUX}"
|
||||
fi;;
|
||||
xzfs)
|
||||
rpool=`${grub_probe} --device ${GRUB_DEVICE} --target=fs_label 2>/dev/null || true`
|
||||
bootfs="`make_system_path_relative_to_its_root / | sed -e "s,@$,,"`"
|
||||
bootfs="`make_system_path_relative_to_its_root "$GRUB_ROOT"/ | sed -e "s,@$,,"`"
|
||||
LINUX_ROOT_DEVICE="ZFS=${rpool}${bootfs}"
|
||||
;;
|
||||
esac
|
||||
|
@ -115,7 +140,7 @@ linux_entry ()
|
|||
|
||||
echo " insmod gzio" | sed "s/^/$submenu_indentation/"
|
||||
|
||||
if [ x$dirname = x/ ]; then
|
||||
if [ x$dirname = x"$GRUB_ROOT"/ ]; then
|
||||
if [ -z "${prepare_root_cache}" ]; then
|
||||
prepare_root_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE} | grub_add_tab)"
|
||||
fi
|
||||
|
@ -144,24 +169,12 @@ EOF
|
|||
EOF
|
||||
}
|
||||
|
||||
machine=`uname -m`
|
||||
case "x$machine" in
|
||||
xi?86 | xx86_64)
|
||||
list=`for i in /boot/vmlinuz-* /vmlinuz-* /boot/kernel-* ; do
|
||||
if grub_file_is_not_garbage "$i" ; then echo -n "$i " ; fi
|
||||
done` ;;
|
||||
*)
|
||||
list=`for i in /boot/vmlinuz-* /boot/vmlinux-* /vmlinuz-* /vmlinux-* /boot/kernel-* ; do
|
||||
if grub_file_is_not_garbage "$i" ; then echo -n "$i " ; fi
|
||||
done` ;;
|
||||
esac
|
||||
|
||||
case "$machine" in
|
||||
i?86) GENKERNEL_ARCH="x86" ;;
|
||||
case "$GRUB_PLATFORM" in
|
||||
x86 | i386-xen-pae | x86_64-xen) GENKERNEL_ARCH="x86" ;;
|
||||
mips|mips64) GENKERNEL_ARCH="mips" ;;
|
||||
mipsel|mips64el) GENKERNEL_ARCH="mipsel" ;;
|
||||
arm*) GENKERNEL_ARCH="arm" ;;
|
||||
*) GENKERNEL_ARCH="$machine" ;;
|
||||
*) GENKERNEL_ARCH="$GRUB_PLATFORM" ;;
|
||||
esac
|
||||
|
||||
prepare_boot_cache=
|
||||
|
@ -200,7 +213,7 @@ while [ "x$list" != "x" ] ; do
|
|||
done
|
||||
|
||||
config=
|
||||
for i in "${dirname}/config-${version}" "${dirname}/config-${alt_version}" "/etc/kernels/kernel-config-${version}" ; do
|
||||
for i in "${dirname}/config-${version}" "${dirname}/config-${alt_version}" "$GRUB_ROOT/etc/kernels/kernel-config-${version}" ; do
|
||||
if test -e "${i}" ; then
|
||||
config="${i}"
|
||||
break
|
||||
|
|
|
@ -22,6 +22,16 @@ exec_prefix="@exec_prefix@"
|
|||
datarootdir="@datarootdir@"
|
||||
. "@datadir@/@PACKAGE@/grub-mkconfig_lib"
|
||||
|
||||
if [ x$GRUB_PLATFORM = xx86 ]; then
|
||||
check=--is-x86-kfreebsd
|
||||
elif [ x$GRUB_PLATFORM = xi386-xen-pae ]; then
|
||||
check=--is-i386-xen-pae-domu
|
||||
elif [ x$GRUB_PLATFORM = xx86_64-xen ]; then
|
||||
check=--is-x86_64-xen-domu
|
||||
else
|
||||
exit 0
|
||||
fi
|
||||
|
||||
export TEXTDOMAIN=@PACKAGE@
|
||||
export TEXTDOMAINDIR="@localedir@"
|
||||
|
||||
|
@ -36,19 +46,13 @@ netbsd_load_fs_module ()
|
|||
loader="$1" # "knetbsd" or "multiboot"
|
||||
kernel="$2" # absolute path to the kernel file
|
||||
|
||||
case $(zcat -f "${kernel}" | file -bL - | cut -d , -f 2 | tr -d ' ') in
|
||||
Intel80386)
|
||||
karch="i386"
|
||||
;;
|
||||
x86-64)
|
||||
if "${grub_file}" --is-x86_64-kfreebsd "${kernel}"; then
|
||||
karch="amd64"
|
||||
;;
|
||||
*)
|
||||
return
|
||||
;;
|
||||
esac
|
||||
else
|
||||
karch="i386"
|
||||
fi
|
||||
|
||||
case $(${grub_probe} --target=fs -d ${GRUB_DEVICE}) in
|
||||
case $GRUB_FS in
|
||||
ext2)
|
||||
kmod="ext2fs"
|
||||
;;
|
||||
|
@ -67,7 +71,7 @@ netbsd_load_fs_module ()
|
|||
esac
|
||||
|
||||
kversion=$(zcat -f "${kernel}" | strings | sed -n -e '/^@(#)NetBSD/ { s/^@(#)NetBSD \([0-9\.]*\) .*$/\1/g ; p ; q ; }')
|
||||
kmodule="/stand/${karch}/${kversion}/modules/${kmod}/${kmod}.kmod"
|
||||
kmodule="$GRUB_ROOT/stand/${karch}/${kversion}/modules/${kmod}/${kmod}.kmod"
|
||||
|
||||
if test -z "$karch" -o -z "$kversion" -o ! -f "${kmodule}"; then
|
||||
return
|
||||
|
@ -94,6 +98,10 @@ netbsd_entry ()
|
|||
type="$3"
|
||||
args="$4" # extra arguments appended to loader command
|
||||
|
||||
if [ "x${loader}" = xmultiboot ] && [ x$GRUB_PLATFORM = xx86 ] && ! "$grub_file" --is-x86-multiboot "$kernel"; then
|
||||
return
|
||||
fi
|
||||
|
||||
kroot_device="$(echo ${GRUB_DEVICE} | sed -e 's,^/dev/r,,')"
|
||||
|
||||
if [ -z "$boot_device_id" ]; then
|
||||
|
@ -147,10 +155,13 @@ pattern="^ELF[^,]*executable.*statically linked"
|
|||
submenu_indentation=""
|
||||
|
||||
is_top_level=true
|
||||
for k in /netbsd $(ls -t /netbsd?* 2>/dev/null) ; do
|
||||
for k in "$GRUB_ROOT"/netbsd $(ls -t "$GRUB_ROOT"/netbsd?* 2>/dev/null) ; do
|
||||
if ! grub_file_is_not_garbage "$k" ; then
|
||||
continue
|
||||
fi
|
||||
if ! "$grub_file" $check "$k"; then
|
||||
continue
|
||||
fi
|
||||
if ! (zcat -f "$k" | file -bL - | grep -q "${pattern}") 2>/dev/null ; then
|
||||
continue
|
||||
fi
|
||||
|
|
|
@ -26,18 +26,28 @@ export TEXTDOMAINDIR="@localedir@"
|
|||
|
||||
. "@datadir@/@PACKAGE@/grub-mkconfig_lib"
|
||||
|
||||
if [ x$GRUB_PLATFORM != xx86 ]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
osx_entry() {
|
||||
if [ x$2 = x32 ]; then
|
||||
# TRANSLATORS: it refers to kernel architecture (32-bit)
|
||||
bitstr="$(gettext "(32-bit)")"
|
||||
if ! [ -f "$GRUB_ROOT"/mach_kernel ] || ! "${grub_file}" --is-i386-xnu "$GRUB_ROOT"/mach_kernel; then
|
||||
return;
|
||||
fi
|
||||
else
|
||||
# TRANSLATORS: it refers to kernel architecture (64-bit)
|
||||
bitstr="$(gettext "(64-bit)")"
|
||||
if ! [ -f "$GRUB_ROOT"/mach_kernel ] || ! "${grub_file}" --is-x86_64-xnu "$GRUB_ROOT"/mach_kernel; then
|
||||
return;
|
||||
fi
|
||||
fi
|
||||
# TRANSLATORS: it refers on the OS residing on device %s
|
||||
onstr="$(gettext_printf "(on %s)" "${GRUB_DEVICE}")"
|
||||
cat << EOF
|
||||
menuentry '$(echo "Darwin/Mac OS X $bitstr $onstr" | grub_quote)' --class osx --class darwin --class os \$menuentry_id_option 'osprober-xnu-$2-$(grub_get_device_id "${GRUB_DEVICE}")' {
|
||||
menuentry '$(echo "Darwin/Mac OS X $bitstr $onstr" | grub_quote)' --class osx --class darwin --class os \$menuentry_id_option 'xnu-$2-$(grub_get_device_id "${GRUB_DEVICE}")' {
|
||||
EOF
|
||||
save_default_entry | grub_add_tab
|
||||
prepare_grub_to_access_device ${GRUB_DEVICE} | grub_add_tab
|
||||
|
@ -50,7 +60,7 @@ EOF
|
|||
fi
|
||||
fi
|
||||
if [ \$do_resume = 0 ]; then
|
||||
xnu_uuid ${OSXUUID} uuid
|
||||
xnu_uuid ${GRUB_DEVICE_UUID} uuid
|
||||
if [ -f /Extra/DSDT.aml ]; then
|
||||
acpi -e /Extra/DSDT.aml
|
||||
fi
|
||||
|
@ -90,6 +100,5 @@ EOF
|
|||
EOF
|
||||
}
|
||||
|
||||
OSXUUID="`${grub_probe} --target=fs_uuid --device ${GRUB_DEVICE} 2> /dev/null`"
|
||||
osx_entry xnu_kernel 32
|
||||
osx_entry xnu_kernel64 64
|
||||
|
|
|
@ -26,6 +26,10 @@ datarootdir="@datarootdir@"
|
|||
export TEXTDOMAIN=@PACKAGE@
|
||||
export TEXTDOMAINDIR="@localedir@"
|
||||
|
||||
if [ x$GRUB_PLATFORM != xx86 ]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
CLASS="--class gnu-linux --class gnu --class os --class xen"
|
||||
|
||||
if [ "x${GRUB_DISTRIBUTOR}" = "x" ] ; then
|
||||
|
@ -61,14 +65,14 @@ fi
|
|||
|
||||
case x"$GRUB_FS" in
|
||||
xbtrfs)
|
||||
rootsubvol="`make_system_path_relative_to_its_root /`"
|
||||
rootsubvol="`make_system_path_relative_to_its_root "$GRUB_ROOT"/`"
|
||||
rootsubvol="${rootsubvol#/}"
|
||||
if [ "x${rootsubvol}" != x ]; then
|
||||
GRUB_CMDLINE_LINUX="rootflags=subvol=${rootsubvol} ${GRUB_CMDLINE_LINUX}"
|
||||
fi;;
|
||||
xzfs)
|
||||
rpool=`${grub_probe} --device ${GRUB_DEVICE} --target=fs_label 2>/dev/null || true`
|
||||
bootfs="`make_system_path_relative_to_its_root / | sed -e "s,@$,,"`"
|
||||
bootfs="`make_system_path_relative_to_its_root "$GRUB_ROOT"/ | sed -e "s,@$,,"`"
|
||||
LINUX_ROOT_DEVICE="ZFS=${rpool}${bootfs}"
|
||||
;;
|
||||
esac
|
||||
|
@ -137,19 +141,9 @@ EOF
|
|||
EOF
|
||||
}
|
||||
|
||||
linux_list=`for i in /boot/vmlinu[xz]-* /vmlinu[xz]-* /boot/kernel-*; do
|
||||
if grub_file_is_not_garbage "$i"; then
|
||||
basename=$(basename $i)
|
||||
version=$(echo $basename | sed -e "s,^[^0-9]*-,,g")
|
||||
dirname=$(dirname $i)
|
||||
config=
|
||||
for j in "${dirname}/config-${version}" "${dirname}/config-${alt_version}" "/etc/kernels/kernel-config-${version}" ; do
|
||||
if test -e "${j}" ; then
|
||||
config="${j}"
|
||||
break
|
||||
fi
|
||||
done
|
||||
if (grep -qx "CONFIG_XEN_DOM0=y" "${config}" 2> /dev/null || grep -qx "CONFIG_XEN_PRIVILEGED_GUEST=y" "${config}" 2> /dev/null); then echo -n "$i " ; fi
|
||||
linux_list=`for i in "$GRUB_ROOT"/boot/vmlinu[xz]-* "$GRUB_ROOT"/vmlinu[xz]-* "$GRUB_ROOT"/boot/kernel-*; do
|
||||
if grub_file_is_not_garbage "$i" && "${grub_file}" --is-x86-xen-dom0 "$i"; then
|
||||
echo -n "$i " ;
|
||||
fi
|
||||
done`
|
||||
if [ "x${linux_list}" = "x" ] ; then
|
||||
|
@ -165,8 +159,8 @@ file_is_not_sym () {
|
|||
esac
|
||||
}
|
||||
|
||||
xen_list=`for i in /boot/xen*; do
|
||||
if grub_file_is_not_garbage "$i" && file_is_not_sym "$i" ; then echo -n "$i " ; fi
|
||||
xen_list=`for i in "$GRUB_ROOT"/boot/xen*; do
|
||||
if grub_file_is_not_garbage "$i" && file_is_not_sym "$i" && ${grub_file} --is-x86-multiboot "$i"; then echo -n "$i " ; fi
|
||||
done`
|
||||
prepare_boot_cache=
|
||||
boot_device_id=
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue