merge with mainline

This commit is contained in:
BVK Chaitanya 2010-09-19 08:45:38 +05:30
commit 7431d7a49c
242 changed files with 11326 additions and 4857 deletions

View file

@ -0,0 +1,13 @@
bash_completion_source = grub-completion.bash.in
bash_completion_script = grub
EXTRA_DIST = $(bash_completion_source)
CLEANFILES = $(bash_completion_script)
bashcompletiondir = $(sysconfdir)/bash_completion.d
bashcompletion_DATA = $(bash_completion_script)
$(bash_completion_script): $(bash_completion_source) $(top_builddir)/config.status
$(top_builddir)/config.status --file=$@:$<

View file

@ -0,0 +1,489 @@
#
# Bash completion for grub
#
# Copyright (C) 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/>.
# bash completion for grub
__grub_dir() {
local i c=1 boot_dir
for (( c=1; c <= ${#COMP_WORDS[@]}; c++ )); do
i="${COMP_WORDS[c]}"
case "$i" in
--boot-directory)
c=$((++c))
i="${COMP_WORDS[c]}"
boot_dir="${i##*=}";
break
;;
esac
done
boot_dir=${boot_dir-/@bootdirname@}
echo "${boot_dir%/}/@grubdirname@"
}
# This function generates completion reply with compgen
# - arg: accepts 1, 2, 3, or 4 arguments
# $1 wordlist separate by space, tab or newline
# $2 (optional) prefix to add
# $3 (optional) current word to complete
# $4 (optional) suffix to add
__grubcomp () {
local cur="${COMP_WORDS[COMP_CWORD]}"
if [ $# -gt 2 ]; then
cur="$3"
fi
case "$cur" in
--*=)
COMPREPLY=()
;;
*)
local IFS=' '$'\t'$'\n'
COMPREPLY=($(compgen -P "${2-}" -W "${1-}" -S "${4-}" -- "$cur"))
;;
esac
}
# Function that return long options from the help of the command
# - arg: $1 (optional) command to get the long options from
__grub_get_options_from_help () {
local prog
if [ $# -ge 1 ]; then
prog="$1"
else
prog="${COMP_WORDS[0]}"
fi
local i IFS=" "$'\t'$'\n'
for i in $(LC_ALL=C $prog --help)
do
case $i in
--*) echo "${i%=*}";;
esac
done
}
# Function that return long options from the usage of the command
# - arg: $1 (optional) command to get the long options from
__grub_get_options_from_usage () {
local prog
if [ $# -ge 1 ]; then
prog="$1"
else
prog="${COMP_WORDS[0]}"
fi
local i IFS=" "$'\t'$'\n'
for i in $(LC_ALL=C $prog --usage)
do
case $i in
\[--*\]) i=${i#[} # Remove leading [
echo ${i%%?(=*)]} # Remove optional value and trailing ]
;;
esac
done
}
__grub_get_last_option () {
local i
for (( i=$COMP_CWORD-1; i > 0; i-- )); do
if [[ "${COMP_WORDS[i]}" == -* ]]; then
echo "${COMP_WORDS[i]}"
break;
fi
done
}
__grub_list_menuentries () {
local cur="${COMP_WORDS[COMP_CWORD]}"
local config_file=$(__grub_dir)/grub.cfg
if [ -f "$config_file" ];then
local IFS=$'\n'
COMPREPLY=( $(compgen \
-W "$( awk -F "[\"']" '/menuentry/ { print $2 }' $config_file )" \
-- "$cur" )) #'# Help emacs syntax highlighting
fi
}
__grub_list_modules () {
local grub_dir=$(__grub_dir)
local IFS=$'\n'
COMPREPLY=( $( compgen -f -X '!*/*.mod' -- "${grub_dir}/$cur" | {
while read -r tmp; do
[ -n $tmp ] && {
tmp=${tmp##*/}
printf '%s\n' ${tmp%.mod}
}
done
}
))
}
#
# grub-set-default & grub-reboot
#
_grub_set_entry () {
local cur prev split=false
COMPREPLY=()
cur=`_get_cword`
prev=${COMP_WORDS[COMP_CWORD-1]}
_split_longopt && split=true
case "$prev" in
--boot-directory)
_filedir -d
return
;;
esac
$split && return 0
if [[ "$cur" == -* ]]; then
__grubcomp "$(__grub_get_options_from_help)"
else
# Default complete with a menuentry
__grub_list_menuentries
fi
}
__grub_set_default_program=$( echo grub-set-default | sed "@program_transform_name@" )
have ${__grub_set_default_program} && \
complete -F _grub_set_entry -o filenames ${__grub_set_default_program}
unset __grub_set_default_program
__grub_reboot_program=$( echo grub-reboot | sed "@program_transform_name@" )
have ${__grub_reboot_program} && \
complete -F _grub_set_entry -o filenames ${__grub_reboot_program}
unset __grub_reboot_program
#
# grub-editenv
#
_grub_editenv () {
local cur prev
COMPREPLY=()
cur=`_get_cword`
prev=${COMP_WORDS[COMP_CWORD-1]}
case "$prev" in
create|list|set|unset)
COMPREPLY=( "" )
return
;;
esac
__grubcomp "$(__grub_get_options_from_help)
create list set unset"
}
__grub_editenv_program=$( echo grub-editenv | sed "@program_transform_name@" )
have ${__grub_editenv_program} && \
complete -F _grub_editenv -o filenames ${__grub_editenv_program}
unset __grub_editenv_program
#
# grub-mkconfig
#
_grub_mkconfig () {
local cur prev
COMPREPLY=()
cur=`_get_cword`
if [[ "$cur" == -* ]]; then
__grubcomp "$(__grub_get_options_from_help)"
else
_filedir
fi
}
__grub_mkconfig_program=$( echo grub-mkconfig | sed "@program_transform_name@" )
have ${__grub_mkconfig_program} && \
complete -F _grub_mkconfig -o filenames ${__grub_mkconfig_program}
unset __grub_mkconfig_program
#
# grub-setup
#
_grub_setup () {
local cur prev split=false
COMPREPLY=()
cur=`_get_cword`
prev=${COMP_WORDS[COMP_CWORD-1]}
_split_longopt && split=true
case "$prev" in
-d|--directory)
_filedir -d
return
;;
esac
$split && return 0
if [[ "$cur" == -* ]]; then
__grubcomp "$(__grub_get_options_from_help)"
else
# Default complete with a filename
_filedir
fi
}
__grub_setup_program=$( echo grub-setup | sed "@program_transform_name@" )
have ${__grub_setup_program} && \
complete -F _grub_setup -o filenames ${__grub_setup_program}
unset __grub_setup_program
#
# grub-install
#
_grub_install () {
local cur prev last split=false
COMPREPLY=()
cur=`_get_cword`
prev=${COMP_WORDS[COMP_CWORD-1]}
last=$(__grub_get_last_option)
_split_longopt && split=true
case "$prev" in
--boot-directory)
_filedir -d
return
;;
--disk-module)
__grubcomp "biosdisk ata"
return
;;
esac
$split && return 0
if [[ "$cur" == -* ]]; then
__grubcomp "$(__grub_get_options_from_help)"
else
case "$last" in
--modules)
__grub_list_modules
return
;;
esac
# Default complete with a filename
_filedir
fi
}
__grub_install_program=$( echo grub-install | sed "@program_transform_name@" )
have ${__grub_install_program} && \
complete -F _grub_install -o filenames ${__grub_install_program}
unset __grub_install_program
#
# grub-mkfont
#
_grub_mkfont () {
local cur
COMPREPLY=()
cur=`_get_cword`
if [[ "$cur" == -* ]]; then
__grubcomp "$(__grub_get_options_from_help)"
else
# Default complete with a filename
_filedir
fi
}
__grub_mkfont_program=$( echo grub-mkfont | sed "@program_transform_name@" )
have ${__grub_mkfont_program} && \
complete -F _grub_mkfont -o filenames ${__grub_mkfont_program}
unset __grub_mkfont_program
#
# grub-mkrescue
#
_grub_mkrescue () {
local cur prev last
COMPREPLY=()
cur=`_get_cword`
prev=${COMP_WORDS[COMP_CWORD-1]}
last=$(__grub_get_last_option)
if [[ "$cur" == -* ]]; then
__grubcomp "$(__grub_get_options_from_help)"
else
case "$last" in
--modules)
__grub_list_modules
return
;;
esac
# Default complete with a filename
_filedir
fi
}
__grub_mkrescue_program=$( echo grub-mkrescue | sed "@program_transform_name@" )
have ${__grub_mkrescue_program} && \
complete -F _grub_mkrescue -o filenames ${__grub_mkrescue_program}
unset __grub_mkrescue_program
#
# grub-mkimage
#
_grub_mkimage () {
local cur prev split=false
COMPREPLY=()
cur=`_get_cword`
prev=${COMP_WORDS[COMP_CWORD-1]}
_split_longopt && split=true
case "$prev" in
-d|--directory|-p|--prefix)
_filedir -d
return
;;
-O|--format)
# Get available format from help
local prog=${COMP_WORDS[0]}
__grubcomp "$(LC_ALL=C $prog --help | \
awk -F ":" '/available formats/ { print $2 }' | \
sed 's/, / /g')"
return
;;
esac
$split && return 0
if [[ "$cur" == -* ]]; then
__grubcomp "$(__grub_get_options_from_help)"
else
# Default complete with a filename
_filedir
fi
}
__grub_mkimage_program=$( echo grub-mkimage | sed "@program_transform_name@" )
have ${__grub_mkimage_program} && \
complete -F _grub_mkimage -o filenames ${__grub_mkimage_program}
unset __grub_mkimage_program
#
# grub-mkpasswd-pbkdf2
#
_grub_mkpasswd-pbkdf2 () {
local cur
COMPREPLY=()
cur=`_get_cword`
if [[ "$cur" == -* ]]; then
__grubcomp "$(__grub_get_options_from_help)"
else
# Default complete with a filename
_filedir
fi
}
__grub_mkpasswd_pbkdf2_program=$( echo grub-mkpasswd-pbkdf2 | sed "@program_transform_name@" )
have ${__grub_mkpasswd_pbkdf2_program} && \
complete -F _grub_mkpasswd-pbkdf2 -o filenames ${__grub_mkpasswd_pbkdf2_program}
unset __grub_mkpasswd_pbkdf2_program
#
# grub-probe
#
_grub_probe () {
local cur prev split=false
COMPREPLY=()
cur=`_get_cword`
prev=${COMP_WORDS[COMP_CWORD-1]}
_split_longopt && split=true
case "$prev" in
-t|--target)
# Get target type from help
local prog=${COMP_WORDS[0]}
__grubcomp "$(LC_ALL=C $prog --help | \
awk -F "[()]" '/--target=/ { print $2 }' | \
sed 's/|/ /g')"
return
;;
esac
$split && return 0
if [[ "$cur" == -* ]]; then
__grubcomp "$(__grub_get_options_from_help)"
else
# Default complete with a filename
_filedir
fi
}
__grub_probe_program=$( echo grub-probe | sed "@program_transform_name@" )
have ${__grub_probe_program} && \
complete -F _grub_probe -o filenames ${__grub_probe_program}
unset __grub_probe_program
#
# grub-script-check
#
_grub_script-check () {
local cur
COMPREPLY=()
cur=`_get_cword`
if [[ "$cur" == -* ]]; then
__grubcomp "$(__grub_get_options_from_help)"
else
# Default complete with a filename
_filedir
fi
}
__grub_script_check_program=$( echo grub-script-check | sed "@program_transform_name@" )
have ${__grub_script_check_program} && \
complete -F _grub_script-check -o filenames ${__grub_script_check_program}
# Local variables:
# mode: shell-script
# sh-basic-offset: 4
# sh-indent-comment: t
# indent-tabs-mode: nil
# End:
# ex: ts=4 sw=4 et filetype=sh

View file

