diff options
author | James <james.mckenzie@citrix.com> | 2012-11-16 10:41:01 +0000 |
---|---|---|
committer | James <james.mckenzie@citrix.com> | 2012-11-16 10:41:01 +0000 |
commit | 041d1ea37802bf7178a31a53f96c26efa6b8fb7b (patch) | |
tree | c193e84ad1237f25a79d0f6a267722e44c73f56a /util/grub.d | |
download | grub-1.99-041d1ea37802bf7178a31a53f96c26efa6b8fb7b.tar.gz grub-1.99-041d1ea37802bf7178a31a53f96c26efa6b8fb7b.tar.bz2 grub-1.99-041d1ea37802bf7178a31a53f96c26efa6b8fb7b.zip |
fish
Diffstat (limited to 'util/grub.d')
-rw-r--r-- | util/grub.d/00_header.in | 271 | ||||
-rw-r--r-- | util/grub.d/10_hurd.in | 127 | ||||
-rw-r--r-- | util/grub.d/10_kfreebsd.in | 192 | ||||
-rw-r--r-- | util/grub.d/10_linux.in | 199 | ||||
-rw-r--r-- | util/grub.d/10_netbsd.in | 143 | ||||
-rw-r--r-- | util/grub.d/10_windows.in | 94 | ||||
-rw-r--r-- | util/grub.d/20_linux_xen.in | 174 | ||||
-rw-r--r-- | util/grub.d/30_os-prober.in | 204 | ||||
-rw-r--r-- | util/grub.d/40_custom.in | 5 | ||||
-rw-r--r-- | util/grub.d/41_custom.in | 7 | ||||
-rw-r--r-- | util/grub.d/README | 11 |
11 files changed, 1427 insertions, 0 deletions
diff --git a/util/grub.d/00_header.in b/util/grub.d/00_header.in new file mode 100644 index 0000000..9da1511 --- /dev/null +++ b/util/grub.d/00_header.in @@ -0,0 +1,271 @@ +#! /bin/sh +set -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/>. + +transform="@program_transform_name@" + +prefix=@prefix@ +exec_prefix=@exec_prefix@ +libdir=@libdir@ +locale_dir=`echo ${GRUB_PREFIX}/locale | sed ${transform}` +grub_lang=`echo $LANG | cut -d . -f 1` + +. ${libdir}/grub/grub-mkconfig_lib + +# Do this as early as possible, since other commands might depend on it. +# (e.g. the `loadfont' command might need lvm or raid modules) +for i in ${GRUB_PRELOAD_MODULES} ; do + echo "insmod $i" +done + +if [ "x${GRUB_DEFAULT}" = "x" ] ; then GRUB_DEFAULT=0 ; fi +if [ "x${GRUB_DEFAULT}" = "xsaved" ] ; then GRUB_DEFAULT='${saved_entry}' ; fi +if [ "x${GRUB_TIMEOUT}" = "x" ] ; then GRUB_TIMEOUT=5 ; fi +if [ "x${GRUB_GFXMODE}" = "x" ] ; then GRUB_GFXMODE=640x480 ; fi + +if [ "x${GRUB_DEFAULT_BUTTON}" = "x" ] ; then GRUB_DEFAULT_BUTTON="$GRUB_DEFAULT" ; fi +if [ "x${GRUB_DEFAULT_BUTTON}" = "xsaved" ] ; then GRUB_DEFAULT_BUTTON='${saved_entry}' ; fi +if [ "x${GRUB_TIMEOUT_BUTTON}" = "x" ] ; then GRUB_TIMEOUT_BUTTON="$GRUB_TIMEOUT" ; fi + +cat << EOF +if [ -s \$prefix/grubenv ]; then + load_env +fi +EOF +if [ "x$GRUB_BUTTON_CMOS_ADDRESS" != "x" ]; then + cat <<EOF +if cmostest $GRUB_BUTTON_CMOS_ADDRESS ; then + set default="${GRUB_DEFAULT_BUTTON}" +else + set default="${GRUB_DEFAULT}" +fi +EOF +else + cat <<EOF +set default="${GRUB_DEFAULT}" +EOF +fi +cat <<EOF +if [ "\${prev_saved_entry}" ]; then + set saved_entry="\${prev_saved_entry}" + save_env saved_entry + set prev_saved_entry= + save_env prev_saved_entry + set boot_once=true +fi + +function savedefault { + if [ -z "\${boot_once}" ]; then + saved_entry="\${chosen}" + save_env saved_entry + fi +} + +function load_video { +EOF +if [ -n "${GRUB_VIDEO_BACKEND}" ]; then + cat <<EOF + insmod ${GRUB_VIDEO_BACKEND} +EOF +else + # Insert all available backends; GRUB will use the most appropriate. + have_video=0; + for backend in $(cat "${GRUB_PREFIX}/video.lst"); do + have_video=1; + cat <<EOF + insmod ${backend} +EOF + done + if [ x$have_video = x0 ]; then + echo "true" + fi +fi +cat <<EOF +} + +EOF + +serial=0; +gfxterm=0; +for x in ${GRUB_TERMINAL_INPUT} ${GRUB_TERMINAL_OUTPUT}; do + if [ xserial = "x$x" ]; then + serial=1; + fi + if [ xgfxterm = "x$x" ]; then + gfxterm=1; + fi +done + +if [ "x$serial" = x1 ]; then + if ! test -e ${GRUB_PREFIX}/serial.mod ; then + echo "Serial terminal not available on this platform." >&2 ; exit 1 + fi + + if [ "x${GRUB_SERIAL_COMMAND}" = "x" ] ; then + grub_warn "Requested serial terminal but GRUB_SERIAL_COMMAND is unspecified. Default parameters will be used." + GRUB_SERIAL_COMMAND=serial + fi + echo "${GRUB_SERIAL_COMMAND}" +fi + +if [ "x$gfxterm" = x1 ]; then + # Make the font accessible + prepare_grub_to_access_device `${grub_probe} --target=device "${GRUB_FONT_PATH}"` + + cat << EOF +if loadfont `make_system_path_relative_to_its_root "${GRUB_FONT_PATH}"` ; then + set gfxmode=${GRUB_GFXMODE} + load_video + insmod gfxterm +EOF + +# Gettext variables and module +if [ "x${LANG}" != "xC" ] && [ -d "${locale_dir}" ] ; then + prepare_grub_to_access_device $(${grub_probe} --target=device ${locale_dir}) | sed -e "s/^/ /" + cat << EOF + set locale_dir=(\$root)$(make_system_path_relative_to_its_root ${locale_dir}) + set lang=${grub_lang} + insmod gettext +EOF +fi + +cat <<EOF +fi +EOF +fi + +case x${GRUB_TERMINAL_INPUT} in + x) + # Just use the native terminal + ;; + x*) + cat << EOF +terminal_input ${GRUB_TERMINAL_INPUT} +EOF + ;; +esac + +case x${GRUB_TERMINAL_OUTPUT} in + x) + # Just use the native terminal + ;; + x*) + cat << EOF +terminal_output ${GRUB_TERMINAL_OUTPUT} +EOF + ;; +esac + +if [ "x$gfxterm" = x1 ]; then + if [ "x$GRUB_THEME" != x ] && [ -f "$GRUB_THEME" ] \ + && is_path_readable_by_grub "$GRUB_THEME"; then + echo "Found theme: $GRUB_THEME" >&2 + prepare_grub_to_access_device `${grub_probe} --target=device "$GRUB_THEME"` + cat << EOF +insmod gfxmenu +EOF + themedir="`dirname "$GRUB_THEME"`" + for x in "$themedir"/*.pf2 "$themedir"/f/*.pf2; do + if [ -f "$x" ]; then + cat << EOF +loadfont (\$root)`make_system_path_relative_to_its_root $x` +EOF + fi + done + if [ x"`echo "$themedir"/*.jpg`" != x"$themedir/*.jpg" ] || [ x"`echo "$themedir"/*.jpeg`" != x"$themedir/*.jpeg" ]; then + cat << EOF +insmod jpeg +EOF + fi + if [ x"`echo "$themedir"/*.png`" != x"$themedir/*.png" ]; then + cat << EOF +insmod png +EOF + fi + if [ x"`echo "$themedir"/*.tga`" != x"$themedir/*.tga" ]; then + cat << EOF +insmod tga +EOF + fi + + cat << EOF +set theme=(\$root)`make_system_path_relative_to_its_root $GRUB_THEME` +EOF + elif [ "x$GRUB_BACKGROUND" != x ] && [ -f "$GRUB_BACKGROUND" ] \ + && is_path_readable_by_grub "$GRUB_BACKGROUND"; then + echo "Found background: $GRUB_BACKGROUND" >&2 + case "$GRUB_BACKGROUND" in + *.png) reader=png ;; + *.tga) reader=tga ;; + *.jpg|*.jpeg) reader=jpeg ;; + *) echo "Unsupported image format" >&2; exit 1 ;; + esac + prepare_grub_to_access_device `${grub_probe} --target=device "$GRUB_BACKGROUND"` + cat << EOF +insmod $reader +background_image -m stretch `make_system_path_relative_to_its_root "$GRUB_BACKGROUND"` +EOF + fi +fi + +make_timeout () +{ + if [ "x${1}" != "x" ] ; then + if [ "x${GRUB_HIDDEN_TIMEOUT_QUIET}" = "xtrue" ] ; then + verbose= + else + verbose=" --verbose" + fi + cat << EOF +if sleep$verbose --interruptible ${1} ; then + set timeout=${2} +fi +EOF + else + cat << EOF +set timeout=${2} +EOF + fi +} + +if [ "x$GRUB_BUTTON_CMOS_ADDRESS" != "x" ]; then + cat <<EOF +if cmostest $GRUB_BUTTON_CMOS_ADDRESS ; then +EOF +make_timeout "${GRUB_HIDDEN_TIMEOUT_BUTTON}" "${GRUB_TIMEOUT_BUTTON}" +echo else +make_timeout "${GRUB_HIDDEN_TIMEOUT}" "${GRUB_TIMEOUT}" +echo fi +else +make_timeout "${GRUB_HIDDEN_TIMEOUT}" "${GRUB_TIMEOUT}" +fi + +if [ "x$GRUB_BUTTON_CMOS_ADDRESS" != "x" ] && [ "x$GRUB_BUTTON_CMOS_CLEAN" = "xyes" ]; then + cat <<EOF +cmosclean $GRUB_BUTTON_CMOS_ADDRESS +EOF +fi + +# Play an initial tune +if [ "x${GRUB_INIT_TUNE}" != "x" ] ; then + echo "play ${GRUB_INIT_TUNE}" +fi + +if [ "x${GRUB_BADRAM}" != "x" ] ; then + echo "badram ${GRUB_BADRAM}" +fi diff --git a/util/grub.d/10_hurd.in b/util/grub.d/10_hurd.in new file mode 100644 index 0000000..8c54eab --- /dev/null +++ b/util/grub.d/10_hurd.in @@ -0,0 +1,127 @@ +#! /bin/sh +set -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@ +libdir=@libdir@ +. ${libdir}/grub/grub-mkconfig_lib + +CLASS="--class gnu --class os" + +if [ "x${GRUB_DISTRIBUTOR}" = "x" ] ; then + OS=GNU +else + OS="${GRUB_DISTRIBUTOR} GNU/Hurd" + CLASS="--class $(echo ${GRUB_DISTRIBUTOR} | tr 'A-Z' 'a-z' | cut -d' ' -f1) ${CLASS}" +fi + +at_least_one=false +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` + echo "Found GNU Mach: $i" >&2 + kernels="${kernels} ${rel_dirname}/${basename}" + at_least_one=true + fi +done + +# FIXME: This works for ext2. For other filesystems we might need special-casing +case "${GRUB_FS}" in + *fs) hurd_fs="${GRUB_FS}" ;; + *) hurd_fs="${GRUB_FS}fs" ;; +esac + +for i in /hurd/${hurd_fs}.static /hurd/exec ; do + if test -e "$i" ; then + echo "Found Hurd module: $i" >&2 + at_least_one=true + else + all_of_them=false + fi +done + +if ${at_least_one} ; then : ; else + # no hurd here, aborting silently + exit 0 +fi + +if ${all_of_them} && test -e /lib/ld.so.1 ; then : ; else + echo "Some Hurd stuff found, but not enough to boot." >&2 + exit 1 +fi + +for kernel in ${kernels} +do + kernel_base="`basename "${kernel}"`" + KERNEL="using ${kernel_base}" + + cat << EOF +menuentry "${OS} ${KERNEL}" ${CLASS} { +EOF + prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | sed -e "s/^/\t/" + message="$(gettext_printf "Loading GNU Mach ...")" + cat << EOF + echo '$message' + multiboot ${kernel} root=device:${GRUB_DEVICE#/dev/} +EOF + save_default_entry | sed -e "s/^/\t/" + prepare_grub_to_access_device ${GRUB_DEVICE} | sed -e "s/^/\t/" + message="$(gettext_printf "Loading the Hurd ...")" + cat << EOF + echo '$message' + module /hurd/${hurd_fs}.static ${hurd_fs} --readonly \\ + --multiboot-command-line='\${kernel-command-line}' \\ + --host-priv-port='\${host-port}' \\ + --device-master-port='\${device-port}' \\ + --exec-server-task='\${exec-task}' -T typed '\${root}' \\ + '\$(task-create)' '\$(task-resume)' + module /lib/ld.so.1 exec /hurd/exec '\$(exec-task=task-create)' +} +EOF + + cat << EOF +menuentry "${OS} ${KERNEL} (recovery mode)" ${CLASS} { +EOF + prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | sed -e "s/^/\t/" + message="$(gettext_printf "Loading GNU Mach ...")" + cat << EOF + echo '$message' + multiboot ${kernel} root=device:${GRUB_DEVICE#/dev/} -s +EOF + prepare_grub_to_access_device ${GRUB_DEVICE} | sed -e "s/^/\t/" + message="$(gettext_printf "Loading the Hurd ...")" + cat << EOF + echo '$message' + module /hurd/${hurd_fs}.static ${hurd_fs} \\ + --multiboot-command-line='\${kernel-command-line}' \\ + --host-priv-port='\${host-port}' \\ + --device-master-port='\${device-port}' \\ + --exec-server-task='\${exec-task}' -T typed '\${root}' \\ + '\$(task-create)' '\$(task-resume)' + module /lib/ld.so.1 exec /hurd/exec '\$(exec-task=task-create)' +} +EOF + +done diff --git a/util/grub.d/10_kfreebsd.in b/util/grub.d/10_kfreebsd.in new file mode 100644 index 0000000..3600c74 --- /dev/null +++ b/util/grub.d/10_kfreebsd.in @@ -0,0 +1,192 @@ +#! /bin/sh +set -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@ + +CLASS="--class os" + +case "${GRUB_DISTRIBUTOR}" in + Debian) + OS="${GRUB_DISTRIBUTOR} GNU/kFreeBSD" + CLASS="--class $(echo ${GRUB_DISTRIBUTOR} | tr 'A-Z' 'a-z' | cut -d' ' -f1) --class gnu-kfreebsd --class gnu ${CLASS}" + ;; + *) + OS="FreeBSD" + CLASS="--class freebsd --class bsd ${CLASS}" + ;; +esac + +load_kfreebsd_module () +{ + mod="$1" + allow_fail="$2" + + if ! test -e "${module_dir}/${mod}.ko" ; then + if [ "${allow_fail}" = "true" ] ; then + # Return silently + return + else + # Print an error and fail. + ls "${module_dir}/${mod}.ko" > /dev/null + fi + fi + + if [ -z "${prepare_module_dir_cache}" ]; then + prepare_module_dir_cache="$(prepare_grub_to_access_device $(grub-probe -t device "${module_dir}") | sed -e "s/^/\t/")" + fi + + printf '%s\n' "${prepare_module_dir_cache}" + cat << EOF + kfreebsd_module_elf ${module_dir_rel}/${mod}.ko +EOF +} + +kfreebsd_entry () +{ + os="$1" + version="$2" + recovery="$3" + args="$4" + if ${recovery} ; then + title="$(gettext_quoted "%s, with kFreeBSD %s (recovery mode)")" + else + title="$(gettext_quoted "%s, with kFreeBSD %s")" + fi + printf "menuentry '${title}' ${CLASS} {\n" "${os}" "${version}" + if ! ${recovery} ; then + save_default_entry | sed -e "s/^/\t/" + fi + if [ -z "${prepare_boot_cache}" ]; then + prepare_boot_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | sed -e "s/^/\t/")" + fi + + printf '%s\n' "${prepare_boot_cache}" + message="$(gettext_printf "Loading kernel of FreeBSD %s ..." ${version})" + cat << EOF + echo '$message' + kfreebsd ${rel_dirname}/${basename} ${args} +EOF + + if test -n "${devices}" ; then + cat << EOF + kfreebsd_loadenv ${devices_rel_dirname}/${devices_basename} +EOF + fi + + load_kfreebsd_module acpi true + + case "${kfreebsd_fs}" in + zfs) + load_kfreebsd_module opensolaris false + + ls "${dirname}/zfs/zpool.cache" > /dev/null + printf '%s\n' "${prepare_boot_cache}" + cat << EOF + kfreebsd_module ${rel_dirname}/zfs/zpool.cache type=/boot/zfs/zpool.cache +EOF + ;; + esac + + if [ x${kfreebsd_fs} = xufs ]; then + load_kfreebsd_module ${kfreebsd_fs} true + else + load_kfreebsd_module ${kfreebsd_fs} false + fi + + cat << EOF + set kFreeBSD.vfs.root.mountfrom=${kfreebsd_fs}:${kfreebsd_device} + set kFreeBSD.vfs.root.mountfrom.options=rw +} +EOF +} + +list=`for i in /boot/kfreebsd-* /boot/kernel/kernel ; do + if grub_file_is_not_garbage "$i" ; then echo -n "$i " ; fi + done` +prepare_boot_cache= + +while [ "x$list" != "x" ] ; do + kfreebsd=`version_find_latest $list` + echo "Found kernel of FreeBSD: $kfreebsd" >&2 + basename=`basename $kfreebsd` + dirname=`dirname $kfreebsd` + rel_dirname=`make_system_path_relative_to_its_root $dirname` + + if [ -f /boot/device.hints ] ; then + devices=/boot/device.hints + devices_basename=`basename $devices` + devices_dirname=`dirname $devices` + devices_rel_dirname=`make_system_path_relative_to_its_root $devices_dirname` + fi + + case ${GRUB_FS} in + ufs1 | ufs2) kfreebsd_fs=ufs ;; + ext2) kfreebsd_fs=ext2fs ;; + *) kfreebsd_fs=${GRUB_FS} ;; + esac + + case ${GRUB_FS} in + zfs) + # 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_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; }' \ + | grep "${kfreebsd_fs}id/${GRUB_DEVICE_UUID}" > /dev/null); then + kfreebsd_device=${GRUB_DEVICE} + fi + ;; + esac + + version=`echo $basename | sed -e "s,^[^0-9]*-,,g;s/\.gz$//g"` + alt_version=`echo $version | sed -e "s,\.old$,,g"` + + module_dir= + for i in "/lib/modules/${version}" "/lib/modules/${alt_version}" \ + "/boot/kernel"; do + if test -e "$i" ; then + module_dir="$i" + break + fi + done + if test -n "${module_dir}" ; then + echo "Found kernel module directory: ${module_dir}" >&2 + module_dir_rel=$(make_system_path_relative_to_its_root $module_dir) + fi + + kfreebsd_entry "${OS}" "${version}" false + if [ "x${GRUB_DISABLE_RECOVERY}" != "xtrue" ]; then + kfreebsd_entry "${OS}" "${version}" true "-s" + fi + + list=`echo $list | tr ' ' '\n' | grep -vx $kfreebsd | tr '\n' ' '` +done diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in new file mode 100644 index 0000000..1d1eb40 --- /dev/null +++ b/util/grub.d/10_linux.in @@ -0,0 +1,199 @@ +#! /bin/sh +set -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@ + +CLASS="--class gnu-linux --class gnu --class os" + +if [ "x${GRUB_DISTRIBUTOR}" = "x" ] ; then + OS=GNU/Linux +else + OS="${GRUB_DISTRIBUTOR} GNU/Linux" + CLASS="--class $(echo ${GRUB_DISTRIBUTOR} | tr 'A-Z' 'a-z' | cut -d' ' -f1) ${CLASS}" +fi + +# loop-AES arranges things so that /dev/loop/X can be our root device, but +# the initrds that Linux uses don't like that. +case ${GRUB_DEVICE} in + /dev/loop/*|/dev/loop[0-9]) + GRUB_DEVICE=`losetup ${GRUB_DEVICE} | sed -e "s/^[^(]*(\([^)]\+\)).*/\1/"` + ;; +esac + +if [ "x${GRUB_DEVICE_UUID}" = "x" ] || [ "x${GRUB_DISABLE_LINUX_UUID}" = "xtrue" ] \ + || ! test -e "/dev/disk/by-uuid/${GRUB_DEVICE_UUID}" \ + || uses_abstraction "${GRUB_DEVICE}" lvm; then + LINUX_ROOT_DEVICE=${GRUB_DEVICE} +else + LINUX_ROOT_DEVICE=UUID=${GRUB_DEVICE_UUID} +fi + +if [ "x`${grub_probe} --device ${GRUB_DEVICE} --target=fs 2>/dev/null || true`" = xbtrfs ]; then + rootsubvol="`make_system_path_relative_to_its_root /`" + rootsubvol="${rootsubvol#/}" + if [ "x${rootsubvol}" != x ]; then + GRUB_CMDLINE_LINUX="rootflags=subvol=${rootsubvol} ${GRUB_CMDLINE_LINUX}" + fi +fi + +linux_entry () +{ + os="$1" + version="$2" + recovery="$3" + args="$4" + if ${recovery} ; then + title="$(gettext_quoted "%s, with Linux %s (recovery mode)")" + else + title="$(gettext_quoted "%s, with Linux %s")" + fi + printf "menuentry '${title}' ${CLASS} {\n" "${os}" "${version}" + if ! ${recovery} ; then + save_default_entry | sed -e "s/^/\t/" + fi + + # Use ELILO's generic "efifb" when it's known to be available. + # FIXME: We need an interface to select vesafb in case efifb can't be used. + if [ "x$GRUB_GFXPAYLOAD_LINUX" = x ]; then + cat << EOF + load_video +EOF + if grep -qx "CONFIG_FB_EFI=y" "${config}" 2> /dev/null \ + && grep -qx "CONFIG_VT_HW_CONSOLE_BINDING=y" "${config}" 2> /dev/null; then + cat << EOF + set gfxpayload=keep +EOF + fi + else + if [ "x$GRUB_GFXPAYLOAD_LINUX" != xtext ]; then + cat << EOF + load_video +EOF + fi + cat << EOF + set gfxpayload=$GRUB_GFXPAYLOAD_LINUX +EOF + fi + + cat << EOF + insmod gzio +EOF + + if [ x$dirname = x/ ]; then + if [ -z "${prepare_root_cache}" ]; then + prepare_root_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE} | sed -e "s/^/\t/")" + fi + printf '%s\n' "${prepare_root_cache}" + else + if [ -z "${prepare_boot_cache}" ]; then + prepare_boot_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | sed -e "s/^/\t/")" + fi + printf '%s\n' "${prepare_boot_cache}" + fi + message="$(gettext_printf "Loading Linux %s ..." ${version})" + cat << EOF + echo '$message' + linux ${rel_dirname}/${basename} root=${linux_root_device_thisversion} ro ${args} +EOF + if test -n "${initrd}" ; then + message="$(gettext_printf "Loading initial ramdisk ...")" + cat << EOF + echo '$message' + initrd ${rel_dirname}/${initrd} +EOF + fi + cat << EOF +} +EOF +} + +case x`uname -m` 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 + +prepare_boot_cache= +prepare_root_cache= + +while [ "x$list" != "x" ] ; do + linux=`version_find_latest $list` + echo "Found linux image: $linux" >&2 + basename=`basename $linux` + dirname=`dirname $linux` + rel_dirname=`make_system_path_relative_to_its_root $dirname` + version=`echo $basename | sed -e "s,^[^0-9]*-,,g"` + alt_version=`echo $version | sed -e "s,\.old$,,g"` + linux_root_device_thisversion="${LINUX_ROOT_DEVICE}" + + initrd= + for i in "initrd.img-${version}" "initrd-${version}.img" \ + "initrd-${version}" "initramfs-${version}.img" \ + "initrd.img-${alt_version}" "initrd-${alt_version}.img" \ + "initrd-${alt_version}" "initramfs-${alt_version}.img" \ + "initramfs-genkernel-${version}" \ + "initramfs-genkernel-${alt_version}"; do + if test -e "${dirname}/${i}" ; then + initrd="$i" + break + fi + done + + config= + for i in "${dirname}/config-${version}" "${dirname}/config-${alt_version}" "/etc/kernels/kernel-config-${version}" ; do + if test -e "${i}" ; then + config="${i}" + break + fi + done + + initramfs= + if test -n "${config}" ; then + initramfs=`grep CONFIG_INITRAMFS_SOURCE= "${config}" | cut -f2 -d= | tr -d \"` + fi + + if test -n "${initrd}" ; then + echo "Found initrd image: ${dirname}/${initrd}" >&2 + elif test -z "${initramfs}" ; then + # "UUID=" magic is parsed by initrd or initramfs. Since there's + # no initrd or builtin initramfs, it can't work here. + linux_root_device_thisversion=${GRUB_DEVICE} + fi + + linux_entry "${OS}" "${version}" false \ + "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}" + if [ "x${GRUB_DISABLE_RECOVERY}" != "xtrue" ]; then + linux_entry "${OS}" "${version}" true \ + "single ${GRUB_CMDLINE_LINUX}" + fi + + list=`echo $list | tr ' ' '\n' | grep -vx $linux | tr '\n' ' '` +done diff --git a/util/grub.d/10_netbsd.in b/util/grub.d/10_netbsd.in new file mode 100644 index 0000000..ffd31ad --- /dev/null +++ b/util/grub.d/10_netbsd.in @@ -0,0 +1,143 @@ +#! /bin/sh +set -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_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) + karch="amd64" + ;; + *) + return + ;; + esac + + case $(${grub_probe} --target=fs -d ${GRUB_DEVICE}) in + ext2) + kmod="ext2fs" + ;; + fat) + kmod="msdosfs" + ;; + ntfs) + kmod="ntfs" + ;; + ufs*) + kmod="ffs" + ;; + *) + return + ;; + 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" + + if test -z "$karch" -o -z "$kversion" -o ! -f "${kmodule}"; then + return + fi + + kmodule_rel=$(make_system_path_relative_to_its_root "$kmodule") || return + prepare_grub_to_access_device $(${grub_probe} -t device "${kmodule}") | sed -e 's,^, ,' + case "${loader}" in + knetbsd) + printf "\tknetbsd_module_elf %s\n" "${kmodule_rel}" + ;; + multiboot) + printf "\tmodule %s\n" "${kmodule_rel}" + ;; + esac +} + +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 + + netbsd_load_fs_module "${loader}" "${kernel}" + + 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 ! (zcat -f "$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_RECOVERY}" != "xtrue" ]; then + netbsd_entry "knetbsd" "$k" true "-s" + netbsd_entry "multiboot" "$k" true "-s" + fi +done diff --git a/util/grub.d/10_windows.in b/util/grub.d/10_windows.in new file mode 100644 index 0000000..fd068dd --- /dev/null +++ b/util/grub.d/10_windows.in @@ -0,0 +1,94 @@ +#! /bin/sh +set -e + +# grub-mkconfig helper script. +# Copyright (C) 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@ +libdir=@libdir@ +. ${libdir}/grub/grub-mkconfig_lib + +case "`uname 2>/dev/null`" in + CYGWIN*) ;; + *) exit 0 ;; +esac + +# Try C: even if current system is on other partition. +case "$SYSTEMDRIVE" in + [Cc]:) drives="C:" ;; + [D-Zd-z]:) drives="C: $SYSTEMDRIVE" ;; + *) exit 0 ;; +esac + +get_os_name_from_boot_ini () +{ + # Fail if no or more than one partition. + test "`sed -n 's,^\(\(multi\|scsi\)[^=]*\)=.*$,\1,p' "$1" 2>/dev/null | \ + sort | uniq | wc -l`" = 1 || return 1 + + # Search 'default=PARTITION' + local part=`sed -n 's,^default=,,p' "$1" | sed 's,\\\\,/,g;s,[ \t\r]*$,,;1q'` + test -n "$part" || return 1 + + # Search 'PARTITION="NAME" ...' + local name=`sed -n 's,\\\\,/,g;s,^'"$part"'="\([^"]*\)".*$,\1,p' "$1" | sed 1q` + test -n "$name" || return 1 + + echo "$name" +} + + +for drv in $drives ; do + + # Convert to Cygwin path. + dir=`cygpath "$drv"` + test -n "$dir" || continue + + needmap= + + # Check for Vista bootmgr. + if [ -f "$dir"/bootmgr -a -f "$dir"/boot/bcd ] ; then + OS="Windows Vista bootmgr" + + # Check for NTLDR. + elif [ -f "$dir"/ntldr -a -f "$dir"/ntdetect.com -a -f "$dir"/boot.ini ] ; then + OS=`get_os_name_from_boot_ini "$dir"/boot.ini` || OS="Windows NT/2000/XP loader" + needmap=t + + else + continue + fi + + # Get boot /dev/ice. + dev=`${grub_probe} -t device "$dir" 2>/dev/null` || continue + + echo "Found $OS on $drv ($dev)" >&2 + cat << EOF +menuentry "$OS" { +EOF + + save_default_entry | sed -e 's,^,\t,' + prepare_grub_to_access_device "$dev" | sed 's,^,\t,' + test -z "$needmap" || cat <<EOF + drivemap -s (hd0) \$root +EOF + cat << EOF + chainloader +1 +} +EOF +done + diff --git a/util/grub.d/20_linux_xen.in b/util/grub.d/20_linux_xen.in new file mode 100644 index 0000000..a900760 --- /dev/null +++ b/util/grub.d/20_linux_xen.in @@ -0,0 +1,174 @@ +#! /bin/sh +set -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@ + +CLASS="--class gnu-linux --class gnu --class os --class xen" + +if [ "x${GRUB_DISTRIBUTOR}" = "x" ] ; then + OS=GNU/Linux +else + OS="${GRUB_DISTRIBUTOR} GNU/Linux" + CLASS="--class $(echo ${GRUB_DISTRIBUTOR} | tr 'A-Z' 'a-z' | cut -d' ' -f1) ${CLASS}" +fi + +# loop-AES arranges things so that /dev/loop/X can be our root device, but +# the initrds that Linux uses don't like that. +case ${GRUB_DEVICE} in + /dev/loop/*|/dev/loop[0-9]) + GRUB_DEVICE=`losetup ${GRUB_DEVICE} | sed -e "s/^[^(]*(\([^)]\+\)).*/\1/"` + ;; +esac + +if [ "x${GRUB_DEVICE_UUID}" = "x" ] || [ "x${GRUB_DISABLE_LINUX_UUID}" = "xtrue" ] \ + || ! test -e "/dev/disk/by-uuid/${GRUB_DEVICE_UUID}" \ + || uses_abstraction "${GRUB_DEVICE}" lvm; then + LINUX_ROOT_DEVICE=${GRUB_DEVICE} +else + LINUX_ROOT_DEVICE=UUID=${GRUB_DEVICE_UUID} +fi + +if [ "x`${grub_probe} --device ${GRUB_DEVICE} --target=fs 2>/dev/null || true`" = xbtrfs ]; then + rootsubvol="`make_system_path_relative_to_its_root /`" + rootsubvol="${rootsubvol#/}" + if [ "x${rootsubvol}" != x ]; then + GRUB_CMDLINE_LINUX="rootflags=subvol=${rootsubvol} ${GRUB_CMDLINE_LINUX}" + fi +fi + +linux_entry () +{ + os="$1" + version="$2" + xen_version="$3" + recovery="$4" + args="$5" + xen_args="$6" + if ${recovery} ; then + title="$(gettext_quoted "%s, with Xen %s and Linux %s (recovery mode)")" + else + title="$(gettext_quoted "%s, with Xen %s and Linux %s")" + fi + printf "menuentry '${title}' ${CLASS} {\n" "${os}" "${xen_version}" "${version}" + if ! ${recovery} ; then + save_default_entry | sed -e "s/^/\t/" + fi + + if [ -z "${prepare_boot_cache}" ]; then + prepare_boot_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | sed -e "s/^/\t/")" + fi + printf '%s\n' "${prepare_boot_cache}" + xmessage="$(gettext_printf "Loading Xen %s ..." ${xen_version})" + lmessage="$(gettext_printf "Loading Linux %s ..." ${version})" + cat << EOF + echo '$xmessage' + multiboot ${rel_xen_dirname}/${xen_basename} placeholder ${xen_args} + echo '$lmessage' + module ${rel_dirname}/${basename} placeholder root=${linux_root_device_thisversion} ro ${args} +EOF + if test -n "${initrd}" ; then + message="$(gettext_printf "Loading initial ramdisk ...")" + cat << EOF + echo '$message' + module ${rel_dirname}/${initrd} +EOF + fi + cat << 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 + fi + done` +if [ "x${linux_list}" = "x" ] ; then + exit 0 +fi +xen_list=`for i in /boot/xen*; do + if grub_file_is_not_garbage "$i" ; then echo -n "$i " ; fi + done` +prepare_boot_cache= + +while [ "x${xen_list}" != "x" ] ; do + list="${linux_list}" + current_xen=`version_find_latest $xen_list` + xen_basename=`basename ${current_xen}` + xen_dirname=`dirname ${current_xen}` + rel_xen_dirname=`make_system_path_relative_to_its_root $xen_dirname` + xen_version=`echo $xen_basename | sed -e "s,.gz$,,g;s,^xen-,,g"` + echo "submenu \"Xen ${xen_version}\" {" + while [ "x$list" != "x" ] ; do + linux=`version_find_latest $list` + echo "Found linux image: $linux" >&2 + basename=`basename $linux` + dirname=`dirname $linux` + rel_dirname=`make_system_path_relative_to_its_root $dirname` + version=`echo $basename | sed -e "s,^[^0-9]*-,,g"` + alt_version=`echo $version | sed -e "s,\.old$,,g"` + linux_root_device_thisversion="${LINUX_ROOT_DEVICE}" + + initrd= + for i in "initrd.img-${version}" "initrd-${version}.img" \ + "initrd-${version}" "initrd.img-${alt_version}" \ + "initrd-${alt_version}.img" "initrd-${alt_version}" \ + "initramfs-genkernel-${version}" \ + "initramfs-genkernel-${alt_version}" ; do + if test -e "${dirname}/${i}" ; then + initrd="$i" + break + fi + done + if test -n "${initrd}" ; then + echo "Found initrd image: ${dirname}/${initrd}" >&2 + else + # "UUID=" magic is parsed by initrds. Since there's no initrd, it can't work here. + linux_root_device_thisversion=${GRUB_DEVICE} + fi + + linux_entry "${OS}" "${version}" "${xen_version}" false \ + "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}" "${GRUB_CMDLINE_XEN} ${GRUB_CMDLINE_XEN_DEFAULT}" + if [ "x${GRUB_DISABLE_RECOVERY}" != "xtrue" ]; then + linux_entry "${OS}" "${version}" "${xen_version}" true \ + "single ${GRUB_CMDLINE_LINUX}" "${GRUB_CMDLINE_XEN}" + fi + + list=`echo $list | tr ' ' '\n' | grep -vx $linux | tr '\n' ' '` + done + echo "}" + xen_list=`echo $xen_list | tr ' ' '\n' | grep -vx $current_xen | tr '\n' ' '` +done diff --git a/util/grub.d/30_os-prober.in b/util/grub.d/30_os-prober.in new file mode 100644 index 0000000..d9d4b0a --- /dev/null +++ b/util/grub.d/30_os-prober.in @@ -0,0 +1,204 @@ +#! /bin/sh +set -e + +# grub-mkconfig helper script. +# Copyright (C) 2006,2007,2008,2009 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@ +libdir=@libdir@ + +. ${libdir}/grub/grub-mkconfig_lib + +if [ "x${GRUB_DISABLE_OS_PROBER}" = "xtrue" ]; then + exit 0 +fi + +if [ -z "`which os-prober 2> /dev/null`" -o -z "`which linux-boot-prober 2> /dev/null`" ] ; then + # missing os-prober and/or linux-boot-prober + exit 0 +fi + +OSPROBED="`os-prober | tr ' ' '^' | paste -s -d ' '`" +if [ -z "${OSPROBED}" ] ; then + # empty os-prober output, nothing doing + exit 0 +fi + +osx_entry() { + cat << EOF +menuentry "${LONGNAME} (${2}-bit) (on ${DEVICE})" --class osx --class darwin --class os { +EOF + save_default_entry | sed -e "s/^/\t/" + prepare_grub_to_access_device ${DEVICE} | sed -e "s/^/\t/" + cat << EOF + load_video + set do_resume=0 + if [ /var/vm/sleepimage -nt10 / ]; then + if xnu_resume /var/vm/sleepimage; then + set do_resume=1 + fi + fi + if [ \$do_resume = 0 ]; then + xnu_uuid ${OSXUUID} uuid + if [ -f /Extra/DSDT.aml ]; then + acpi -e /Extra/DSDT.aml + fi + $1 /mach_kernel boot-uuid=\${uuid} rd=*uuid + if [ /System/Library/Extensions.mkext -nt /System/Library/Extensions ]; then + xnu_mkext /System/Library/Extensions.mkext + else + xnu_kextdir /System/Library/Extensions + fi + if [ -f /Extra/Extensions.mkext ]; then + xnu_mkext /Extra/Extensions.mkext + fi + if [ -d /Extra/Extensions ]; then + xnu_kextdir /Extra/Extensions + fi + if [ -f /Extra/devprop.bin ]; then + xnu_devprop_load /Extra/devprop.bin + fi + if [ -f /Extra/splash.jpg ]; then + insmod jpeg + xnu_splash /Extra/splash.jpg + fi + if [ -f /Extra/splash.png ]; then + insmod png + xnu_splash /Extra/splash.png + fi + if [ -f /Extra/splash.tga ]; then + insmod tga + xnu_splash /Extra/splash.tga + fi + fi +} +EOF +} + +for OS in ${OSPROBED} ; do + DEVICE="`echo ${OS} | cut -d ':' -f 1`" + LONGNAME="`echo ${OS} | cut -d ':' -f 2 | tr '^' ' '`" + LABEL="`echo ${OS} | cut -d ':' -f 3 | tr '^' ' '`" + BOOT="`echo ${OS} | cut -d ':' -f 4`" + + if [ -z "${LONGNAME}" ] ; then + LONGNAME="${LABEL}" + fi + + echo "Found ${LONGNAME} on ${DEVICE}" >&2 + + case ${BOOT} in + chain) + + cat << EOF +menuentry "${LONGNAME} (on ${DEVICE})" --class windows --class os { +EOF + save_default_entry | sed -e "s/^/\t/" + prepare_grub_to_access_device ${DEVICE} | sed -e "s/^/\t/" + + case ${LONGNAME} in + Windows\ Vista*|Windows\ 7*|Windows\ Server\ 2008*) + ;; + *) + cat << EOF + drivemap -s (hd0) \${root} +EOF + ;; + esac + + cat <<EOF + chainloader +1 +} +EOF + ;; + linux) + LINUXPROBED="`linux-boot-prober ${DEVICE} 2> /dev/null | tr ' ' '^' | paste -s -d ' '`" + prepare_boot_cache= + + for LINUX in ${LINUXPROBED} ; do + LROOT="`echo ${LINUX} | cut -d ':' -f 1`" + LBOOT="`echo ${LINUX} | cut -d ':' -f 2`" + LLABEL="`echo ${LINUX} | cut -d ':' -f 3 | tr '^' ' '`" + LKERNEL="`echo ${LINUX} | cut -d ':' -f 4`" + LINITRD="`echo ${LINUX} | cut -d ':' -f 5`" + LPARAMS="`echo ${LINUX} | cut -d ':' -f 6- | tr '^' ' '`" + + if [ -z "${LLABEL}" ] ; then + LLABEL="${LONGNAME}" + fi + + if [ "${LROOT}" != "${LBOOT}" ]; then + LKERNEL="${LKERNEL#/boot}" + LINITRD="${LINITRD#/boot}" + fi + + cat << EOF +menuentry "${LLABEL} (on ${DEVICE})" --class gnu-linux --class gnu --class os { +EOF + save_default_entry | sed -e "s/^/\t/" + if [ -z "${prepare_boot_cache}" ]; then + prepare_boot_cache="$(prepare_grub_to_access_device ${LBOOT} | sed -e "s/^/\t/")" + fi + printf '%s\n' "${prepare_boot_cache}" + cat << EOF + linux ${LKERNEL} ${LPARAMS} +EOF + if [ -n "${LINITRD}" ] ; then + cat << EOF + initrd ${LINITRD} +EOF + fi + cat << EOF +} +EOF + done + ;; + macosx) + OSXUUID="`grub-probe --target=fs_uuid --device ${DEVICE} 2> /dev/null`" + osx_entry xnu_kernel 32 + osx_entry xnu_kernel64 64 + ;; + hurd) + cat << EOF +menuentry "${LONGNAME} (on ${DEVICE})" --class hurd --class gnu --class os { +EOF + save_default_entry | sed -e "s/^/\t/" + prepare_grub_to_access_device ${DEVICE} | sed -e "s/^/\t/" + grub_device="`${grub_probe} --device ${DEVICE} --target=drive`" + mach_device="`echo "${grub_device}" | sed -e 's/(\(hd.*\),msdos\(.*\))/\1s\2/'`" + grub_fs="`${grub_probe} --device ${DEVICE} --target=fs`" + case "${grub_fs}" in + *fs) hurd_fs="${grub_fs}" ;; + *) hurd_fs="${grub_fs}fs" ;; + esac + cat << EOF + multiboot /boot/gnumach.gz root=device:${mach_device} + module /hurd/${hurd_fs}.static ${hurd_fs} --readonly \\ + --multiboot-command-line='\${kernel-command-line}' \\ + --host-priv-port='\${host-port}' \\ + --device-master-port='\${device-port}' \\ + --exec-server-task='\${exec-task}' -T typed '\${root}' \\ + '\$(task-create)' '\$(task-resume)' + module /lib/ld.so.1 exec /hurd/exec '\$(exec-task=task-create)' +} +EOF + ;; + *) + echo " ${LONGNAME} is not yet supported by grub-mkconfig." >&2 + ;; + esac +done diff --git a/util/grub.d/40_custom.in b/util/grub.d/40_custom.in new file mode 100644 index 0000000..48068de --- /dev/null +++ b/util/grub.d/40_custom.in @@ -0,0 +1,5 @@ +#!/bin/sh +exec tail -n +3 $0 +# This file provides an easy way to add custom menu entries. Simply type the +# menu entries you want to add after this comment. Be careful not to change +# the 'exec tail' line above. diff --git a/util/grub.d/41_custom.in b/util/grub.d/41_custom.in new file mode 100644 index 0000000..64d691c --- /dev/null +++ b/util/grub.d/41_custom.in @@ -0,0 +1,7 @@ +#!/bin/sh +cat <<EOF +if [ -f \$prefix/custom.cfg ]; then + source \$prefix/custom.cfg; +fi +EOF + diff --git a/util/grub.d/README b/util/grub.d/README new file mode 100644 index 0000000..3ea109d --- /dev/null +++ b/util/grub.d/README @@ -0,0 +1,11 @@ + +All executable files in this directory are processed in shell expansion order. + + 00_*: Reserved for 00_header. + 10_*: Native boot entries. + 20_*: Third party apps (e.g. memtest86+). + +The number namespace in-between is configurable by system installer and/or +administrator. For example, you can add an entry to boot another OS as +01_otheros, 11_otheros, etc, depending on the position you want it to occupy in +the menu; and then adjust the default setting via /etc/default/grub. |