@ -259,13 +259,11 @@ fstest (char **images, int num_disks, int cmd, int n, char **args)
{
char *host_file;
char *loop_name;
char *argv[3];
int i;
argv[0] = "-p";
for (i = 0; i < num_disks; i++)
{
char *argv[2];
loop_name = grub_xasprintf ("loop%d", i);
if (!loop_name)
grub_util_error (grub_errmsg);
@ -274,10 +272,10 @@ fstest (char **images, int num_disks, int cmd, int n, char **args)
if (!host_file)
grub_util_error (grub_errmsg);
argv[1] = loop_name;
argv[2] = host_file;
argv[0] = loop_name;
argv[1] = host_file;
if (execute_command ("loopback", 3, argv))
if (execute_command ("loopback", 2, argv))
grub_util_error ("loopback command fails");
grub_free (loop_name);
@ -312,15 +310,16 @@ fstest (char **images, int num_disks, int cmd, int n, char **args)
execute_command ("blocklist", n, args);
grub_printf ("\n");
}
argv[0] = "-d";
for (i = 0; i < num_disks; i++)
{
char *argv[2];
loop_name = grub_xasprintf ("loop%d", i);
if (!loop_name)
grub_util_error (grub_errmsg);
argv[0] = "-d";
argv[1] = loop_name;
execute_command ("loopback", 2, argv);

View file

@ -24,6 +24,7 @@ exec_prefix=@exec_prefix@
sbindir=@sbindir@
bindir=@bindir@
libdir=@libdir@
sysconfdir=@sysconfdir@
PACKAGE_NAME=@PACKAGE_NAME@
PACKAGE_TARNAME=@PACKAGE_TARNAME@
PACKAGE_VERSION=@PACKAGE_VERSION@
@ -40,8 +41,10 @@ grub_mkimage=${bindir}/`echo grub-mkimage | sed ${transform}`
grub_mkdevicemap=${sbindir}/`echo grub-mkdevicemap | sed ${transform}`
grub_probe=${sbindir}/`echo grub-probe | sed ${transform}`
grub_editenv=${bindir}/`echo grub-editenv | sed ${transform}`
grub_mkrelpath=${bindir}/`echo grub-mkrelpath | sed ${transform}`
rootdir=
grub_prefix=`echo /boot/grub | sed ${transform}`
bootdir=
grubdir=`echo "/@bootdirname@/@grubdirname@" | sed 's,//*,/,g'`
modules=
install_device=
@ -51,9 +54,27 @@ recheck=no
debug=no
debug_image=
update_nvram=yes
ofpathname=`which ofpathname`
nvsetenv=`which nvsetenv`
efibootmgr=`which efibootmgr 2>/dev/null || true`
removable=no
efi_quiet=
# Get GRUB_DISTRIBUTOR.
if test -f ${sysconfdir}/default/grub ; then
. ${sysconfdir}/default/grub
fi
bootloader_id="$(echo "$GRUB_DISTRIBUTOR" | tr '[A-Z]' '[a-z]' | cut -d' ' -f1)"
if test -z "$bootloader_id"; then
bootloader_id=grub
fi
if [ "${target_cpu}-${platform}" = "i386-pc" ] ; then
disk_module=biosdisk
elif [ "${target_cpu}-${platform}" = "sparc64-ieee1275" ] ; then
elif [ "${platform}" = "ieee1275" ] || [ "${platform}" = "efi" ] ; then
disk_module=
else
disk_module=ata
@ -62,17 +83,27 @@ fi
# Usage: usage
# Print the usage.
usage () {
if [ "${target_cpu}-${platform}" = "i386-pc" ] \
|| [ "${target_cpu}-${platform}" = "sparc64-ieee1275" ]; then
cat <<EOF
Usage: $self [OPTION] install_device
EOF
else
cat <<EOF
Usage: $self [OPTION] [install_device]
EOF
fi
cat <<EOF
Install GRUB on your drive.
-h, --help print this message and exit
-v, --version print the version information and exit
--modules=MODULES pre-load specified modules MODULES
--root-directory=DIR install GRUB images under the directory DIR
instead of the root directory
--boot-directory=DIR install GRUB images under the directory DIR/@grubdirname@
instead of the $grubdir directory
--grub-setup=FILE use FILE as grub-setup
--grub-mkimage=FILE use FILE as grub-mkimage
--grub-mkrelpath=FILE use FILE as grub-mkrelpath
--grub-mkdevicemap=FILE use FILE as grub-mkdevicemap
--grub-probe=FILE use FILE as grub-probe
--no-floppy do not probe any floppy drive
@ -83,16 +114,24 @@ if [ "${target_cpu}-${platform}" = "i386-pc" ] ; then
cat <<EOF
--disk-module=MODULE disk module to use
EOF
fi
if [ "${target_cpu}-${platform}" = "i386-ieee1275" ] || [ "${target_cpu}-${platform}" = "powerpc-ieee1275" ] ; then
cat <<EOF
--no-nvram don't update the boot-device NVRAM variable
EOF
fi
if [ "${platform}" = "efi" ]; then
cat <<EOF
--removable the installation device is removable
--bootloader-id=ID the ID of bootloader.
EOF
fi
cat <<EOF
INSTALL_DEVICE can be a GRUB device name or a system device filename.
$self copies GRUB images into /boot/grub (or /grub on NetBSD and
OpenBSD), and uses grub-setup to install grub into the boot sector.
If the --root-directory option is used, then $self will copy
images into the operating system installation rooted at that directory.
$self copies GRUB images into $grubdir, and uses grub-setup
to install grub into the boot sector.
Report bugs to <bug-grub@gnu.org>.
EOF
@ -134,21 +173,37 @@ do
--font=*)
;;
# Accept for compatibility
--root-directory)
rootdir=`argument $option "$@"`; shift;;
--root-directory=*)
rootdir=`echo "$option" | sed 's/--root-directory=//'` ;;
--boot-directory)
bootdir=`argument $option "$@"`; shift;;
--boot-directory=*)
bootdir=`echo "$option" | sed 's/--boot-directory=//'` ;;
--grub-setup)
grub_setup=`argument $option "$@"`; shift;;
--grub-setup=*)
grub_setup=`echo "$option" | sed 's/--grub-setup=//'` ;;
--bootloader-id)
bootloader_id=`argument $option "$@"`; shift;;
--bootloader_id=*)
bootloader_id=`echo "$option" | sed 's/--bootloader_id=//'` ;;
--grub-mkimage)
grub_mkimage=`argument $option "$@"`; shift;;
--grub-mkimage=*)
grub_mkimage=`echo "$option" | sed 's/--grub-mkimage=//'` ;;
--grub-mkrelpath)
grub_mkrelpath=`argument $option "$@"`; shift;;
--grub-mkimage=*)
grub_mkrelpath=`echo "$option" | sed 's/--grub-mkrelpath=//'` ;;
--grub-mkdevicemap)
grub_mkdevicemap=`argument $option "$@"`; shift;;
--grub-mkdevicemap=*)
@ -163,6 +218,8 @@ do
no_floppy="--no-floppy" ;;
--recheck)
recheck=yes ;;
--removable)
removable=yes ;;
--disk-module)
if [ "${target_cpu}-${platform}" = "i386-pc" ] ; then
@ -173,6 +230,9 @@ do
disk_module=`echo "$option" | sed 's/--disk-module=//'`
fi ;;
--no-nvram)
update_nvram=no ;;
# This is an undocumented feature...
--debug)
debug=yes ;;
@ -202,7 +262,8 @@ done
# for make_system_path_relative_to_its_root()
. ${libdir}/grub/grub-mkconfig_lib
if test "x$install_device" = x && test "${target_cpu}-${platform}" != "mips-yeeloong"; then
if test "x$install_device" = x && ([ "${target_cpu}-${platform}" = "i386-pc" ] \
|| [ "${target_cpu}-${platform}" = "sparc64-ieee1275" ]); then
echo "install_device not specified." 1>&2
usage
exit 1
@ -213,25 +274,21 @@ setup_verbose=
if test $debug = yes; then
set -x
setup_verbose="--verbose"
efi_quiet=-q
fi
# Initialize these directories here, since ROOTDIR was initialized.
case "$host_os" in
netbsd* | openbsd*)
# Because /boot is used for the boot block in NetBSD and OpenBSD, use /grub
# instead of /boot/grub.
grub_prefix=`echo /grub | sed ${transform}`
bootdir=${rootdir}
;;
*)
# Use /boot/grub by default.
bootdir=${rootdir}/boot
;;
esac
if [ -z "$bootdir" ]; then
# Default bootdir if bootdir not initialized.
bootdir=/@bootdirname@
grubdir=${bootdir}/`echo grub | sed ${transform}`
if [ -n "$rootdir" ] ; then
# Initialize bootdir if rootdir was initialized.
bootdir=${rootdir}/@bootdirname@
fi
fi
grubdir=`echo "${bootdir}/@grubdirname@" | sed 's,//*,/,g'`
device_map=${grubdir}/device.map
grub_probe="${grub_probe} --device-map=${device_map}"
# Check if GRUB is installed.
@ -261,6 +318,87 @@ else
exit 1
fi
if [ x"$platform" = xefi ]; then
# Find the EFI System Partition.
efidir=
if test -d ${bootdir}/efi; then
install_device=`$grub_mkdevicemap --device-map=/dev/stdout | $grub_probe --target=device --device-map=/dev/stdin ${bootdir}/efi`
# Is it a mount point?
if test "x$install_device" != "x`$grub_mkdevicemap --device-map=/dev/stdout | $grub_probe --target=device --device-map=/dev/stdin ${bootdir}`"; then
efidir=${bootdir}/efi
fi
elif test -n "$rootdir" && test "x$rootdir" != "x/"; then
# The EFI System Partition may have been given directly using
# --root-directory.
install_device=`$grub_mkdevicemap --device-map=/dev/stdout | $grub_probe --target=device --device-map=/dev/stdin ${rootdir}`
# Is it a mount point?
if test "x$install_device" != "x`$grub_mkdevicemap --device-map=/dev/stdout | $grub_probe --target=device --device-map=/dev/stdin ${rootdir}/..`"; then
efidir=${rootdir}
fi
fi
if test -n "$efidir"; then
efi_fs=`$grub_probe --target=fs --device-map=${device_map} ${efidir}`
if test "x$efi_fs" = xfat; then :; else
echo "${efidir} doesn't look like an EFI partition." 1>&2
efidir=
fi
fi
if test -n "$efidir"; then
# The EFI specification requires that an EFI System Partition must
# contain an "EFI" subdirectory, and that OS loaders are stored in
# subdirectories below EFI. Vendors are expected to pick names that do
# not collide with other vendors. To minimise collisions, we use the
# name of our distributor if possible.
efi_distributor="$bootloader_id"
if test $removable = yes; then
# The specification makes stricter requirements of removable
# devices, in order that only one image can be automatically loaded
# from them. The image must always reside under /EFI/BOOT, and it
# must have a specific file name depending on the architecture.
efi_distributor=BOOT
case "$target_cpu" in
i386)
efi_file=BOOTIA32.EFI ;;
x86-64)
efi_file=BOOTX64.EFI ;;
# GRUB does not yet support these architectures, but they're defined
# by the specification so we include them here to ease future
# expansion.
ia64)
efi_file=BOOTIA64.EFI ;;
esac
else
# It is convenient for each architecture to have a different
# efi_file, so that different versions can be installed in parallel.
case "$target_cpu" in
i386)
efi_file=grubia32.efi ;;
x86-64)
efi_file=grubx64.efi ;;
# GRUB does not yet support these architectures, but they're defined
# by the specification so we include them here to ease future
# expansion.
ia64)
efi_file=grubia64.efi ;;
*)
efi_file=grub.efi ;;
esac
# TODO: We should also use efibootmgr, if available, to add a Boot
# entry for ourselves.
fi
efidir="$efidir/EFI/$efi_distributor"
mkdir -p "$efidir" || exit 1
else
# We don't know what's going on. Fall back to traditional
# (non-specification-compliant) behaviour.
efidir="$grubdir"
efi_distributor=
efi_file=grub.efi
fi
fi
# Create the GRUB directory if it is not present.
mkdir -p "$grubdir" || exit 1
@ -369,6 +507,7 @@ if [ "x${devabstraction_module}" = "x" ] ; then
grub_drive="`$grub_probe --target=drive --device ${grub_device}`" || exit 1
# Strip partition number
grub_partition="`echo ${grub_drive} | sed -e 's/^[^,]*,//; s/)$//'`"
grub_drive="`echo ${grub_drive} | sed -e s/,[a-z0-9,]*//g`"
if [ "$disk_module" = ata ] ; then
# generic method (used on coreboot and ata mod)
@ -391,28 +530,113 @@ if [ "x${devabstraction_module}" = "x" ] ; then
echo 'set prefix=($root)'"${relative_grubdir}" >> ${grubdir}/load.cfg
config_opt="-c ${grubdir}/load.cfg "
modules="$modules search_fs_uuid"
elif [ "x$platform" = xefi ] || [ "x$platform" = xpc ]; then
# we need to hardcode the partition number in the core image's prefix.
prefix_drive="(,$grub_partition)"
fi
else
prefix_drive=`$grub_probe --target=drive --device ${grub_device}` || exit 1
fi
case "${target_cpu}-${platform}" in
i386-pc) mkimage_target=i386-pc ;;
sparc64-ieee1275) mkimage_target=sparc64-ieee1275-raw ;;
mips-yeeloong) mkimage_target=mipsel-yeeloong-elf ;;
*) mkimage_target=i386-coreboot;
*) mkimage_target="${target_cpu}-${platform}" ;;
esac
if [ "${target_cpu}-${platform}" = "i386-pc" ] || [ "${target_cpu}-${platform}" = "sparc64-ieee1275" ] ; then
$grub_mkimage ${config_opt} -O ${mkimage_target} --output=${grubdir}/core.img --prefix=${prefix_drive}${relative_grubdir} $modules || exit 1
case "${target_cpu}-${platform}" in
i386-efi | x86_64-efi) imgext=efi ;;
mips-yeeloong | i386-coreboot | i386-multiboot | i386-ieee1275 \
| powerpc-ieee1275) imgext=elf ;;
*) imgext=img ;;
esac
$grub_mkimage ${config_opt} -d ${pkglibdir} -O ${mkimage_target} --output=${grubdir}/core.${imgext} --prefix=${prefix_drive}${relative_grubdir} $modules || exit 1
# Backward-compatibility kludges
if [ "${target_cpu}-${platform}" = "mips-yeeloong" ]; then
cp ${grubdir}/core.${imgext} /boot/grub.elf
elif [ "${target_cpu}-${platform}" = "i386-ieee1275" ] || [ "${target_cpu}-${platform}" = "powerpc-ieee1275" ]; then
cp ${grubdir}/core.${imgext} /boot/grub/grub
elif [ "${target_cpu}-${platform}" = "i386-efi" ] || [ "${target_cpu}-${platform}" = "x86_64-efi" ]; then
$grub_mkimage ${config_opt} -d ${pkglibdir} -O ${mkimage_target} --output=${grubdir}/grub.efi --prefix="" $modules || exit 1
fi
# Perform the platform-dependent install
if [ "${target_cpu}-${platform}" = "i386-pc" ] || [ "${target_cpu}-${platform}" = "sparc64-ieee1275" ] ; then
# Now perform the installation.
$grub_setup ${setup_verbose} ${setup_force} --directory=${grubdir} --device-map=${device_map} \
${install_device} || exit 1
elif [ "${target_cpu}-${platform}" = "mips-yeeloong" ] ; then
$grub_mkimage ${config_opt} -d ${pkglibdir} -O ${mkimage_target} --output=/boot/grub.elf --prefix=${prefix_drive}${relative_grubdir} $modules || exit 1
else
$grub_mkimage -O ${mkimage_target} ${config_opt} -d ${pkglibdir} --output=/boot/multiboot.img --prefix=${prefix_drive}${relative_grubdir} $modules || exit 1
$grub_setup ${setup_verbose} ${setup_force} --directory=${grubdir} \
--device-map=${device_map} ${install_device} || exit 1
elif [ "${target_cpu}-${platform}" = "i386-ieee1275" ] || [ "${target_cpu}-${platform}" = "powerpc-ieee1275" ]; then
if [ x"$update_nvram" = xyes ]; then
set $ofpathname dummy
if test -f "$1"; then
:
else
echo "$1: Not found." 1>&2
exit 1
fi
set $nvsetenv dummy
if test -f "$1"; then
:
else
echo "$1: Not found." 1>&2
exit 1
fi
# Get the Open Firmware device tree path translation.
dev=`echo $grub_device | sed -e 's/\/dev\///' -e 's/[0-9]\+//'`
partno=`echo $grub_device | sed -e 's/.*[^0-9]\([0-9]\+\)$/\1/'`
ofpath=`$ofpathname $dev` || {
echo "Couldn't find Open Firmware device tree path for $dev."
echo "You will have to set boot-device manually."
exit 1
}
# Point boot-device at the new grub install
boot_device="$ofpath:$partno,"`grub-mkrelpath ${grubdir}/core.${imgext} | sed 's,/,\\\\,g'`
"$nvsetenv" boot-device "$boot_device" || {
echo "$nvsetenv failed."
echo "You will have to set boot-device manually. At the Open Firmware prompt, type:"
echo " setenv boot-device $boot_device"
exit 1
}
fi
elif [ x"$platform" = xefi ]; then
cp ${grubdir}/core.${imgext} ${efidir}/${efi_file}
# Try to make this image bootable using the EFI Boot Manager, if available.
if test "$removable" = no && test -n "$efi_distributor" && \
test -n "$efibootmgr"; then
# On Linux, we need the efivars kernel modules.
case "$host_os" in
linux*)
modprobe -q efivars 2>/dev/null || true ;;
esac
# Delete old entries from the same distributor.
for bootnum in `efibootmgr | grep '^Boot[0-9]' | \
fgrep -i " $efi_distributor" | cut -b5-8`; do
efibootmgr $efi_quiet -b "$bootnum" -B
done
# Add a new entry for the image we just created. efibootmgr needs to be
# given the disk device and partition number separately, so we have to
# fiddle about with grub-probe to get hold of this reasonably reliably.
# Use fresh device map text to avoid any problems with stale data, since
# all we need here is a one-to-one mapping.
clean_devmap="$($grub_mkdevicemap --device-map=/dev/stdout)"
efidir_drive="$(echo "$clean_devmap" | $grub_probe --target=drive --device-map=/dev/stdin "$efidir")"
if test -z "$efidir_drive"; then
echo "Can't find GRUB drive for $efidir; unable to create EFI Boot Manager entry." >&2
else
efidir_disk="$(echo "$clean_devmap" | grep "^$(echo "$efidir_drive" | sed 's/,[^)]*//')" | cut -f2)"
efidir_part="$(echo "$efidir_drive" | sed 's/^([^,]*,[^0-9]*//; s/[^0-9].*//')"
efibootmgr $efi_quiet -c -d "$efidir_disk" -p "$efidir_part" -w \
-L "$GRUB_DISTRIBUTOR" -l "\\EFI\\$efi_distributor\\$efi_file"
fi
fi
fi
echo "Installation finished. No error reported."

6
util/grub-kbdcomp.in Normal file
View file

@ -0,0 +1,6 @@
#!/bin/sh
grub_mklayout=${bindir}/`echo grub-mklayout | sed ${transform}`
ckbcomp "$@" | $grub_mklayout -o "$1".gkb

120
util/grub-menulst2cfg.c Normal file
View file

@ -0,0 +1,120 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 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/>.
*/
#include <grub/legacy_parse.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <grub/util/misc.h>
int
main (int argc, char **argv)
{
FILE *in, *out;
char *entryname = NULL;
char *buf = NULL;
size_t bufsize = 0;
char *suffix = xstrdup ("");
int suffixlen = 0;
if (argc >= 2 && argv[1][0] == '-')
{
fprintf (stdout, "Usage: %s [INFILE [OUTFILE]]\n", argv[0]);
return 0;
}
if (argc >= 2)
{
in = fopen (argv[1], "r");
if (!in)
{
fprintf (stderr, "Couldn't open %s for reading: %s\n",
argv[1], strerror (errno));
return 1;
}
}
else
in = stdin;
if (argc >= 3)
{
out = fopen (argv[2], "w");
if (!out)
{
if (in != stdin)
fclose (in);
fprintf (stderr, "Couldn't open %s for writing: %s\n",
argv[2], strerror (errno));
return 1;
}
}
else
out = stdout;
while (1)
{
char *parsed;
if (getline (&buf, &bufsize, in) < 0)
break;
{
char *oldname = NULL;
char *newsuffix;
oldname = entryname;
parsed = grub_legacy_parse (buf, &entryname, &newsuffix);
if (newsuffix)
{
suffixlen += strlen (newsuffix);
suffix = xrealloc (suffix, suffixlen + 1);
strcat (suffix, newsuffix);
}
if (oldname != entryname && oldname)
fprintf (out, "}\n\n");
if (oldname != entryname)
{
char *escaped = grub_legacy_escape (entryname, strlen (entryname));
fprintf (out, "menuentry \'%s\' {\n", escaped);
free (escaped);
free (oldname);
}
}
if (parsed)
fprintf (out, "%s%s", entryname ? " " : "", parsed);
free (parsed);
parsed = NULL;
}
if (entryname)
fprintf (out, "}\n\n");
fwrite (suffix, 1, suffixlen, out);
free (buf);
free (suffix);
free (entryname);
if (in != stdin)
fclose (in);
if (out != stdout)
fclose (out);
return 0;
}

View file

@ -38,6 +38,8 @@ self=`basename $0`
grub_mkdevicemap=${sbindir}/`echo grub-mkdevicemap | sed ${transform}`
grub_probe=${sbindir}/`echo grub-probe | sed ${transform}`
GRUB_PREFIX=`echo '/@bootdirname@/@grubdirname@' | sed "s,//*,/,g"`
# Usage: usage
# Print the usage.
usage () {
@ -93,18 +95,6 @@ done
. ${libdir}/grub/grub-mkconfig_lib
case "$host_os" in
netbsd* | openbsd*)
# Because /boot is used for the boot block in NetBSD and OpenBSD, use /grub
# instead of /boot/grub.
GRUB_PREFIX=`echo /grub | sed ${transform}`
;;
*)
# Use /boot/grub by default.
GRUB_PREFIX=`echo /boot/grub | sed ${transform}`
;;
esac
if [ "x$EUID" = "x" ] ; then
EUID=`id -u`
fi
@ -158,7 +148,7 @@ GRUB_DEVICE_BOOT_UUID="`${grub_probe} --device ${GRUB_DEVICE_BOOT} --target=fs_u
# Filesystem for the device containing our userland. Used for stuff like
# choosing Hurd filesystem module.
GRUB_FS="`${grub_probe} --target=fs / 2> /dev/null || echo unknown`"
GRUB_FS="`${grub_probe} --device ${GRUB_DEVICE} --target=fs 2> /dev/null || echo unknown`"
if test -f ${sysconfdir}/default/grub ; then
. ${sysconfdir}/default/grub
@ -200,7 +190,7 @@ for x in ${GRUB_TERMINAL_OUTPUT}; do
exit 1
fi
else
for dir in ${pkgdatadir} /boot/grub /usr/share/grub ; do
for dir in ${pkgdatadir} ${GRUB_PREFIX} /usr/share/grub ; do
for basename in unicode unifont ascii; do
path="${dir}/${basename}.pf2"
if is_path_readable_by_grub ${path} > /dev/null ; then
@ -255,6 +245,7 @@ export GRUB_DEFAULT \
GRUB_HIDDEN_TIMEOUT_BUTTON \
GRUB_TIMEOUT_BUTTON \
GRUB_BUTTON_CMOS_ADDRESS \
GRUB_BUTTON_CMOS_CLEAN \
GRUB_DISTRIBUTOR \
GRUB_CMDLINE_LINUX \
GRUB_CMDLINE_LINUX_DEFAULT \

View file

@ -119,7 +119,7 @@ prepare_grub_to_access_device ()
# otherwise set root as per value in device.map.
echo "set root='`${grub_probe} --device ${device} --target=drive`'"
if fs_uuid="`${grub_probe} --device ${device} --target=fs_uuid 2> /dev/null`" ; then
echo "search --no-floppy --fs-uuid --set ${fs_uuid}"
echo "search --no-floppy --fs-uuid --set=root ${fs_uuid}"
fi
}

View file

@ -555,7 +555,7 @@ SUFFIX (locate_sections) (Elf_Shdr *sections, Elf_Half section_entsize,
i++, s = (Elf_Shdr *) ((char *) s + section_entsize))
if (SUFFIX (is_text_section) (s, image_target))
{
Elf_Word align = grub_host_to_target32 (s->sh_addralign);
Elf_Word align = grub_host_to_target_addr (s->sh_addralign);
const char *name = strtab + grub_host_to_target32 (s->sh_name);
if (align)
current_address = ALIGN_UP (current_address + image_target->vaddr_offset,
@ -577,7 +577,7 @@ SUFFIX (locate_sections) (Elf_Shdr *sections, Elf_Half section_entsize,
i++, s = (Elf_Shdr *) ((char *) s + section_entsize))
if (SUFFIX (is_data_section) (s, image_target))
{
Elf_Word align = grub_host_to_target32 (s->sh_addralign);
Elf_Word align = grub_host_to_target_addr (s->sh_addralign);
const char *name = strtab + grub_host_to_target32 (s->sh_name);
if (align)
@ -641,7 +641,7 @@ SUFFIX (load_image) (const char *kernel_path, grub_size_t *exec_size,
/* Relocate sections then symbols in the virtual address space. */
s = (Elf_Shdr *) ((char *) sections
+ grub_host_to_target16 (e->e_shstrndx) * section_entsize);
strtab = (char *) e + grub_host_to_target32 (s->sh_offset);
strtab = (char *) e + grub_host_to_target_addr (s->sh_offset);
section_addresses = SUFFIX (locate_sections) (sections, section_entsize,
num_sections, strtab,
@ -662,7 +662,7 @@ SUFFIX (load_image) (const char *kernel_path, grub_size_t *exec_size,
i++, s = (Elf_Shdr *) ((char *) s + section_entsize))
if (grub_target_to_host32 (s->sh_type) == SHT_NOBITS)
{
Elf_Word align = grub_host_to_target32 (s->sh_addralign);
Elf_Word align = grub_host_to_target_addr (s->sh_addralign);
const char *name = strtab + grub_host_to_target32 (s->sh_name);
if (align)

498
util/grub-mklayout.c Normal file
View file

@ -0,0 +1,498 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 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/>.
*/
#include <grub/util/misc.h>
#include <grub/i18n.h>
#include <grub/term.h>
#include <grub/keyboard_layouts.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <getopt.h>
#include <unistd.h>
#include <errno.h>
#include "progname.h"
#define CKBCOMP "ckbcomp"
static struct option options[] = {
{"output", required_argument, 0, 'o'},
{"help", no_argument, 0, 'h'},
{"version", no_argument, 0, 'V'},
{"verbose", no_argument, 0, 'v'},
{0, 0, 0, 0}
};
struct console_grub_equivalence
{
char *layout;
grub_uint32_t grub;
};
static struct console_grub_equivalence console_grub_equivalences_shift[] = {
{"KP_0", '0'},
{"KP_1", '1'},
{"KP_2", '2'},
{"KP_3", '3'},
{"KP_4", '4'},
{"KP_5", '5'},
{"KP_6", '6'},
{"KP_7", '7'},
{"KP_8", '8'},
{"KP_9", '9'},
{"KP_Period", '.'},
};
static struct console_grub_equivalence console_grub_equivalences_unshift[] = {
{"KP_0", GRUB_TERM_KEY_INSERT},
{"KP_1", GRUB_TERM_KEY_END},
{"KP_2", GRUB_TERM_KEY_DOWN},
{"KP_3", GRUB_TERM_KEY_NPAGE},
{"KP_4", GRUB_TERM_KEY_LEFT},
{"KP_5", GRUB_TERM_KEY_CENTER},
{"KP_6", GRUB_TERM_KEY_RIGHT},
{"KP_7", GRUB_TERM_KEY_HOME},
{"KP_8", GRUB_TERM_KEY_UP},
{"KP_9", GRUB_TERM_KEY_PPAGE},
{"KP_Period", GRUB_TERM_KEY_DC},
};
static struct console_grub_equivalence console_grub_equivalences_common[] = {
{"Escape", GRUB_TERM_ESC},
{"Tab", GRUB_TERM_TAB},
{"Delete", GRUB_TERM_BACKSPACE},
{"KP_Enter", '\n'},
{"Return", '\n'},
{"KP_Multiply", '*'},
{"KP_Subtract", '-'},
{"KP_Add", '+'},
{"KP_Divide", '/'},
{"F1", GRUB_TERM_KEY_F1},
{"F2", GRUB_TERM_KEY_F2},
{"F3", GRUB_TERM_KEY_F3},
{"F4", GRUB_TERM_KEY_F4},
{"F5", GRUB_TERM_KEY_F5},
{"F6", GRUB_TERM_KEY_F6},
{"F7", GRUB_TERM_KEY_F7},
{"F8", GRUB_TERM_KEY_F8},
{"F9", GRUB_TERM_KEY_F9},
{"F10", GRUB_TERM_KEY_F10},
{"F11", GRUB_TERM_KEY_F11},
{"F12", GRUB_TERM_KEY_F12},
{"F13", GRUB_TERM_KEY_F1 | GRUB_TERM_SHIFT},
{"F14", GRUB_TERM_KEY_F2 | GRUB_TERM_SHIFT},
{"F15", GRUB_TERM_KEY_F3 | GRUB_TERM_SHIFT},
{"F16", GRUB_TERM_KEY_F4 | GRUB_TERM_SHIFT},
{"F17", GRUB_TERM_KEY_F5 | GRUB_TERM_SHIFT},
{"F18", GRUB_TERM_KEY_F6 | GRUB_TERM_SHIFT},
{"F19", GRUB_TERM_KEY_F7 | GRUB_TERM_SHIFT},
{"F20", GRUB_TERM_KEY_F8 | GRUB_TERM_SHIFT},
{"F21", GRUB_TERM_KEY_F9 | GRUB_TERM_SHIFT},
{"F22", GRUB_TERM_KEY_F10 | GRUB_TERM_SHIFT},
{"F23", GRUB_TERM_KEY_F11 | GRUB_TERM_SHIFT},
{"F24", GRUB_TERM_KEY_F12 | GRUB_TERM_SHIFT},
{"Console_13", GRUB_TERM_KEY_F1 | GRUB_TERM_ALT},
{"Console_14", GRUB_TERM_KEY_F2 | GRUB_TERM_ALT},
{"Console_15", GRUB_TERM_KEY_F3 | GRUB_TERM_ALT},
{"Console_16", GRUB_TERM_KEY_F4 | GRUB_TERM_ALT},
{"Console_17", GRUB_TERM_KEY_F5 | GRUB_TERM_ALT},
{"Console_18", GRUB_TERM_KEY_F6 | GRUB_TERM_ALT},
{"Console_19", GRUB_TERM_KEY_F7 | GRUB_TERM_ALT},
{"Console_20", GRUB_TERM_KEY_F8 | GRUB_TERM_ALT},
{"Console_21", GRUB_TERM_KEY_F9 | GRUB_TERM_ALT},
{"Console_22", GRUB_TERM_KEY_F10 | GRUB_TERM_ALT},
{"Console_23", GRUB_TERM_KEY_F11 | GRUB_TERM_ALT},
{"Console_24", GRUB_TERM_KEY_F12 | GRUB_TERM_ALT},
{"Console_25", GRUB_TERM_KEY_F1 | GRUB_TERM_SHIFT | GRUB_TERM_ALT},
{"Console_26", GRUB_TERM_KEY_F2 | GRUB_TERM_SHIFT | GRUB_TERM_ALT},
{"Console_27", GRUB_TERM_KEY_F3 | GRUB_TERM_SHIFT | GRUB_TERM_ALT},
{"Console_28", GRUB_TERM_KEY_F4 | GRUB_TERM_SHIFT | GRUB_TERM_ALT},
{"Console_29", GRUB_TERM_KEY_F5 | GRUB_TERM_SHIFT | GRUB_TERM_ALT},
{"Console_30", GRUB_TERM_KEY_F6 | GRUB_TERM_SHIFT | GRUB_TERM_ALT},
{"Console_31", GRUB_TERM_KEY_F7 | GRUB_TERM_SHIFT | GRUB_TERM_ALT},
{"Console_32", GRUB_TERM_KEY_F8 | GRUB_TERM_SHIFT | GRUB_TERM_ALT},
{"Console_33", GRUB_TERM_KEY_F9 | GRUB_TERM_SHIFT | GRUB_TERM_ALT},
{"Console_34", GRUB_TERM_KEY_F10 | GRUB_TERM_SHIFT | GRUB_TERM_ALT},
{"Console_35", GRUB_TERM_KEY_F11 | GRUB_TERM_SHIFT | GRUB_TERM_ALT},
{"Console_36", GRUB_TERM_KEY_F12 | GRUB_TERM_SHIFT | GRUB_TERM_ALT},
{"Insert", GRUB_TERM_KEY_INSERT},
{"Down", GRUB_TERM_KEY_DOWN},
{"Up", GRUB_TERM_KEY_UP},
{"Home", GRUB_TERM_KEY_HOME},
{"End", GRUB_TERM_KEY_END},
{"Right", GRUB_TERM_KEY_RIGHT},
{"Left", GRUB_TERM_KEY_LEFT},
{"Next", GRUB_TERM_KEY_NPAGE},
{"Prior", GRUB_TERM_KEY_PPAGE},
{"Remove", GRUB_TERM_KEY_DC},
{"VoidSymbol", 0},
/* "Undead" keys since no dead key support in GRUB. */
{"dead_acute", '\''},
{"dead_circumflex", '^'},
{"dead_grave", '`'},
{"dead_tilde", '~'},
{"dead_diaeresis", '"'},
/* Following ones don't provide any useful symbols for shell. */
{"dead_cedilla", 0},
{"dead_ogonek", 0},
{"dead_caron", 0},
{"dead_breve", 0},
{"dead_doubleacute", 0},
/* Unused in GRUB. */
{"Pause", 0},
{"Scroll_Forward", 0},
{"Scroll_Backward", 0},
{"Hex_0", 0},
{"Hex_1", 0},
{"Hex_2", 0},
{"Hex_3", 0},
{"Hex_4", 0},
{"Hex_5", 0},
{"Hex_6", 0},
{"Hex_7", 0},
{"Hex_8", 0},
{"Hex_9", 0},
{"Hex_A", 0},
{"Hex_B", 0},
{"Hex_C", 0},
{"Hex_D", 0},
{"Hex_E", 0},
{"Hex_F", 0},
{"Scroll_Lock", 0},
{"Show_Memory", 0},
{"Show_Registers", 0},
{"Control_backslash", 0},
{"Compose", 0},
{NULL, '\0'}
};
static grub_uint8_t linux_to_usb_map[128] = {
/* 0x00 */ 0 /* Unused */, GRUB_KEYBOARD_KEY_ESCAPE,
/* 0x02 */ GRUB_KEYBOARD_KEY_1, GRUB_KEYBOARD_KEY_2,
/* 0x04 */ GRUB_KEYBOARD_KEY_3, GRUB_KEYBOARD_KEY_4,
/* 0x06 */ GRUB_KEYBOARD_KEY_5, GRUB_KEYBOARD_KEY_6,
/* 0x08 */ GRUB_KEYBOARD_KEY_7, GRUB_KEYBOARD_KEY_8,
/* 0x0a */ GRUB_KEYBOARD_KEY_9, GRUB_KEYBOARD_KEY_0,
/* 0x0c */ GRUB_KEYBOARD_KEY_DASH, GRUB_KEYBOARD_KEY_EQUAL,
/* 0x0e */ GRUB_KEYBOARD_KEY_BACKSPACE, GRUB_KEYBOARD_KEY_TAB,
/* 0x10 */ GRUB_KEYBOARD_KEY_Q, GRUB_KEYBOARD_KEY_W,
/* 0x12 */ GRUB_KEYBOARD_KEY_E, GRUB_KEYBOARD_KEY_R,
/* 0x14 */ GRUB_KEYBOARD_KEY_T, GRUB_KEYBOARD_KEY_Y,
/* 0x16 */ GRUB_KEYBOARD_KEY_U, GRUB_KEYBOARD_KEY_I,
/* 0x18 */ GRUB_KEYBOARD_KEY_O, GRUB_KEYBOARD_KEY_P,
/* 0x1a */ GRUB_KEYBOARD_KEY_LBRACKET, GRUB_KEYBOARD_KEY_RBRACKET,
/* 0x1c */ GRUB_KEYBOARD_KEY_ENTER, GRUB_KEYBOARD_KEY_LEFT_CTRL,
/* 0x1e */ GRUB_KEYBOARD_KEY_A, GRUB_KEYBOARD_KEY_S,
/* 0x20 */ GRUB_KEYBOARD_KEY_D, GRUB_KEYBOARD_KEY_F,
/* 0x22 */ GRUB_KEYBOARD_KEY_G, GRUB_KEYBOARD_KEY_H,
/* 0x24 */ GRUB_KEYBOARD_KEY_J, GRUB_KEYBOARD_KEY_K,
/* 0x26 */ GRUB_KEYBOARD_KEY_L, GRUB_KEYBOARD_KEY_SEMICOLON,
/* 0x28 */ GRUB_KEYBOARD_KEY_DQUOTE, GRUB_KEYBOARD_KEY_RQUOTE,
/* 0x2a */ GRUB_KEYBOARD_KEY_LEFT_SHIFT, GRUB_KEYBOARD_KEY_BACKSLASH,
/* 0x2c */ GRUB_KEYBOARD_KEY_Z, GRUB_KEYBOARD_KEY_X,
/* 0x2e */ GRUB_KEYBOARD_KEY_C, GRUB_KEYBOARD_KEY_V,
/* 0x30 */ GRUB_KEYBOARD_KEY_B, GRUB_KEYBOARD_KEY_N,
/* 0x32 */ GRUB_KEYBOARD_KEY_M, GRUB_KEYBOARD_KEY_COMMA,
/* 0x34 */ GRUB_KEYBOARD_KEY_DOT, GRUB_KEYBOARD_KEY_SLASH,
/* 0x36 */ GRUB_KEYBOARD_KEY_RIGHT_SHIFT, GRUB_KEYBOARD_KEY_NUMMUL,
/* 0x38 */ GRUB_KEYBOARD_KEY_LEFT_ALT, GRUB_KEYBOARD_KEY_SPACE,
/* 0x3a */ GRUB_KEYBOARD_KEY_CAPS_LOCK, GRUB_KEYBOARD_KEY_F1,
/* 0x3c */ GRUB_KEYBOARD_KEY_F2, GRUB_KEYBOARD_KEY_F3,
/* 0x3e */ GRUB_KEYBOARD_KEY_F4, GRUB_KEYBOARD_KEY_F5,
/* 0x40 */ GRUB_KEYBOARD_KEY_F6, GRUB_KEYBOARD_KEY_F7,
/* 0x42 */ GRUB_KEYBOARD_KEY_F8, GRUB_KEYBOARD_KEY_F9,
/* 0x44 */ GRUB_KEYBOARD_KEY_F10, GRUB_KEYBOARD_KEY_NUM_LOCK,
/* 0x46 */ GRUB_KEYBOARD_KEY_SCROLL_LOCK, GRUB_KEYBOARD_KEY_NUM7,
/* 0x48 */ GRUB_KEYBOARD_KEY_NUM8, GRUB_KEYBOARD_KEY_NUM9,
/* 0x4a */ GRUB_KEYBOARD_KEY_NUMMINUS, GRUB_KEYBOARD_KEY_NUM4,
/* 0x4c */ GRUB_KEYBOARD_KEY_NUM5, GRUB_KEYBOARD_KEY_NUM6,
/* 0x4e */ GRUB_KEYBOARD_KEY_NUMPLUS, GRUB_KEYBOARD_KEY_NUM1,
/* 0x50 */ GRUB_KEYBOARD_KEY_NUM2, GRUB_KEYBOARD_KEY_NUM3,
/* 0x52 */ GRUB_KEYBOARD_KEY_NUMDOT, GRUB_KEYBOARD_KEY_NUMDOT,
/* 0x54 */ 0, 0,
/* 0x56 */ GRUB_KEYBOARD_KEY_102ND, GRUB_KEYBOARD_KEY_F11,
/* 0x58 */ GRUB_KEYBOARD_KEY_F12, 0,
/* 0x5a */ 0, 0,
/* 0x5c */ 0, 0,
/* 0x5e */ 0, 0,
/* 0x60 */ GRUB_KEYBOARD_KEY_NUMENTER, GRUB_KEYBOARD_KEY_RIGHT_CTRL,
/* 0x62 */ GRUB_KEYBOARD_KEY_NUMSLASH, 0,
/* 0x64 */ GRUB_KEYBOARD_KEY_RIGHT_ALT, 0,
/* 0x66 */ GRUB_KEYBOARD_KEY_HOME, GRUB_KEYBOARD_KEY_UP,
/* 0x68 */ GRUB_KEYBOARD_KEY_PPAGE, GRUB_KEYBOARD_KEY_LEFT,
/* 0x6a */ GRUB_KEYBOARD_KEY_RIGHT, GRUB_KEYBOARD_KEY_END,
/* 0x6c */ GRUB_KEYBOARD_KEY_DOWN, GRUB_KEYBOARD_KEY_NPAGE,
/* 0x6e */ GRUB_KEYBOARD_KEY_INSERT, GRUB_KEYBOARD_KEY_DELETE
};
static void
usage (int status)
{
if (status)
fprintf (stderr, "Try `%s --help' for more information.\n", program_name);
else
printf ("\
Usage: %s [OPTIONS] LAYOUT\n\
-o, --output set output base name file. Default is LAYOUT.gkb\n\
-h, --help display this message and exit.\n\
-V, --version print version information and exit.\n\
-v, --verbose print verbose messages.\n\
\n\
Report bugs to <%s>.\n", program_name, PACKAGE_BUGREPORT);
exit (status);
}
static void
add_special_keys (struct grub_keyboard_layout *layout)
{
(void) layout;
}
static unsigned
lookup (char *code, int shift)
{
int i;
struct console_grub_equivalence *pr;
if (shift)
pr = console_grub_equivalences_shift;
else
pr = console_grub_equivalences_unshift;
for (i = 0; pr[i].layout != NULL; i++)
if (strcmp (code, pr[i].layout) == 0)
return pr[i].grub;
for (i = 0; console_grub_equivalences_common[i].layout != NULL; i++)
if (strcmp (code, console_grub_equivalences_common[i].layout) == 0)
return console_grub_equivalences_common[i].grub;
fprintf (stderr, "Unknown key %s\n", code);
return '\0';
}
static unsigned int
get_grub_code (char *layout_code, int shift)
{
unsigned int code;
if (strncmp (layout_code, "U+", sizeof ("U+") - 1) == 0)
sscanf (layout_code, "U+%x", &code);
else if (strncmp (layout_code, "+U+", sizeof ("+U+") - 1) == 0)
sscanf (layout_code, "+U+%x", &code);
else
code = lookup (layout_code, shift);
return code;
}
static void
write_file (FILE *out, struct grub_keyboard_layout *layout)
{
grub_uint32_t version;
unsigned i;
version = grub_cpu_to_le32 (GRUB_KEYBOARD_LAYOUTS_VERSION);
for (i = 0; i < ARRAY_SIZE (layout->keyboard_map); i++)
layout->keyboard_map[i] = grub_cpu_to_le32(layout->keyboard_map[i]);
for (i = 0; i < ARRAY_SIZE (layout->keyboard_map_shift); i++)
layout->keyboard_map_shift[i]
= grub_cpu_to_le32(layout->keyboard_map_shift[i]);
for (i = 0; i < ARRAY_SIZE (layout->keyboard_map_l3); i++)
layout->keyboard_map_l3[i]
= grub_cpu_to_le32(layout->keyboard_map_l3[i]);
for (i = 0; i < ARRAY_SIZE (layout->keyboard_map_shift_l3); i++)
layout->keyboard_map_shift_l3[i]
= grub_cpu_to_le32(layout->keyboard_map_shift_l3[i]);
fwrite (GRUB_KEYBOARD_LAYOUTS_FILEMAGIC, 1,
GRUB_KEYBOARD_LAYOUTS_FILEMAGIC_SIZE, out);
fwrite (&version, sizeof (version), 1, out);
fwrite (layout, 1, sizeof (*layout), out);
}
static void
write_keymaps (FILE *in, FILE *out)
{
struct grub_keyboard_layout layout;
char line[2048];
int ok;
memset (&layout, 0, sizeof (layout));
/* Process the ckbcomp output and prepare the layouts. */
ok = 0;
while (fgets (line, sizeof (line), in))
{
if (strncmp (line, "keycode", sizeof ("keycode") - 1) == 0)
{
unsigned keycode_linux;
unsigned keycode_usb;
char normal[64];
char shift[64];
char normalalt[64];
char shiftalt[64];
sscanf (line, "keycode %u = %60s %60s %60s %60s", &keycode_linux,
normal, shift, normalalt, shiftalt);
/* Not used. */
if (keycode_linux == 0x77 /* Pause */
/* Some obscure keys */
|| keycode_linux == 0x63 || keycode_linux == 0x7d
|| keycode_linux == 0x7e)
continue;
/* Not remappable. */
if (keycode_linux == 0x1d /* Left CTRL */
|| keycode_linux == 0x61 /* Right CTRL */
|| keycode_linux == 0x2a /* Left Shift. */
|| keycode_linux == 0x36 /* Right Shift. */
|| keycode_linux == 0x38 /* Left ALT. */
|| keycode_linux == 0x64 /* Right ALT. */
|| keycode_linux == 0x3a /* CapsLock. */
|| keycode_linux == 0x45 /* NumLock. */
|| keycode_linux == 0x46 /* ScrollLock. */)
continue;
keycode_usb = linux_to_usb_map[keycode_linux];
if (keycode_usb == 0
|| keycode_usb >= GRUB_KEYBOARD_LAYOUTS_ARRAY_SIZE)
{
fprintf (stderr, "Unknown keycode 0x%02x\n", keycode_linux);
continue;
}
if (keycode_usb < GRUB_KEYBOARD_LAYOUTS_ARRAY_SIZE)
{
layout.keyboard_map[keycode_usb] = get_grub_code (normal, 0);
layout.keyboard_map_shift[keycode_usb] = get_grub_code (shift, 1);
layout.keyboard_map_l3[keycode_usb]
= get_grub_code (normalalt, 0);
layout.keyboard_map_shift_l3[keycode_usb]
= get_grub_code (shiftalt, 1);
ok = 1;
}
}
}
if (ok == 0)
{
fprintf (stderr, "ERROR: no keycodes found. Check output of %s.\n",
CKBCOMP);
exit (1);
}
add_special_keys (&layout);
write_file (out, &layout);
}
int
main (int argc, char *argv[])
{
int verbosity;
char *infile_name = NULL;
char *outfile_name = NULL;
FILE *in, *out;
set_program_name (argv[0]);
verbosity = 0;
/* Check for options. */
while (1)
{
int c = getopt_long (argc, argv, "o:i:hVv", options, 0);
if (c == -1)
break;
else
switch (c)
{
case 'h':
usage (0);
break;
case 'i':
infile_name = optarg;
break;
case 'o':
outfile_name = optarg;
break;
case 'V':
printf ("%s (%s) %s\n", program_name, PACKAGE_NAME,
PACKAGE_VERSION);
return 0;
case 'v':
verbosity++;
break;
default:
usage (1);
break;
}
}
if (infile_name)
in = fopen (infile_name, "r");
else
in = stdin;
if (!in)
grub_util_error ("Couldn't open input file: %s\n", strerror (errno));
if (outfile_name)
out = fopen (outfile_name, "wb");
else
out = stdout;
if (!out)
{
if (in != stdin)
fclose (in);
grub_util_error ("Couldn't open output file: %s\n", strerror (errno));
}
write_keymaps (in, out);
if (in != stdin)
fclose (in);
if (out != stdout)
fclose (out);
return 0;
}

230
util/grub-mknetdir.in Normal file
View file

@ -0,0 +1,230 @@
#! /bin/sh
# Install GRUB on your drive.
# Copyright (C) 1999,2000,2001,2002,2003,2004,2005,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/>.
# Initialize some variables.
transform="@program_transform_name@"
prefix=@prefix@
exec_prefix=@exec_prefix@
sbindir=@sbindir@
bindir=@bindir@
libdir=@libdir@
PACKAGE_NAME=@PACKAGE_NAME@
PACKAGE_TARNAME=@PACKAGE_TARNAME@
PACKAGE_VERSION=@PACKAGE_VERSION@
target_cpu=@target_cpu@
platform=@platform@
host_os=@host_os@
pkglibdir=${libdir}/`echo ${PACKAGE_TARNAME}/${target_cpu}-${platform} | sed ${transform}`
localedir=@datadir@/locale
native_platform=@platform@
pkglib_DATA="moddep.lst command.lst fs.lst partmap.lst parttool.lst handler.lst video.lst crypto.lst terminal.lst"
self=`basename $0`
grub_mkimage=${bindir}/`echo grub-mkimage | sed ${transform}`
rootdir=/srv/tftp
grub_prefix=`echo /boot/grub | sed ${transform}`
modules=
install_device=
no_floppy=
recheck=no
debug=no
debug_image=
subdir=`echo /boot/grub | sed ${transform}`
pc_dir=${libdir}/$(echo ${PACKAGE_TARNAME} | sed ${transform})/i386-pc
# Usage: usage
# Print the usage.
usage () {
cat <<EOF
Usage: $self [OPTION] install_device
Install GRUB on your drive.
-h, --help print this message and exit
-v, --version print the version information and exit
--modules=MODULES pre-load specified modules MODULES
--net-directory=DIR root directory of TFTP server
--subdir=DIR relative subdirectory on network server
--grub-mkimage=FILE use FILE as grub-mkimage
$self copies GRUB images into net_directory/subdir/${target_cpu}-${platform}
Report bugs to <bug-grub@gnu.org>.
EOF
}
argument () {
opt=$1
shift
if test $# -eq 0; then
echo "$0: option requires an argument -- '$opt'" 1>&2
exit 1
fi
echo $1
}
# Check the arguments.
while test $# -gt 0
do
option=$1
shift
case "$option" in
-h | --help)
usage
exit 0 ;;
-v | --version)
echo "$self (${PACKAGE_NAME}) ${PACKAGE_VERSION}"
exit 0 ;;
--modules)
modules=`argument $option "$@"`; shift;;
--modules=*)
modules=`echo "$option" | sed 's/--modules=//'` ;;
--net-directory)
rootdir=`argument $option "$@"`; shift;;
--net-directory=*)
rootdir=`echo "$option" | sed 's/--net-directory=//'` ;;
--subdir)
subdir=`argument $option "$@"`; shift;;
--subdir=*)
subdir=`echo "$option" | sed 's/--subdir=//'` ;;
--grub-mkimage)
grub_mkimage=`argument $option "$@"`; shift;;
--grub-mkimage=*)
grub_mkimage=`echo "$option" | sed 's/--grub-mkimage=//'` ;;
# This is an undocumented feature...
--debug)
debug=yes ;;
--debug-image)
debug_image=`argument $option "$@"`; shift;;
--debug-image=*)
debug_image=`echo "$option" | sed 's/--debug-image=//'` ;;
# Intentionally undocumented
--override-directory)
override_dir=`argument $option "$@"`
shift
PATH=${override_dir}:$PATH
export PATH
;;
--override-directory=*)
override_dir=`echo "${option}/" | sed 's/--override-directory=//'`
PATH=${override_dir}:$PATH
export PATH
;;
-*)
echo "Unrecognized option \`$option'" 1>&2
usage
exit 1
;;
*)
if test "x$install_device" != x; then
echo "More than one install_devices?" 1>&2
usage
exit 1
fi
install_device="${option}" ;;
esac
done
set $grub_mkimage dummy
if test -f "$1"; then
:
else
echo "$1: Not found." 1>&2
exit 1
fi
# Create the GRUB directory if it is not present.
mkdir -p "${rootdir}/${subdir}" || exit 1
process_input_dir ()
{
input_dir="$1"
platform="$2"
grubdir="${rootdir}/${subdir}/${platform}"
config_opt=
mkdir -p "$grubdir" || exit 1
for file in ${grubdir}/*.mod ${grubdir}/*.lst ${grubdir}/*.img ${grubdir}/efiemu??.o; do
if test -f $file && [ "`basename $file`" != menu.lst ]; then
rm -f $file || exit 1
fi
done
for file in ${input_dir}/*.mod; do
if test -f "$file"; then
cp -f "$file" "$grubdir/"
fi
done
for file in ${pkglib_DATA}; do
if test -f "${input_dir}/${file}"; then
cp -f "${input_dir}/${file}" "$grubdir/"
fi
done
mkdir -p "$grubdir/locale"
for file in ${input_dir}/po/*.mo; do
if test -f "$file"; then
cp -f "$file" "$grubdir/locale/"
fi
done
rm -f ${grubdir}/load.cfg
if [ "x${debug_image}" != x ]; then
echo "set debug='${debug_image}'" >> ${grubdir}/load.cfg
config_opt="-c ${grubdir}/load.cfg "
fi
case "${platform}" in
i386-pc) mkimage_target=i386-pc-pxe;
netmodules="pxe";
prefix="(pxe)/${subdir}/${platform}";
ext=0 ;;
*) echo Unsupported platform ${platform};
exit 1;;
esac
cat << EOF > ${grubdir}/grub.cfg
source ${subdir}/grub.cfg
EOF
$grub_mkimage ${config_opt} -d "${input_dir}" -O ${mkimage_target} --output=${grubdir}/core.$ext --prefix=$prefix $modules $netmodules || exit 1
echo "Netboot directory for ${platform} created. Configure your DHCP server to point to ${subdir}/${platform}/core.$ext"
}
if [ "${override_dir}" = "" ] ; then
if test -e "${pc_dir}" ; then
process_input_dir ${pc_dir} i386-pc
fi
else
process_input_dir ${override_dir} ${target_cpu}-${native_platform}
fi
# Bye.
exit 0

View file

@ -226,49 +226,16 @@ probe (const char *path, char *device_name)
if (print == PRINT_FS)
{
if (path)
{
struct stat st;
stat (path, &st);
if (S_ISREG (st.st_mode))
{
/* Regular file. Verify that we can read it properly. */
grub_file_t file;
char *rel_path;
grub_util_info ("reading %s via OS facilities", path);
filebuf_via_sys = grub_util_read_image (path);
rel_path = grub_make_system_path_relative_to_its_root (path);
grub_path = xasprintf ("(%s)%s", drive_name, rel_path);
free (rel_path);
grub_util_info ("reading %s via GRUB facilities", grub_path);
grub_file_filter_disable_compression ();
file = grub_file_open (grub_path);
if (! file)
grub_util_error ("cannot open %s via GRUB facilities", grub_path);
filebuf_via_grub = xmalloc (file->size);
grub_file_read (file, filebuf_via_grub, file->size);
grub_util_info ("comparing");
if (memcmp (filebuf_via_grub, filebuf_via_sys, file->size))
grub_util_error ("files differ");
}
}
printf ("%s\n", fs->name);
}
if (print == PRINT_FS_UUID)
else if (print == PRINT_FS_UUID)
{
char *uuid;
if (! fs->uuid)
grub_util_error ("%s does not support UUIDs", fs->name);
fs->uuid (dev, &uuid);
if (fs->uuid (dev, &uuid) != GRUB_ERR_NONE)
grub_util_error ("%s", grub_errmsg);
printf ("%s\n", uuid);
}
@ -278,7 +245,8 @@ probe (const char *path, char *device_name)
if (! fs->label)
grub_util_error ("%s does not support labels", fs->name);
fs->label (dev, &label);
if (fs->label (dev, &label) != GRUB_ERR_NONE)
grub_util_error ("%s", grub_errmsg);
printf ("%s\n", label);
}

View file

@ -29,6 +29,8 @@ self=`basename $0`
grub_editenv=${bindir}/`echo grub-editenv | sed ${transform}`
rootdir=
bootdir=
grubdir=`echo "/@bootdirname@/@grubdirname@" | sed 's,//*,/,g'`
# Usage: usage
# Print the usage.
@ -39,8 +41,8 @@ Set the default boot entry for GRUB, for the next boot only.
-h, --help print this message and exit
-v, --version print the version information and exit
--root-directory=DIR expect GRUB images under the directory DIR
instead of the root directory
--boot-directory=DIR expect GRUB images under the directory DIR/@grubdirname@
instead of the $grubdir directory
ENTRY is a number or a menu item title.
@ -73,11 +75,17 @@ do
echo "$self (${PACKAGE_NAME}) ${PACKAGE_VERSION}"
exit 0 ;;
# Accept for compatibility
--root-directory)
rootdir=`argument $option "$@"`; shift ;;
--root-directory=*)
rootdir=`echo "$option" | sed 's/--root-directory=//'` ;;
--boot-directory)
bootdir=`argument $option "$@"`; shift;;
--boot-directory=*)
bootdir=`echo "$option" | sed 's/--boot-directory=//'` ;;
-*)
echo "Unrecognized option \`$option'" 1>&2
usage
@ -99,21 +107,17 @@ if test "x$entry" = x; then
exit 1
fi
# Initialize these directories here, since ROOTDIR was initialized.
case "$host_os" in
netbsd* | openbsd*)
# Because /boot is used for the boot block in NetBSD and OpenBSD, use /grub
# instead of /boot/grub.
grub_prefix=`echo /grub | sed ${transform}`
bootdir=${rootdir}
;;
*)
# Use /boot/grub by default.
bootdir=${rootdir}/boot
;;
esac
if [ -z "$bootdir" ]; then
# Default bootdir if bootdir not initialized.
bootdir=/@bootdirname@
grubdir=${bootdir}/`echo grub | sed ${transform}`
if [ -n "$rootdir" ] ; then
# Initialize bootdir if rootdir was initialized.
bootdir=${rootdir}/@bootdirname@
fi
fi
grubdir=`echo "${bootdir}/@grubdirname@" | sed 's,//*,/,g'`
prev_saved_entry=`$grub_editenv ${grubdir}/grubenv list | sed -n 's/^saved_entry=//p'`
if [ "$prev_saved_entry" ]; then

View file

@ -29,6 +29,8 @@ self=`basename $0`
grub_editenv=${bindir}/`echo grub-editenv | sed ${transform}`
rootdir=
bootdir=
grubdir=`echo "/@bootdirname@/@grubdirname@" | sed 's,//*,/,g'`
# Usage: usage
# Print the usage.
@ -39,8 +41,8 @@ Set the default boot entry for GRUB.
-h, --help print this message and exit
-v, --version print the version information and exit
--root-directory=DIR expect GRUB images under the directory DIR
instead of the root directory
--boot-directory=DIR expect GRUB images under the directory DIR/@grubdirname@
instead of the $grubdir directory
ENTRY is a number or a menu item title.
@ -73,11 +75,17 @@ do
echo "$self (${PACKAGE_NAME}) ${PACKAGE_VERSION}"
exit 0 ;;
# Accept for compatibility
--root-directory)
rootdir=`argument $option "$@"`; shift ;;
--root-directory=*)
rootdir=`echo "$option" | sed 's/--root-directory=//'` ;;
--boot-directory)
bootdir=`argument $option "$@"`; shift;;
--boot-directory=*)
bootdir=`echo "$option" | sed 's/--boot-directory=//'` ;;
-*)
echo "Unrecognized option \`$option'" 1>&2
usage
@ -99,21 +107,17 @@ if test "x$entry" = x; then
exit 1
fi
# Initialize these directories here, since ROOTDIR was initialized.
case "$host_os" in
netbsd* | openbsd*)
# Because /boot is used for the boot block in NetBSD and OpenBSD, use /grub
# instead of /boot/grub.
grub_prefix=`echo /grub | sed ${transform}`
bootdir=${rootdir}
;;
*)
# Use /boot/grub by default.
bootdir=${rootdir}/boot
;;
esac
if [ -z "$bootdir" ]; then
# Default bootdir if bootdir not initialized.
bootdir=/@bootdirname@
grubdir=${bootdir}/`echo grub | sed ${transform}`
if [ -n "$rootdir" ] ; then
# Initialize bootdir if rootdir was initialized.
bootdir=${rootdir}/@bootdirname@
fi
fi
grubdir=`echo "${bootdir}/@grubdirname@" | sed 's,//*,/,g'`
$grub_editenv ${grubdir}/grubenv unset prev_saved_entry
$grub_editenv ${grubdir}/grubenv set saved_entry="$entry"

View file

@ -26,8 +26,6 @@
#include <grub/file.h>
#include <grub/fs.h>
#include <grub/partition.h>
#include <grub/msdos_partition.h>
#include <grub/gpt_partition.h>
#include <grub/env.h>
#include <grub/emu/hostdisk.h>
#include <grub/machine/boot.h>
@ -36,9 +34,9 @@
#include <grub/i18n.h>
#include <grub/util/raid.h>
#include <grub/util/lvm.h>
#include <grub/emu/getroot.h>
static const grub_gpt_part_type_t grub_gpt_partition_type_bios_boot = GRUB_GPT_PARTITION_TYPE_BIOS_BOOT;
#ifdef GRUB_MACHINE_IEEE1275
#include <grub/util/ofpath.h>
#endif
#include <stdio.h>
#include <unistd.h>
@ -48,96 +46,165 @@ static const grub_gpt_part_type_t grub_gpt_partition_type_bios_boot = GRUB_GPT_P
#include <sys/stat.h>
#include <dirent.h>
#include <assert.h>
#include <grub/emu/getroot.h>
#include "progname.h"
#define _GNU_SOURCE 1
#include <getopt.h>
/* On SPARC this program fills in various fields inside of the 'boot' and 'core'
* image files.
*
* The 'boot' image needs to know the OBP path name of the root
* device. It also needs to know the initial block number of
* 'core' (which is 'diskboot' concatenated with 'kernel' and
* all the modules, this is created by grub-mkimage). This resulting
* 'boot' image is 512 bytes in size and is placed in the second block
* of a partition.
*
* The initial 'diskboot' block acts as a loader for the actual GRUB
* kernel. It contains the loading code and then a block list.
*
* The block list of 'core' starts at the end of the 'diskboot' image
* and works it's way backwards towards the end of the code of 'diskboot'.
*
* We patch up the images with the necessary values and write out the
* result.
*/
#define DEFAULT_BOOT_FILE "boot.img"
#define DEFAULT_CORE_FILE "core.img"
#ifdef GRUB_MACHINE_SPARC64
#define grub_target_to_host16(x) grub_be_to_cpu16(x)
#define grub_target_to_host32(x) grub_be_to_cpu32(x)
#define grub_target_to_host64(x) grub_be_to_cpu64(x)
#define grub_host_to_target16(x) grub_cpu_to_be16(x)
#define grub_host_to_target32(x) grub_cpu_to_be32(x)
#define grub_host_to_target64(x) grub_cpu_to_be64(x)
#elif defined (GRUB_MACHINE_PCBIOS)
#define grub_target_to_host16(x) grub_le_to_cpu16(x)
#define grub_target_to_host32(x) grub_le_to_cpu32(x)
#define grub_target_to_host64(x) grub_le_to_cpu64(x)
#define grub_host_to_target16(x) grub_cpu_to_le16(x)
#define grub_host_to_target32(x) grub_cpu_to_le32(x)
#define grub_host_to_target64(x) grub_cpu_to_le64(x)
#else
#error Complete this
#endif
static void
write_rootdev (char *core_img, grub_device_t root_dev,
char *boot_img, grub_uint64_t first_sector)
{
#ifdef GRUB_MACHINE_PCBIOS
{
grub_int32_t *install_dos_part, *install_bsd_part;
grub_int32_t dos_part, bsd_part;
grub_uint8_t *boot_drive;
grub_disk_addr_t *kernel_sector;
boot_drive = (grub_uint8_t *) (boot_img + GRUB_BOOT_MACHINE_BOOT_DRIVE);
kernel_sector = (grub_disk_addr_t *) (boot_img
+ GRUB_BOOT_MACHINE_KERNEL_SECTOR);
install_dos_part = (grub_int32_t *) (core_img + GRUB_DISK_SECTOR_SIZE
+ GRUB_KERNEL_MACHINE_INSTALL_DOS_PART);
install_bsd_part = (grub_int32_t *) (core_img + GRUB_DISK_SECTOR_SIZE
+ GRUB_KERNEL_MACHINE_INSTALL_BSD_PART);
/* If we hardcoded drive as part of prefix, we don't want to
override the current setting. */
if (*install_dos_part != -2)
{
/* Embed information about the installed location. */
if (root_dev->disk->partition)
{
if (root_dev->disk->partition->parent)
{
if (root_dev->disk->partition->parent->parent)
grub_util_error ("Installing on doubly nested partitions is "
"not supported");
dos_part = root_dev->disk->partition->parent->number;
bsd_part = root_dev->disk->partition->number;
}
else
{
dos_part = root_dev->disk->partition->number;
bsd_part = -1;
}
}
else
dos_part = bsd_part = -1;
}
else
{
dos_part = grub_le_to_cpu32 (*install_dos_part);
bsd_part = grub_le_to_cpu32 (*install_bsd_part);
}
grub_util_info ("dos partition is %d, bsd partition is %d",
dos_part, bsd_part);
*install_dos_part = grub_cpu_to_le32 (dos_part);
*install_bsd_part = grub_cpu_to_le32 (bsd_part);
/* FIXME: can this be skipped? */
*boot_drive = 0xFF;
*kernel_sector = grub_cpu_to_le64 (first_sector);
}
#endif
#ifdef GRUB_MACHINE_IEEE1275
{
grub_disk_addr_t *kernel_byte;
kernel_byte = (grub_disk_addr_t *) (boot_img
+ GRUB_BOOT_AOUT_HEADER_SIZE
+ GRUB_BOOT_MACHINE_KERNEL_BYTE);
*kernel_byte = grub_cpu_to_be64 (first_sector << GRUB_DISK_SECTOR_BITS);
}
#endif
}
#ifdef GRUB_MACHINE_IEEE1275
#define BOOT_SECTOR 1
#else
#define BOOT_SECTOR 0
#endif
static void
setup (const char *dir,
const char *boot_file, const char *core_file,
const char *root, const char *dest, int must_embed, int force, int fs_probe)
const char *root, const char *dest, int must_embed, int force,
int fs_probe)
{
char *boot_path, *core_path, *core_path_dev, *core_path_dev_full;
char *boot_img, *core_img;
size_t boot_size, core_size;
grub_uint16_t core_sectors;
grub_device_t root_dev, dest_dev;
const char *dest_partmap;
int multiple_partmaps;
grub_uint8_t *boot_drive;
grub_disk_addr_t *kernel_sector;
grub_uint16_t *boot_drive_check;
struct grub_boot_blocklist *first_block, *block;
grub_int32_t *install_dos_part, *install_bsd_part;
grub_int32_t dos_part, bsd_part;
char *install_prefix;
char *prefix = NULL;
char *tmp_img;
int i;
grub_disk_addr_t first_sector;
#ifdef GRUB_MACHINE_PCBIOS
grub_uint16_t current_segment
= GRUB_BOOT_MACHINE_KERNEL_SEG + (GRUB_DISK_SECTOR_SIZE >> 4);
#endif
grub_uint16_t last_length = GRUB_DISK_SECTOR_SIZE;
grub_file_t file;
FILE *fp;
struct { grub_uint64_t start; grub_uint64_t end; } embed_region;
embed_region.start = embed_region.end = ~0UL;
auto void NESTED_FUNC_ATTR save_first_sector (grub_disk_addr_t sector, unsigned offset,
unsigned length);
auto void NESTED_FUNC_ATTR save_blocklists (grub_disk_addr_t sector, unsigned offset,
unsigned length);
auto void NESTED_FUNC_ATTR save_first_sector (grub_disk_addr_t sector,
unsigned offset,
unsigned length);
auto void NESTED_FUNC_ATTR save_blocklists (grub_disk_addr_t sector,
unsigned offset,
unsigned length);
auto int NESTED_FUNC_ATTR find_usable_region_msdos (grub_disk_t disk,
const grub_partition_t p);
int NESTED_FUNC_ATTR find_usable_region_msdos (grub_disk_t disk __attribute__ ((unused)),
const grub_partition_t p)
{
/* There's always an embed region, and it starts right after the MBR. */
embed_region.start = 1;
if (embed_region.end > grub_partition_get_start (p))
embed_region.end = grub_partition_get_start (p);
return 0;
}
auto int NESTED_FUNC_ATTR find_usable_region_gpt (grub_disk_t disk,
const grub_partition_t p);
int NESTED_FUNC_ATTR find_usable_region_gpt (grub_disk_t disk __attribute__ ((unused)),
const grub_partition_t p)
{
struct grub_gpt_partentry gptdata;
disk->partition = p->parent;
if (grub_disk_read (disk, p->offset, p->index,
sizeof (gptdata), &gptdata))
return 0;
/* If there's an embed region, it is in a dedicated partition. */
if (! memcmp (&gptdata.type, &grub_gpt_partition_type_bios_boot, 16))
{
embed_region.start = grub_partition_get_start (p);
embed_region.end = grub_partition_get_start (p) + grub_partition_get_len (p);
return 1;
}
return 0;
}
void NESTED_FUNC_ATTR save_first_sector (grub_disk_addr_t sector, unsigned offset,
unsigned length)
void NESTED_FUNC_ATTR save_first_sector (grub_disk_addr_t sector,
unsigned offset,
unsigned length)
{
grub_util_info ("the first sector is <%llu,%u,%u>",
sector, offset, length);
@ -148,26 +215,28 @@ setup (const char *dir,
first_sector = sector;
}
void NESTED_FUNC_ATTR save_blocklists (grub_disk_addr_t sector, unsigned offset,
unsigned length)
void NESTED_FUNC_ATTR save_blocklists (grub_disk_addr_t sector,
unsigned offset,
unsigned length)
{
struct grub_boot_blocklist *prev = block + 1;
grub_util_info ("saving <%llu,%u,%u> with the segment 0x%x",
sector, offset, length, (unsigned) current_segment);
grub_util_info ("saving <%llu,%u,%u>", sector, offset, length);
if (offset != 0 || last_length != GRUB_DISK_SECTOR_SIZE)
grub_util_error (_("non-sector-aligned data is found in the core file"));
if (block != first_block
&& (grub_le_to_cpu64 (prev->start)
+ grub_le_to_cpu16 (prev->len)) == sector)
prev->len = grub_cpu_to_le16 (grub_le_to_cpu16 (prev->len) + 1);
&& (grub_target_to_host64 (prev->start)
+ grub_target_to_host16 (prev->len)) == sector)
prev->len = grub_host_to_target16 (grub_target_to_host16 (prev->len) + 1);
else
{
block->start = grub_cpu_to_le64 (sector);
block->len = grub_cpu_to_le16 (1);
block->segment = grub_cpu_to_le16 (current_segment);
block->start = grub_host_to_target64 (sector);
block->len = grub_host_to_target16 (1);
#ifdef GRUB_MACHINE_PCBIOS
block->segment = grub_host_to_target16 (current_segment);
#endif
block--;
if (block->len)
@ -175,7 +244,9 @@ setup (const char *dir,
}
last_length = length;
#ifdef GRUB_MACHINE_PCBIOS
current_segment += GRUB_DISK_SECTOR_SIZE >> 4;
#endif
}
/* Read the boot image by the OS service. */
@ -187,21 +258,16 @@ setup (const char *dir,
boot_img = grub_util_read_image (boot_path);
free (boot_path);
/* Set the addresses of variables in the boot image. */
boot_drive = (grub_uint8_t *) (boot_img + GRUB_BOOT_MACHINE_BOOT_DRIVE);
kernel_sector = (grub_disk_addr_t *) (boot_img
+ GRUB_BOOT_MACHINE_KERNEL_SECTOR);
boot_drive_check = (grub_uint16_t *) (boot_img
+ GRUB_BOOT_MACHINE_DRIVE_CHECK);
core_path = grub_util_get_path (dir, core_file);
core_size = grub_util_get_image_size (core_path);
core_sectors = ((core_size + GRUB_DISK_SECTOR_SIZE - 1)
>> GRUB_DISK_SECTOR_BITS);
if (core_size < GRUB_DISK_SECTOR_SIZE)
grub_util_error (_("the size of `%s' is too small"), core_path);
else if (core_size > 0xFFFF * GRUB_DISK_SECTOR_SIZE)
#ifdef GRUB_MACHINE_PCBIOS
if (core_size > 0xFFFF * GRUB_DISK_SECTOR_SIZE)
grub_util_error (_("the size of `%s' is too large"), core_path);
#endif
core_img = grub_util_read_image (core_path);
@ -209,19 +275,15 @@ setup (const char *dir,
first_block = (struct grub_boot_blocklist *) (core_img
+ GRUB_DISK_SECTOR_SIZE
- sizeof (*block));
install_dos_part = (grub_int32_t *) (core_img + GRUB_DISK_SECTOR_SIZE
+ GRUB_KERNEL_MACHINE_INSTALL_DOS_PART);
install_bsd_part = (grub_int32_t *) (core_img + GRUB_DISK_SECTOR_SIZE
+ GRUB_KERNEL_MACHINE_INSTALL_BSD_PART);
install_prefix = (char *) (core_img + GRUB_DISK_SECTOR_SIZE +
GRUB_KERNEL_MACHINE_PREFIX);
grub_util_info ("root is `%s', dest is `%s'", root, dest);
/* Open the root device and the destination device. */
grub_util_info ("Opening root");
root_dev = grub_device_open (root);
if (! root_dev)
grub_util_error ("%s", grub_errmsg);
grub_util_info ("Opening dest");
dest_dev = grub_device_open (dest);
if (! dest_dev)
grub_util_error ("%s", grub_errmsg);
@ -230,197 +292,171 @@ setup (const char *dir,
if (grub_env_set ("root", root) != GRUB_ERR_NONE)
grub_util_error ("%s", grub_errmsg);
#ifdef GRUB_MACHINE_PCBIOS
/* Read the original sector from the disk. */
tmp_img = xmalloc (GRUB_DISK_SECTOR_SIZE);
if (grub_disk_read (dest_dev->disk, 0, 0, GRUB_DISK_SECTOR_SIZE, tmp_img))
grub_util_error ("%s", grub_errmsg);
#endif
if (dest_dev->disk->partition && fs_probe)
#ifdef GRUB_MACHINE_PCBIOS
{
grub_uint16_t *boot_drive_check;
boot_drive_check = (grub_uint16_t *) (boot_img
+ GRUB_BOOT_MACHINE_DRIVE_CHECK);
/* Copy the possible DOS BPB. */
memcpy (boot_img + GRUB_BOOT_MACHINE_BPB_START,
tmp_img + GRUB_BOOT_MACHINE_BPB_START,
GRUB_BOOT_MACHINE_BPB_END - GRUB_BOOT_MACHINE_BPB_START);
/* If DEST_DRIVE is a hard disk, enable the workaround, which is
for buggy BIOSes which don't pass boot drive correctly. Instead,
they pass 0x00 or 0x01 even when booted from 0x80. */
if (!grub_util_biosdisk_is_floppy (dest_dev->disk))
/* Replace the jmp (2 bytes) with double nop's. */
*boot_drive_check = 0x9090;
}
#endif
/* Clean out the blocklists. */
block = first_block;
while (block->len)
{
grub_fs_t fs;
fs = grub_fs_probe (dest_dev);
if (! fs)
grub_util_error (_("unable to identify a filesystem in %s; safety check can't be performed"),
dest_dev->disk->name);
grub_memset (block, 0, sizeof (block));
if (! fs->reserved_first_sector)
grub_util_error (_("%s appears to contain a %s filesystem which isn't known to "
"reserve space for DOS-style boot. Installing GRUB there could "
"result in FILESYSTEM DESTRUCTION if valuable data is overwritten "
"by grub-setup (--skip-fs-probe disables this "
"check, use at your own risk)"), dest_dev->disk->name, fs->name);
block--;
if ((char *) block <= core_img)
grub_util_error ("No terminator in the core image");
}
/* Copy the possible DOS BPB. */
memcpy (boot_img + GRUB_BOOT_MACHINE_BPB_START,
tmp_img + GRUB_BOOT_MACHINE_BPB_START,
GRUB_BOOT_MACHINE_BPB_END - GRUB_BOOT_MACHINE_BPB_START);
#ifdef GRUB_MACHINE_PCBIOS
{
grub_partition_map_t dest_partmap = NULL;
grub_partition_t container = dest_dev->disk->partition;
int multiple_partmaps = 0;
grub_err_t err;
grub_disk_addr_t sectors[core_sectors];
int i;
grub_fs_t fs;
/* Copy the possible partition table. */
if (dest_dev->disk->has_partitions)
memcpy (boot_img + GRUB_BOOT_MACHINE_WINDOWS_NT_MAGIC,
tmp_img + GRUB_BOOT_MACHINE_WINDOWS_NT_MAGIC,
GRUB_BOOT_MACHINE_PART_END - GRUB_BOOT_MACHINE_WINDOWS_NT_MAGIC);
free (tmp_img);
/* If DEST_DRIVE is a hard disk, enable the workaround, which is
for buggy BIOSes which don't pass boot drive correctly. Instead,
they pass 0x00 or 0x01 even when booted from 0x80. */
if (dest_dev->disk->id & 0x80)
/* Replace the jmp (2 bytes) with double nop's. */
*boot_drive_check = 0x9090;
/* If we hardcoded drive as part of prefix, we don't want to
override the current setting. */
if (*install_dos_part != -2)
/* Unlike root_dev, with dest_dev we're interested in the partition map even
if dest_dev itself is a whole disk. */
auto int NESTED_FUNC_ATTR identify_partmap (grub_disk_t disk,
const grub_partition_t p);
int NESTED_FUNC_ATTR identify_partmap (grub_disk_t disk __attribute__ ((unused)),
const grub_partition_t p)
{
/* Embed information about the installed location. */
if (root_dev->disk->partition)
{
if (root_dev->disk->partition->parent)
{
if (root_dev->disk->partition->parent->parent)
grub_util_error ("Installing on doubly nested partitions is "
"not supported");
dos_part = root_dev->disk->partition->parent->number;
bsd_part = root_dev->disk->partition->number;
}
else
{
dos_part = root_dev->disk->partition->number;
bsd_part = -1;
}
if (install_prefix[0] != '(')
{
char *root_part_name;
root_part_name =
grub_partition_get_name (root_dev->disk->partition);
prefix = xasprintf ("(,%s)%s", root_part_name, install_prefix);
free (root_part_name);
}
}
else
dos_part = bsd_part = -1;
}
else
{
dos_part = grub_le_to_cpu32 (*install_dos_part);
bsd_part = grub_le_to_cpu32 (*install_bsd_part);
}
grub_util_info ("dos partition is %d, bsd partition is %d",
dos_part, bsd_part);
if (! dest_dev->disk->has_partitions)
{
grub_util_warn (_("Attempting to install GRUB to a partitionless disk. This is a BAD idea."));
goto unable_to_embed;
}
if (dest_dev->disk->partition)
{
grub_util_warn (_("Attempting to install GRUB to a partition instead of the MBR. This is a BAD idea."));
goto unable_to_embed;
}
/* Unlike root_dev, with dest_dev we're interested in the partition map even
if dest_dev itself is a whole disk. */
auto int NESTED_FUNC_ATTR identify_partmap (grub_disk_t disk,
const grub_partition_t p);
int NESTED_FUNC_ATTR identify_partmap (grub_disk_t disk __attribute__ ((unused)),
const grub_partition_t p)
{
if (p->parent)
if (p->parent != container)
return 0;
if (dest_partmap == NULL)
dest_partmap = p->partmap->name;
else if (strcmp (dest_partmap, p->partmap->name) != 0)
{
multiple_partmaps = 1;
return 1;
dest_partmap = p->partmap;
return 0;
}
return 0;
}
dest_partmap = 0;
multiple_partmaps = 0;
grub_partition_iterate (dest_dev->disk, identify_partmap);
if (! dest_partmap)
{
grub_util_warn (_("Attempting to install GRUB to a partitionless disk. This is a BAD idea."));
goto unable_to_embed;
}
if (multiple_partmaps)
{
grub_util_warn (_("Attempting to install GRUB to a disk with multiple partition labels. This is not supported yet."));
goto unable_to_embed;
if (dest_partmap == p->partmap)
return 0;
multiple_partmaps = 1;
return 1;
}
if (strcmp (dest_partmap, "msdos") == 0)
grub_partition_iterate (dest_dev->disk, find_usable_region_msdos);
else if (strcmp (dest_partmap, "gpt") == 0)
grub_partition_iterate (dest_dev->disk, find_usable_region_gpt);
else
grub_util_error (_("No DOS-style partitions found"));
grub_partition_iterate (dest_dev->disk, identify_partmap);
if (embed_region.end <= embed_region.start)
{
if (! strcmp (dest_partmap, "msdos"))
grub_util_warn (_("This msdos-style partition label has no post-MBR gap; embedding won't be possible!"));
else
grub_util_warn (_("This GPT partition label has no BIOS Boot Partition; embedding won't be possible!"));
goto unable_to_embed;
}
fs = grub_fs_probe (dest_dev);
if (!fs)
grub_errno = GRUB_ERR_NONE;
if ((unsigned long) core_sectors > embed_region.end - embed_region.start)
{
if (core_sectors > 62)
grub_util_warn (_("Your core.img is unusually large. It won't fit in the embedding area."));
else /* embed_region.end - embed_region.start < 62 */
grub_util_warn (_("Your embedding area is unusually small. core.img won't fit in it."));
goto unable_to_embed;
}
#ifdef GRUB_MACHINE_PCBIOS
if (fs_probe)
{
if (!fs && !dest_partmap)
grub_util_error (_("unable to identify a filesystem in %s; safety check can't be performed"),
dest_dev->disk->name);
if (fs && !fs->reserved_first_sector)
grub_util_error (_("%s appears to contain a %s filesystem which isn't known to "
"reserve space for DOS-style boot. Installing GRUB there could "
"result in FILESYSTEM DESTRUCTION if valuable data is overwritten "
"by grub-setup (--skip-fs-probe disables this "
"check, use at your own risk)"), dest_dev->disk->name, fs->name);
if (dest_partmap && strcmp (dest_partmap->name, "msdos") != 0
&& strcmp (dest_partmap->name, "gpt") != 0
&& strcmp (dest_partmap->name, "bsd") != 0
&& strcmp (dest_partmap->name, "netbsd") != 0
&& strcmp (dest_partmap->name, "openbsd") != 0
&& strcmp (dest_partmap->name, "sunpc") != 0)
grub_util_error (_("%s appears to contain a %s partition map which isn't known to "
"reserve space for DOS-style boot. Installing GRUB there could "
"result in FILESYSTEM DESTRUCTION if valuable data is overwritten "
"by grub-setup (--skip-fs-probe disables this "
"check, use at your own risk)"), dest_dev->disk->name, dest_partmap->name);
}
#endif
grub_util_info ("the core image will be embedded at sector 0x%llx", embed_region.start);
if (! dest_partmap)
{
grub_util_warn (_("Attempting to install GRUB to a partitionless disk. This is a BAD idea."));
goto unable_to_embed;
}
if (multiple_partmaps || fs)
{
grub_util_warn (_("Attempting to install GRUB to a disk with multiple partition labels or both partition label and filesystem. This is not supported yet."));
goto unable_to_embed;
}
*install_dos_part = grub_cpu_to_le32 (dos_part);
*install_bsd_part = grub_cpu_to_le32 (bsd_part);
if (prefix)
strcpy (install_prefix, prefix);
/* Copy the partition table. */
if (dest_partmap)
memcpy (boot_img + GRUB_BOOT_MACHINE_WINDOWS_NT_MAGIC,
tmp_img + GRUB_BOOT_MACHINE_WINDOWS_NT_MAGIC,
GRUB_BOOT_MACHINE_PART_END - GRUB_BOOT_MACHINE_WINDOWS_NT_MAGIC);
/* The first blocklist contains the whole sectors. */
first_block->start = grub_cpu_to_le64 (embed_region.start + 1);
free (tmp_img);
if (!dest_partmap->embed)
{
grub_util_warn ("Partition style '%s' doesn't support embeding",
dest_partmap->name);
goto unable_to_embed;
}
/* These are filled elsewhere. Verify them just in case. */
assert (first_block->len == grub_host_to_target16 (core_sectors - 1));
assert (first_block->segment == grub_host_to_target16 (GRUB_BOOT_MACHINE_KERNEL_SEG
+ (GRUB_DISK_SECTOR_SIZE >> 4)));
err = dest_partmap->embed (dest_dev->disk, core_sectors,
GRUB_EMBED_PCBIOS, sectors);
if (err)
{
grub_util_warn ("%s", grub_errmsg);
grub_errno = GRUB_ERR_NONE;
goto unable_to_embed;
}
/* Make sure that the second blocklist is a terminator. */
block = first_block - 1;
block->start = 0;
block->len = 0;
block->segment = 0;
save_first_sector (sectors[0] + grub_partition_get_start (container),
0, GRUB_DISK_SECTOR_SIZE);
/* Write the core image onto the disk. */
if (grub_disk_write (dest_dev->disk, embed_region.start, 0, core_size, core_img))
grub_util_error ("%s", grub_errmsg);
block = first_block;
for (i = 1; i < core_sectors; i++)
save_blocklists (sectors[i] + grub_partition_get_start (container),
0, GRUB_DISK_SECTOR_SIZE);
/* FIXME: can this be skipped? */
*boot_drive = 0xFF;
write_rootdev (core_img, root_dev, boot_img, first_sector);
*kernel_sector = grub_cpu_to_le64 (embed_region.start);
/* Make sure that the second blocklist is a terminator. */
block = first_block - 1;
block->start = 0;
block->len = 0;
block->segment = 0;
/* Write the boot image onto the disk. */
if (grub_disk_write (dest_dev->disk, 0, 0, GRUB_DISK_SECTOR_SIZE,
boot_img))
grub_util_error ("%s", grub_errmsg);
/* Write the core image onto the disk. */
for (i = 0; i < core_sectors; i++)
grub_disk_write (dest_dev->disk, sectors[i], 0,
(core_size - i * GRUB_DISK_SECTOR_SIZE
< GRUB_DISK_SECTOR_SIZE) ? core_size
- i * GRUB_DISK_SECTOR_SIZE
: GRUB_DISK_SECTOR_SIZE,
core_img + i * GRUB_DISK_SECTOR_SIZE);
goto finish;
goto finish;
}
#endif
unable_to_embed:
@ -434,6 +470,9 @@ unable_to_embed:
if (! force)
grub_util_error (_("if you really want blocklists, use --force"));
/* The core image must be put on a filesystem unfortunately. */
grub_util_info ("will leave the core image on the filesystem");
/* Make sure that GRUB reads the identical image as the OS. */
tmp_img = xmalloc (core_size);
core_path_dev_full = grub_util_get_path (dir, core_file);
@ -516,7 +555,9 @@ unable_to_embed:
{
block->start = 0;
block->len = 0;
#ifdef GRUB_MACHINE_PCBIOS
block->segment = 0;
#endif
block--;
@ -541,20 +582,39 @@ unable_to_embed:
!= (grub_ssize_t) core_size - GRUB_DISK_SECTOR_SIZE)
grub_util_error (_("failed to read the rest sectors of the core image"));
#ifdef GRUB_MACHINE_IEEE1275
{
char *boot_devpath;
boot_devpath = (char *) (boot_img
+ GRUB_BOOT_AOUT_HEADER_SIZE
+ GRUB_BOOT_MACHINE_BOOT_DEVPATH);
if (file->device->disk->id != dest_dev->disk->id)
{
const char *dest_ofpath;
dest_ofpath
= grub_util_devname_to_ofpath (grub_util_biosdisk_get_osdev (file->device->disk));
grub_util_info ("dest_ofpath is `%s'", dest_ofpath);
strncpy (boot_devpath, dest_ofpath, GRUB_BOOT_MACHINE_BOOT_DEVPATH_END
- GRUB_BOOT_MACHINE_BOOT_DEVPATH - 1);
boot_devpath[GRUB_BOOT_MACHINE_BOOT_DEVPATH_END
- GRUB_BOOT_MACHINE_BOOT_DEVPATH - 1] = 0;
}
else
{
grub_util_info ("non cross-disk install");
memset (boot_devpath, 0, GRUB_BOOT_MACHINE_BOOT_DEVPATH_END
- GRUB_BOOT_MACHINE_BOOT_DEVPATH);
}
grub_util_info ("boot device path %s", boot_devpath);
}
#endif
grub_file_close (file);
free (core_path_dev);
free (tmp_img);
*kernel_sector = grub_cpu_to_le64 (first_sector);
/* FIXME: can this be skipped? */
*boot_drive = 0xFF;
*install_dos_part = grub_cpu_to_le32 (dos_part);
*install_bsd_part = grub_cpu_to_le32 (bsd_part);
if (prefix)
strcpy (install_prefix, prefix);
write_rootdev (core_img, root_dev, boot_img, first_sector);
/* Write the first two sectors of the core image onto the disk. */
grub_util_info ("opening the core image `%s'", core_path);
@ -565,16 +625,17 @@ unable_to_embed:
grub_util_write_image (core_img, GRUB_DISK_SECTOR_SIZE * 2, fp);
fclose (fp);
finish:
/* Write the boot image onto the disk. */
if (grub_disk_write (dest_dev->disk, 0, 0, GRUB_DISK_SECTOR_SIZE, boot_img))
if (grub_disk_write (dest_dev->disk, BOOT_SECTOR,
0, GRUB_DISK_SECTOR_SIZE, boot_img))
grub_util_error ("%s", grub_errmsg);
finish:
/* Sync is a Good Thing. */
sync ();
free (prefix);
free (core_path);
free (core_img);
free (boot_img);
@ -646,14 +707,18 @@ get_device_name (char *dev)
int
main (int argc, char *argv[])
{
char *boot_file = 0;
char *core_file = 0;
char *dir = 0;
char *dev_map = 0;
char *root_dev = 0;
char *dest_dev;
char *boot_file = NULL;
char *core_file = NULL;
char *dir = NULL;
char *dev_map = NULL;
char *root_dev = NULL;
char *dest_dev = NULL;
int must_embed = 0, force = 0, fs_probe = 1;
#ifdef GRUB_MACHINE_IEEE1275
force = 1;
#endif
set_program_name (argv[0]);
grub_util_init_nls ();
@ -768,10 +833,15 @@ main (int argc, char *argv[])
fprintf (stderr, _("Invalid device `%s'.\n"), argv[optind]);
usage (1);
}
grub_util_info ("transformed OS device `%s' into GRUB device `%s'",
argv[optind], dest_dev);
}
else
/* For simplicity. */
dest_dev = xstrdup (dest_dev);
{
/* For simplicity. */
dest_dev = xstrdup (dest_dev);
grub_util_info ("Using `%s' as GRUB device", dest_dev);
}
if (root_dev)
{
@ -786,13 +856,18 @@ main (int argc, char *argv[])
}
else
{
root_dev = grub_util_get_grub_dev (grub_guess_root_device (dir ? : DEFAULT_DIRECTORY));
char *root_device = grub_guess_root_device (dir ? : DEFAULT_DIRECTORY);
root_dev = grub_util_get_grub_dev (root_device);
if (! root_dev)
{
grub_util_info ("guessing the root device failed, because of `%s'",
grub_errmsg);
grub_util_error (_("cannot guess the root device. Specify the option `--root-device'"));
}
grub_util_info ("guessed root device `%s' and root_dev `%s' from "
"dir `%s'", root_device, root_dev,
dir ? : DEFAULT_DIRECTORY);
}
#ifdef __linux__
@ -824,7 +899,7 @@ main (int argc, char *argv[])
}
else
#endif
/* Do the real work. */
/* Do the real work. */
setup (dir ? : DEFAULT_DIRECTORY,
boot_file ? : DEFAULT_BOOT_FILE,
core_file ? : DEFAULT_CORE_FILE,

View file

@ -247,6 +247,12 @@ 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}"

View file

@ -138,7 +138,12 @@ while [ "x$list" != "x" ] ; do
esac
case ${GRUB_FS} in
zfs) kfreebsd_device=$(grub-probe -t fs_label --device ${GRUB_DEVICE}) ;;
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=${GRUB_DEVICE} ;;
esac

View file

@ -1,261 +0,0 @@
#! /bin/sh
# Install GRUB on your EFI partition.
# Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2006,2007,2008 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/>.
# Initialize some variables.
transform="@program_transform_name@"
prefix=@prefix@
exec_prefix=@exec_prefix@
sbindir=@sbindir@
bindir=@bindir@
libdir=@libdir@
PACKAGE_NAME=@PACKAGE_NAME@
PACKAGE_TARNAME=@PACKAGE_TARNAME@
PACKAGE_VERSION=@PACKAGE_VERSION@
target_cpu=@target_cpu@
platform=@platform@
host_os=@host_os@
pkglibdir=${libdir}/`echo ${PACKAGE_TARNAME}/${target_cpu}-${platform} | sed ${transform}`
localedir=@datadir@/locale
self=`basename $0`
grub_mkimage=${bindir}/`echo grub-mkimage | sed ${transform}`
grub_mkdevicemap=${sbindir}/`echo grub-mkdevicemap | sed ${transform}`
grub_probe=${sbindir}/`echo grub-probe | sed ${transform}`
grub_editenv=${bindir}/`echo grub-editenv | sed ${transform}`
rootdir=
grub_prefix=`echo /boot/grub | sed ${transform}`
modules=
no_floppy=
force_lba=
recheck=no
debug=no
# Usage: usage
# Print the usage.
usage () {
cat <<EOF
Usage: $self [OPTION]
Install GRUB on your EFI partition.
-h, --help print this message and exit
-v, --version print the version information and exit
--modules=MODULES pre-load specified modules MODULES
--root-directory=DIR install GRUB images under the directory DIR
instead of the root directory
--grub-mkimage=FILE use FILE as grub-mkimage
--grub-mkdevicemap=FILE use FILE as grub-mkdevicemap
--grub-probe=FILE use FILE as grub-probe
--no-floppy do not probe any floppy drive
--recheck probe a device map even if it already exists
$self copies GRUB images into the DIR/boot directory specified by
--root-directory.
Report bugs to <bug-grub@gnu.org>.
EOF
}
argument () {
opt=$1
shift
if test $# -eq 0; then
echo "$0: option requires an argument -- '$opt'" 1>&2
exit 1
fi
echo $1
}
# Check the arguments.
while test $# -gt 0
do
option=$1
shift
case "$option" in
-h | --help)
usage
exit 0 ;;
-v | --version)
echo "$self (${PACKAGE_NAME}) ${PACKAGE_VERSION}"
exit 0 ;;
--modules)
modules=`argument $option "$@"`; shift ;;
--modules=*)
modules=`echo "$option" | sed 's/--modules=//'` ;;
--root-directory)
rootdir=`argument $option "$@"`; shift ;;
--root-directory=*)
rootdir=`echo "$option" | sed 's/--root-directory=//'` ;;
--grub-mkimage)
grub_mkimage=`argument $option "$@"`; shift ;;
--grub-mkimage=*)
grub_mkimage=`echo "$option" | sed 's/--grub-mkimage=//'` ;;
--grub-mkdevicemap)
grub_mkdevicemap=`argument $option "$@"`; shift ;;
--grub-mkdevicemap=*)
grub_mkdevicemap=`echo "$option" | sed 's/--grub-mkdevicemap=//'` ;;
--grub-probe)
grub_probe=`argument $option "$@"`; shift ;;
--grub-probe=*)
grub_probe=`echo "$option" | sed 's/--grub-probe=//'` ;;
--no-floppy)
no_floppy="--no-floppy" ;;
--recheck)
recheck=yes ;;
# This is an undocumented feature...
--debug)
debug=yes ;;
*)
echo "Unrecognized option \`$option'" 1>&2
usage
exit 1
;;
esac
done
# If the debugging feature is enabled, print commands.
if test $debug = yes; then
set -x
fi
# Initialize these directories here, since ROOTDIR was initialized.
case "$host_os" in
netbsd* | openbsd*)
# Because /boot is used for the boot block in NetBSD and OpenBSD, use /grub
# instead of /boot/grub.
grub_prefix=`echo /grub | sed ${transform}`
bootdir=${rootdir}
;;
*)
# Use /boot/grub by default.
bootdir=${rootdir}/boot
;;
esac
grubdir=${bootdir}/`echo grub | sed ${transform}`
device_map=${grubdir}/device.map
# Check if GRUB is installed.
set $grub_mkimage dummy
if test -f "$1"; then
:
else
echo "$1: Not found." 1>&2
exit 1
fi
set $grub_mkdevicemap dummy
if test -f "$1"; then
:
else
echo "$1: Not found." 1>&2
exit 1
fi
# Create the GRUB directory if it is not present.
mkdir -p "$grubdir" || exit 1
# If --recheck is specified, remove the device map, if present.
if test $recheck = yes; then
rm -f $device_map
fi
# Create the device map file if it is not present.
if test -f "$device_map"; then
:
else
# Create a safe temporary file.
test -n "$mklog" && log_file=`$mklog`
$grub_mkdevicemap --device-map=$device_map $no_floppy || exit 1
fi
# Make sure that there is no duplicated entry.
tmp=`sed -n '/^([fh]d[0-9]*)/s/\(^(.*)\).*/\1/p' $device_map \
| sort | uniq -d | sed -n 1p`
if test -n "$tmp"; then
echo "The drive $tmp is defined multiple times in the device map $device_map" 1>&2
exit 1
fi
# Copy the GRUB images to the GRUB directory.
for file in ${grubdir}/*.mod ${grubdir}/*.lst; do
if test -f $file && [ "`basename $file`" != menu.lst ]; then
rm -f $file || exit 1
fi
done
for file in ${pkglibdir}/*.mod ${pkglibdir}/*.lst; do
cp -f $file ${grubdir} || exit 1
done
# Copy gettext files
mkdir -p ${grubdir}/locale/
for dir in ${localedir}/*; do
if test -f "$dir/LC_MESSAGES/grub.mo"; then
cp -f "$dir/LC_MESSAGES/grub.mo" "${grubdir}/locale/${dir##*/}.mo"
fi
done
if ! test -f ${grubdir}/grubenv; then
$grub_editenv ${grubdir}/grubenv create
fi
# Create the core image. First, auto-detect the filesystem module.
fs_module=`$grub_probe --target=fs --device-map=${device_map} ${grubdir}`
if test "x$fs_module" = xfat; then :; else
echo "${grubdir} doesn't look like an EFI partition." 1>&2
exit 1
fi
# Then the partition map module. In order to support partition-less media,
# this command is allowed to fail (--target=fs already grants us that the
# filesystem will be accessible).
partmap_module=
for x in `$grub_probe --target=partmap --device-map=${device_map} ${grubdir} 2> /dev/null`; do
partmap_module="$partmap_module part_$x";
done
# Device abstraction module, if any (lvm, raid).
devabstraction_module=`$grub_probe --target=abstraction --device-map=${device_map} ${grubdir}`
# The order in this list is critical. Be careful when modifying it.
modules="$modules $fs_module $partmap_module $devabstraction_module"
$grub_mkimage -p "" -O ${target_cpu}-efi --output=${grubdir}/grub.efi $modules || exit 1
# Prompt the user to check if the device map is correct.
echo "Installation finished. No error reported."
echo "This is the contents of the device map $device_map."
echo "Check if this is correct or not. If any of the lines is incorrect,"
echo "fix it and re-run the script \`$self'."
echo
cat $device_map
# Bye.
exit 0

View file

@ -1,273 +0,0 @@
#! /bin/sh
# Install GRUB on your drive.
# Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2006,2007,2008 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/>.
# This script uses `ofpathname', which is downloadable from
# http://ppc64-utils.ozlabs.org .
# Initialize some variables.
transform="@program_transform_name@"
prefix=@prefix@
exec_prefix=@exec_prefix@
sbindir=@sbindir@
bindir=@bindir@
libdir=@libdir@
PACKAGE_NAME=@PACKAGE_NAME@
PACKAGE_TARNAME=@PACKAGE_TARNAME@
PACKAGE_VERSION=@PACKAGE_VERSION@
target_cpu=@target_cpu@
platform=@platform@
pkglibdir=${libdir}/`echo ${PACKAGE_TARNAME}/${target_cpu}-${platform} | sed ${transform}`
self=`basename $0`
grub_mkimage=${bindir}/`echo grub-mkimage | sed ${transform}`
grub_mkdevicemap=${sbindir}/`echo grub-mkdevicemap | sed ${transform}`
grub_probe=${sbindir}/`echo grub-probe | sed ${transform}`
grub_editenv=${bindir}/`echo grub-editenv | sed ${transform}`
rootdir=
grub_prefix=`echo /boot/grub | sed ${transform}`
modules=
install_device=
debug=no
update_nvram=yes
ofpathname=`which ofpathname`
nvsetenv=`which nvsetenv`
# Usage: usage
# Print the usage.
usage () {
cat <<EOF
Usage: $self [OPTION] [install_device]
Install GRUB on your drive.
-h, --help print this message and exit
-v, --version print the version information and exit
--modules=MODULES pre-load specified modules MODULES
--root-directory=DIR install GRUB images under the directory DIR
instead of the root directory
--grub-mkdevicemap=FILE use FILE as grub-mkdevicemap
--grub-mkimage=FILE use FILE as grub-mkimage
--grub-probe=FILE use FILE as grub-probe
--no-nvram don't update the boot-device NVRAM variable
$self copies GRUB images into the DIR/boot directory specified by
--root-directory, and uses nvsetenv to set the Open Firmware boot-device
variable.
Report bugs to <bug-grub@gnu.org>.
EOF
}
argument () {
opt=$1
shift
if test $# -eq 0; then
echo "$0: option requires an argument -- '$opt'" 1>&2
exit 1
fi
echo $1
}
# Check the arguments.
while test $# -gt 0
do
option=$1
shift
case "$option" in
-h | --help)
usage
exit 0 ;;
-v | --version)
echo "$self (${PACKAGE_NAME}) ${PACKAGE_VERSION}"
exit 0 ;;
--modules)
modules=`argument $option "$@"`; shift ;;
--modules=*)
modules=`echo "$option" | sed 's/--modules=//'` ;;
--root-directory)
rootdir=`argument $option "$@"`; shift ;;
--root-directory=*)
rootdir=`echo "$option" | sed 's/--root-directory=//'` ;;
--grub-mkdevicemap)
grub_mkdevicemap=`argument $option "$@"`; shift ;;
--grub-mkdevicemap=*)
grub_mkdevicemap=`echo "$option" | sed 's/--grub-mkdevicemap=//'` ;;
--grub-mkimage)
grub_mkimage=`argument $option "$@"`; shift ;;
--grub-mkimage=*)
grub_mkimage=`echo "$option" | sed 's/--grub-mkimage=//'` ;;
--grub-probe)
grub_probe=`argument $option "$@"`; shift ;;
--grub-probe=*)
grub_probe=`echo "$option" | sed 's/--grub-probe=//'` ;;
--no-nvram)
update_nvram=no ;;
# This is an undocumented feature...
--debug)
debug=yes ;;
-*)
echo "Unrecognized option \`$option'" 1>&2
usage
exit 1
;;
*)
if test "x$install_device" != x; then
echo "More than one install_devices?" 1>&2
usage
exit 1
fi
install_device="${option}" ;;
esac
done
# If the debugging feature is enabled, print commands.
if test $debug = yes; then
set -x
fi
# Initialize these directories here, since ROOTDIR was initialized.
bootdir=${rootdir}/boot
grubdir=${bootdir}/`echo grub | sed ${transform}`
device_map=${grubdir}/device.map
set $grub_mkimage dummy
if test -f "$1"; then
:
else
echo "$1: Not found." 1>&2
exit 1
fi
# Find the partition at the right mount point.
install_device=`$grub_mkdevicemap --device-map=/dev/stdout | $grub_probe --target=device --device-map=/dev/stdin ${grubdir}`
if test "x$install_device" = "x`$grub_mkdevicemap --device-map=/dev/stdout | $grub_probe --target=device --device-map=/dev/stdin ${bootdir}`"; then
echo "$grubdir must be a mount point."
exit 1
fi
# XXX warn on firmware-unreadable filesystems?
# Create the GRUB directory if it is not present.
mkdir -p "$grubdir" || exit 1
# Create the device map file if it is not present.
if test -f "$device_map"; then
:
else
# Create a safe temporary file.
test -n "$mklog" && log_file=`$mklog`
$grub_mkdevicemap --device-map=$device_map $no_floppy || exit 1
fi
# Copy the GRUB images to the GRUB directory.
for file in ${grubdir}/*.mod ${grubdir}/*.lst ; do
if test -f $file; then
rm -f $file || exit 1
fi
done
for file in ${pkglibdir}/*.mod ${pkglibdir}/*.lst ; do
cp -f $file ${grubdir} || exit 1
done
if ! test -f ${grubdir}/grubenv; then
$grub_editenv ${grubdir}/grubenv create
fi
# Create the core image. First, auto-detect the filesystem module.
fs_module=`$grub_probe --target=fs --device-map=${device_map} ${grubdir}`
if test "x$fs_module" = x -a "x$modules" = x; then
echo "Auto-detection of a filesystem module failed." 1>&2
echo "Please specify the module with the option \`--modules' explicitly." 1>&2
exit 1
fi
# Then the partition map module. In order to support partition-less media,
# this command is allowed to fail (--target=fs already grants us that the
# filesystem will be accessible).
partmap_module=
for x in `$grub_probe --target=partmap --device-map=${device_map} ${grubdir} 2> /dev/null`; do
partmap_module="$partmap_module part_$x";
done
# Device abstraction module, if any (lvm, raid).
devabstraction_module=`$grub_probe --target=abstraction --device-map=${device_map} ${grubdir}`
modules="$modules $fs_module $partmap_module $devabstraction_module"
# Now perform the installation.
"$grub_mkimage" -O ${target_cpu}-ieee1275 --directory=${pkglibdir} --output=${grubdir}/grub $modules || exit 1
if test $update_nvram = yes; then
set $ofpathname dummy
if test -f "$1"; then
:
else
echo "$1: Not found." 1>&2
exit 1
fi
set $nvsetenv dummy
if test -f "$1"; then
:
else
echo "$1: Not found." 1>&2
exit 1
fi
# Get the Open Firmware device tree path translation.
dev=`echo $install_device | sed -e 's/\/dev\///' -e 's/[0-9]\+//'`
partno=`echo $install_device | sed -e 's/.*[^0-9]\([0-9]\+\)$/\1/'`
ofpath=`$ofpathname $dev` || {
echo "Couldn't find Open Firmware device tree path for $dev."
echo "You will have to set boot-device manually."
exit 1
}
# Point boot-device at the new grub install
boot_device="$ofpath:$partno,\\grub"
"$nvsetenv" boot-device "$boot_device" || {
echo "$nvsetenv failed."
echo "You will have to set boot-device manually. At the Open Firmware prompt, type:"
echo " setenv boot-device $boot_device"
exit 1
}
fi
# Prompt the user to check if the device map is correct.
echo "Installation finished. No error reported."
echo "This is the contents of the device map $device_map."
echo "Check if this is correct or not. If any of the lines is incorrect,"
echo "fix it and re-run the script \`$self'."
echo
cat $device_map
# Bye.
exit 0

View file

@ -22,40 +22,19 @@
#include <grub/emu/misc.h>
#include <grub/util/misc.h>
#include <grub/util/raid.h>
#include <grub/emu/getroot.h>
#include <string.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <errno.h>
#include <sys/types.h>
#include <linux/types.h>
#include <linux/major.h>
#include <linux/raid/md_p.h>
#include <linux/raid/md_u.h>
static char *
grub_util_getdiskname (int major, int minor)
{
char *name = xmalloc (15);
if (major == LOOP_MAJOR)
sprintf (name, "/dev/loop%d", minor);
else if (major == IDE0_MAJOR)
sprintf (name, "/dev/hd%c", 'a' + minor / 64);
else if (major == IDE1_MAJOR)
sprintf (name, "/dev/hd%c", 'c' + minor / 64);
else if (major == IDE2_MAJOR)
sprintf (name, "/dev/hd%c", 'e' + minor / 64);
else if (major == IDE3_MAJOR)
sprintf (name, "/dev/hd%c", 'g' + minor / 64);
else if (major == SCSI_DISK0_MAJOR)
sprintf (name, "/dev/sd%c", 'a' + minor / 16);
else
grub_util_error ("unknown device number: %d, %d", major, minor);
return name;
}
char **
grub_util_raid_getmembers (char *name)
{
@ -100,7 +79,8 @@ grub_util_raid_getmembers (char *name)
if (disk.state & (1 << MD_DISK_ACTIVE))
{
devicelist[j] = grub_util_getdiskname (disk.major, disk.minor);
devicelist[j] = grub_find_device (NULL,
makedev (disk.major, disk.minor));
j++;
}
}

View file

@ -1,644 +0,0 @@
/* grub-setup.c - make GRUB usable */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 1999,2000,2001,2002,2003,2004,2005,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/>.
*/
#include <config.h>
#include <grub/types.h>
#include <grub/emu/misc.h>
#include <grub/util/misc.h>
#include <grub/device.h>
#include <grub/i18n.h>
#include <grub/disk.h>
#include <grub/file.h>
#include <grub/fs.h>
#include <grub/partition.h>
#include <grub/msdos_partition.h>
#include <grub/gpt_partition.h>
#include <grub/env.h>
#include <grub/emu/hostdisk.h>
#include <grub/machine/boot.h>
#include <grub/machine/kernel.h>
#include <grub/term.h>
#include <grub/util/raid.h>
#include <grub/util/lvm.h>
#include <grub/util/ofpath.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>
#include <grub/emu/getroot.h>
#define _GNU_SOURCE 1
#include <getopt.h>
#include "progname.h"
/* This program fills in various fields inside of the 'boot' and 'core'
* image files.
*
* The 'boot' image needs to know the OBP path name of the root
* device. It also needs to know the initial block number of
* 'core' (which is 'diskboot' concatenated with 'kernel' and
* all the modules, this is created by grub-mkimage). This resulting
* 'boot' image is 512 bytes in size and is placed in the second block
* of a partition.
*
* The initial 'diskboot' block acts as a loader for the actual GRUB
* kernel. It contains the loading code and then a block list.
*
* The block list of 'core' starts at the end of the 'diskboot' image
* and works it's way backwards towards the end of the code of 'diskboot'.
*
* We patch up the images with the necessary values and write out the
* result.
*/
#define DEFAULT_BOOT_FILE "boot.img"
#define DEFAULT_CORE_FILE "core.img"
#define grub_target_to_host16(x) grub_be_to_cpu16(x)
#define grub_target_to_host32(x) grub_be_to_cpu32(x)
#define grub_target_to_host64(x) grub_be_to_cpu64(x)
#define grub_host_to_target16(x) grub_cpu_to_be16(x)
#define grub_host_to_target32(x) grub_cpu_to_be32(x)
#define grub_host_to_target64(x) grub_cpu_to_be64(x)
/* This is the blocklist used in the diskboot image. */
struct boot_blocklist
{
grub_uint64_t start;
grub_uint32_t len;
} __attribute__ ((packed));
static void
setup (const char *prefix, const char *dir,
const char *boot_file, const char *core_file,
const char *root, const char *dest)
{
char *boot_path, *core_path;
char *boot_img, *core_img;
size_t boot_size, core_size;
grub_uint16_t core_sectors;
grub_device_t root_dev, dest_dev;
char *boot_devpath;
grub_disk_addr_t *kernel_byte;
struct boot_blocklist *first_block, *block;
char *tmp_img;
int i;
grub_disk_addr_t first_sector;
grub_uint16_t last_length = GRUB_DISK_SECTOR_SIZE;
grub_file_t file;
FILE *fp;
struct { grub_uint64_t start; grub_uint64_t end; } embed_region;
embed_region.start = embed_region.end = ~0UL;
auto void NESTED_FUNC_ATTR save_first_sector (grub_disk_addr_t sector,
unsigned int offset,
unsigned int length);
auto void NESTED_FUNC_ATTR save_blocklists (grub_disk_addr_t sector,
unsigned int offset,
unsigned int length);
void NESTED_FUNC_ATTR save_first_sector (grub_disk_addr_t sector,
unsigned int offset,
unsigned int length)
{
grub_util_info ("first sector is <%llu,%u,%u>", sector, offset, length);
if (offset != 0 || length != GRUB_DISK_SECTOR_SIZE)
grub_util_error ("the first sector of the core file "
"is not sector-aligned");
first_sector = sector;
}
void NESTED_FUNC_ATTR save_blocklists (grub_disk_addr_t sector,
unsigned int offset,
unsigned int length)
{
struct boot_blocklist *prev = block + 1;
grub_util_info ("saving <%llu,%u,%u>", sector, offset, length);
if (offset != 0 || last_length != GRUB_DISK_SECTOR_SIZE)
grub_util_error ("non-sector-aligned data is found in the core file");
if (block != first_block
&& (grub_be_to_cpu64 (prev->start)
+ grub_be_to_cpu16 (prev->len)) == sector)
prev->len = grub_cpu_to_be16 (grub_be_to_cpu16 (prev->len) + 1);
else
{
block->start = grub_cpu_to_be64 (sector);
block->len = grub_cpu_to_be16 (1);
block--;
if (block->len)
grub_util_error ("the sectors of the core file are too fragmented");
}
last_length = length;
}
/* Read the boot image by the OS service. */
boot_path = grub_util_get_path (dir, boot_file);
boot_size = grub_util_get_image_size (boot_path);
if (boot_size != GRUB_DISK_SECTOR_SIZE)
grub_util_error ("the size of `%s' is not %d",
boot_path, GRUB_DISK_SECTOR_SIZE);
boot_img = grub_util_read_image (boot_path);
free (boot_path);
/* Set the addresses of variables in the boot image. */
boot_devpath = (char *) (boot_img
+ GRUB_BOOT_AOUT_HEADER_SIZE
+ GRUB_BOOT_MACHINE_BOOT_DEVPATH);
kernel_byte = (grub_disk_addr_t *) (boot_img
+ GRUB_BOOT_AOUT_HEADER_SIZE
+ GRUB_BOOT_MACHINE_KERNEL_BYTE);
core_path = grub_util_get_path (dir, core_file);
core_size = grub_util_get_image_size (core_path);
core_sectors = ((core_size + GRUB_DISK_SECTOR_SIZE - 1)
>> GRUB_DISK_SECTOR_BITS);
if (core_size < GRUB_DISK_SECTOR_SIZE)
grub_util_error ("the size of `%s' is too small", core_path);
core_img = grub_util_read_image (core_path);
free (core_path);
/* Have FIRST_BLOCK to point to the first blocklist. */
first_block = (struct boot_blocklist *) (core_img
+ GRUB_DISK_SECTOR_SIZE
- sizeof (*block));
grub_util_info ("root is `%s', dest is `%s'", root, dest);
/* Open the root device and the destination device. */
grub_util_info ("Opening root");
root_dev = grub_device_open (root);
if (! root_dev)
grub_util_error ("%s", grub_errmsg);
grub_util_info ("Opening dest");
dest_dev = grub_device_open (dest);
if (! dest_dev)
grub_util_error ("%s", grub_errmsg);
grub_util_info ("setting the root device to `%s'", root);
if (grub_env_set ("root", root) != GRUB_ERR_NONE)
grub_util_error ("%s", grub_errmsg);
/* The core image must be put on a filesystem unfortunately. */
grub_util_info ("will leave the core image on the filesystem");
/* Make sure that GRUB reads the identical image as the OS. */
tmp_img = xmalloc (core_size);
core_path = grub_util_get_path (prefix, core_file);
/* It is a Good Thing to sync two times. */
sync ();
sync ();
#define MAX_TRIES 5
for (i = 0; i < MAX_TRIES; i++)
{
grub_util_info ("attempting to read the core image `%s' from GRUB%s",
core_path, (i == 0) ? "" : " again");
grub_disk_cache_invalidate_all ();
grub_file_filter_disable_compression ();
file = grub_file_open (core_path);
if (file)
{
if (grub_file_size (file) != core_size)
grub_util_info ("succeeded in opening the core image but the size is different (%d != %d)",
(int) grub_file_size (file), (int) core_size);
else if (grub_file_read (file, tmp_img, core_size)
!= (grub_ssize_t) core_size)
grub_util_info ("succeeded in opening the core image but cannot read %d bytes",
(int) core_size);
else if (memcmp (core_img, tmp_img, core_size) != 0)
{
#if 0
FILE *dump;
FILE *dump2;
dump = fopen ("dump.img", "wb");
if (dump)
{
fwrite (tmp_img, 1, core_size, dump);
fclose (dump);
}
dump2 = fopen ("dump2.img", "wb");
if (dump2)
{
fwrite (core_img, 1, core_size, dump2);
fclose (dump2);
}
#endif
grub_util_info ("succeeded in opening the core image but the data is different");
}
else
{
grub_file_close (file);
break;
}
grub_file_close (file);
}
else
grub_util_info ("couldn't open the core image");
if (grub_errno)
grub_util_info ("error message = %s", grub_errmsg);
grub_errno = GRUB_ERR_NONE;
sync ();
sleep (1);
}
if (i == MAX_TRIES)
grub_util_error ("cannot read `%s' correctly", core_path);
/* Clean out the blocklists. */
block = first_block;
while (block->len)
{
block->start = 0;
block->len = 0;
block--;
if ((char *) block <= core_img)
grub_util_error ("no terminator in the core image");
}
/* Now read the core image to determine where the sectors are. */
grub_file_filter_disable_compression ();
file = grub_file_open (core_path);
if (! file)
grub_util_error ("%s", grub_errmsg);
file->read_hook = save_first_sector;
if (grub_file_read (file, tmp_img, GRUB_DISK_SECTOR_SIZE)
!= GRUB_DISK_SECTOR_SIZE)
grub_util_error ("failed to read the first sector of the core image");
block = first_block;
file->read_hook = save_blocklists;
if (grub_file_read (file, tmp_img, core_size - GRUB_DISK_SECTOR_SIZE)
!= (grub_ssize_t) core_size - GRUB_DISK_SECTOR_SIZE)
grub_util_error ("failed to read the rest sectors of the core image");
if (file->device->disk->id != dest_dev->disk->id)
{
const char *dest_ofpath;
dest_ofpath
= grub_util_devname_to_ofpath (grub_util_biosdisk_get_osdev (file->device->disk));
grub_util_info ("dest_ofpath is `%s'", dest_ofpath);
strncpy (boot_devpath, dest_ofpath, GRUB_BOOT_MACHINE_BOOT_DEVPATH_END
- GRUB_BOOT_MACHINE_BOOT_DEVPATH - 1);
boot_devpath[GRUB_BOOT_MACHINE_BOOT_DEVPATH_END
- GRUB_BOOT_MACHINE_BOOT_DEVPATH - 1] = 0;
}
else
{
grub_util_info ("non cross-disk install");
memset (boot_devpath, 0, GRUB_BOOT_MACHINE_BOOT_DEVPATH_END
- GRUB_BOOT_MACHINE_BOOT_DEVPATH);
}
grub_file_close (file);
free (core_path);
free (tmp_img);
*kernel_byte = grub_cpu_to_be64 (first_sector << GRUB_DISK_SECTOR_BITS);
grub_util_info ("boot device path %s, prefix is %s, dest is %s",
boot_devpath, prefix, dest);
/* Write the first two sectors of the core image onto the disk. */
core_path = grub_util_get_path (dir, core_file);
grub_util_info ("opening the core image `%s'", core_path);
fp = fopen (core_path, "r+b");
if (! fp)
grub_util_error ("cannot open `%s'", core_path);
grub_util_write_image (core_img, GRUB_DISK_SECTOR_SIZE, fp);
fclose (fp);
free (core_path);
/* Write the boot image onto the disk. */
if (grub_disk_write (dest_dev->disk, 1, 0, GRUB_DISK_SECTOR_SIZE, boot_img))
grub_util_error ("%s", grub_errmsg);
/* Sync is a Good Thing. */
sync ();
free (core_img);
free (boot_img);
grub_device_close (dest_dev);
grub_device_close (root_dev);
}
static struct option options[] =
{
{"boot-image", required_argument, 0, 'b'},
{"core-image", required_argument, 0, 'c'},
{"directory", required_argument, 0, 'd'},
{"device-map", required_argument, 0, 'm'},
{"root-device", required_argument, 0, 'r'},
{"help", no_argument, 0, 'h'},
{"version", no_argument, 0, 'V'},
{"verbose", no_argument, 0, 'v'},
{0, 0, 0, 0}
};
static void
usage (int status)
{
if (status)
fprintf (stderr, "Try `%s --help' for more information.\n", program_name);
else
printf ("\
Usage: %s [OPTION]... DEVICE\n\
\n\
Set up images to boot from DEVICE.\n\
DEVICE must be a GRUB device (e.g. `(hd0,1)').\n\
\n\
You should not normally run %s directly. Use grub-install instead.\n\
\n\
-b, --boot-image=FILE use FILE as the boot image [default=%s]\n\
-c, --core-image=FILE use FILE as the core image [default=%s]\n\
-d, --directory=DIR use GRUB files in the directory DIR [default=%s]\n\
-m, --device-map=FILE use FILE as the device map [default=%s]\n\
-r, --root-device=DEV use DEV as the root device [default=guessed]\n\
-h, --help display this message and exit\n\
-V, --version print version information and exit\n\
-v, --verbose print verbose messages\n\
\n\
Report bugs to <%s>.\n\
", program_name, program_name,
DEFAULT_BOOT_FILE, DEFAULT_CORE_FILE, DEFAULT_DIRECTORY,
DEFAULT_DEVICE_MAP, PACKAGE_BUGREPORT);
exit (status);
}
struct grub_setup_info
{
char *boot_file;
char *core_file;
char *dir;
char *dev_map;
char *root_dev;
char *prefix;
char *dest_dev;
};
static void
init_info (struct grub_setup_info *gp)
{
gp->boot_file = NULL;
gp->core_file = NULL;
gp->dir = NULL;
gp->dev_map = NULL;
gp->root_dev = NULL;
gp->prefix = NULL;
gp->dest_dev = NULL;
}
static int
parse_options (struct grub_setup_info *gp, int argc, char *argv[])
{
while (1)
{
int c = getopt_long (argc, argv, "b:c:d:m:r:hVv", options, 0);
if (c == -1)
break;
else
switch (c)
{
case 'b':
if (gp->boot_file)
free (gp->boot_file);
gp->boot_file = xstrdup (optarg);
break;
case 'c':
if (gp->core_file)
free (gp->core_file);
gp->core_file = xstrdup (optarg);
break;
case 'd':
if (gp->dir)
free (gp->dir);
gp->dir = xstrdup (optarg);
break;
case 'm':
if (gp->dev_map)
free (gp->dev_map);
gp->dev_map = xstrdup (optarg);
break;
case 'r':
if (gp->root_dev)
free (gp->root_dev);
gp->root_dev = xstrdup (optarg);
break;
case 'h':
usage (0);
break;
case 'V':
printf ("%s (%s) %s\n", program_name, PACKAGE_NAME, PACKAGE_VERSION);
return 0;
case 'v':
verbosity++;
break;
default:
usage (1);
break;
}
}
if (verbosity > 1)
grub_env_set ("debug", "all");
if (optind >= argc)
{
fprintf (stderr, "No device is specified.\n");
usage (1);
}
if (optind + 1 != argc)
{
fprintf (stderr, "Unknown extra argument `%s'.\n", argv[optind + 1]);
usage (1);
}
return 1;
}
static char *
get_device_name (char *dev)
{
size_t len = strlen (dev);
if (dev[0] != '(' || dev[len - 1] != ')')
return 0;
dev[len - 1] = '\0';
return dev + 1;
}
static void
find_dest_dev (struct grub_setup_info *gp, char *argv[])
{
gp->dest_dev = get_device_name (argv[optind]);
if (! gp->dest_dev)
{
/* Possibly, the user specified an OS device file. */
gp->dest_dev = grub_util_get_grub_dev (argv[optind]);
if (! gp->dest_dev)
{
fprintf (stderr, "Invalid device `%s'.\n", argv[optind]);
usage (1);
}
grub_util_info ("transformed OS device `%s' into GRUB device `%s'",
argv[optind], gp->dest_dev);
}
else
{
/* For simplicity. */
gp->dest_dev = xstrdup (gp->dest_dev);
grub_util_info ("Using `%s' as GRUB device", gp->dest_dev);
}
}
static void
check_root_dev (struct grub_setup_info *gp)
{
if (gp->root_dev)
{
char *tmp = get_device_name (gp->root_dev);
if (! tmp)
grub_util_error ("invalid root device `%s'", gp->root_dev);
tmp = xstrdup (tmp);
free (gp->root_dev);
gp->root_dev = tmp;
}
else
{
char *dir = gp->dir ? gp->dir : DEFAULT_DIRECTORY;
char *root_device = grub_guess_root_device (dir);
gp->root_dev = grub_util_get_grub_dev (root_device);
if (! gp->root_dev)
{
grub_util_info ("guessing the root device failed, because of `%s'",
grub_errmsg);
grub_util_error ("cannot guess the root device. "
"Specify the option `--root-device'");
}
grub_util_info ("guessed root device `%s' and root_dev `%s' from "
"dir `%s'", root_device, gp->root_dev, dir);
}
}
static void
free_memory (struct grub_setup_info *gp)
{
free (gp->boot_file);
free (gp->core_file);
free (gp->dir);
free (gp->dev_map);
free (gp->root_dev);
free (gp->prefix);
free (gp->dest_dev);
}
int
main (int argc, char *argv[])
{
struct grub_setup_info ginfo;
set_program_name (argv[0]);
grub_util_init_nls ();
init_info (&ginfo);
if (!parse_options (&ginfo, argc, argv))
return 0;
/* Initialize the emulated biosdisk driver. */
grub_util_biosdisk_init (ginfo.dev_map ? ginfo.dev_map : DEFAULT_DEVICE_MAP);
/* Initialize all modules. */
grub_init_all ();
grub_lvm_fini ();
grub_mdraid_fini ();
grub_raid_fini ();
grub_raid_init ();
grub_mdraid_init ();
grub_lvm_init ();
find_dest_dev (&ginfo, argv);
ginfo.prefix = grub_make_system_path_relative_to_its_root (ginfo.dir ?
: DEFAULT_DIRECTORY);
check_root_dev (&ginfo);
/* Do the real work. */
setup (ginfo.prefix,
ginfo.dir ? ginfo.dir : DEFAULT_DIRECTORY,
ginfo.boot_file ? ginfo.boot_file : DEFAULT_BOOT_FILE,
ginfo.core_file ? ginfo.core_file : DEFAULT_CORE_FILE,
ginfo.root_dev, ginfo.dest_dev);
/* Free resources. */
grub_fini_all ();
free_memory (&ginfo);
return 0;
}