merge mainline into legacy_parser
This commit is contained in:
commit
0cb2f2813f
124 changed files with 3369 additions and 1991 deletions
13
util/bash-completion.d/Makefile.am
Normal file
13
util/bash-completion.d/Makefile.am
Normal 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=$@:$<
|
467
util/bash-completion.d/grub-completion.bash.in
Normal file
467
util/bash-completion.d/grub-completion.bash.in
Normal file
|
@ -0,0 +1,467 @@
|
|||
#
|
||||
# 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
|
||||
# - 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 $($prog --help)
|
||||
do
|
||||
case $i in
|
||||
--*) echo "${i%=*}";;
|
||||
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 "$($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 "$($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
|
|
@ -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);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#! /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.
|
||||
# Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009 Free Software Foundation, Inc.
|
||||
#
|
||||
# GRUB is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
|
@ -327,7 +327,8 @@ if test "x$fs_module" = x -a "x$modules" = x; then
|
|||
fi
|
||||
|
||||
# Then the partition map module. In order to support partition-less media,
|
||||
# this command is allowed to fail.
|
||||
# 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 ${grub_device} 2> /dev/null`; do
|
||||
partmap_module="$partmap_module part_$x";
|
||||
|
@ -405,24 +406,9 @@ case "${target_cpu}-${platform}" in
|
|||
*) mkimage_target=i386-coreboot;
|
||||
esac
|
||||
|
||||
# Verify readability of a few critical files
|
||||
for file in grubenv normal.mod ; do
|
||||
if is_path_readable_by_grub ${grubdir}/${file} ${grub_device} ${relative_grubdir}/${file} ; then : ; else
|
||||
echo "GRUB is unable to read ${grubdir}/${file}" >&2
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
|
||||
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
|
||||
|
||||
# This is a temporary workaround; it can be merged back into the check
|
||||
# above once the install branch is merged.
|
||||
if is_path_readable_by_grub ${grubdir}/core.img ${grub_device} ${relative_grubdir}/core.img ; then : ; else
|
||||
echo "GRUB is unable to read ${grubdir}/core.img" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Now perform the installation.
|
||||
$grub_setup ${setup_verbose} ${setup_force} --directory=${grubdir} --device-map=${device_map} \
|
||||
${install_device} || exit 1
|
||||
|
|
|
@ -303,14 +303,6 @@ for i in ${grub_mkconfig_dir}/* ; do
|
|||
esac
|
||||
done
|
||||
|
||||
# Verify readability of ${grub_cfg}.new
|
||||
if test "x${grub_cfg}" != "x"; then
|
||||
if is_path_readable_by_grub ${grub_cfg}.new ; then : ; else
|
||||
echo "GRUB is unable to read ${grubdir}/${file}" >&2
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
if test "x${grub_cfg}" != "x" ; then
|
||||
# none of the children aborted with error, install the new grub.cfg
|
||||
mv -f ${grub_cfg}.new ${grub_cfg}
|
||||
|
|
|
@ -30,9 +30,6 @@ fi
|
|||
if test "x$grub_mkrelpath" = x; then
|
||||
grub_mkrelpath=${bindir}/`echo grub-mkrelpath | sed ${transform}`
|
||||
fi
|
||||
if test "x$grub_fstest" = x; then
|
||||
grub_fstest=${bindir}/`echo grub-fstest | sed ${transform}`
|
||||
fi
|
||||
|
||||
if $(which gettext >/dev/null 2>/dev/null) ; then
|
||||
gettext="gettext"
|
||||
|
@ -53,24 +50,14 @@ make_system_path_relative_to_its_root ()
|
|||
is_path_readable_by_grub ()
|
||||
{
|
||||
path=$1
|
||||
device=$2
|
||||
relpath=$3
|
||||
|
||||
# abort if path doesn't exist
|
||||
if test -e $path ; then : ;else
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [ "${device}" = "" ] ; then
|
||||
device=$(${grub_probe} --target=device $path)
|
||||
fi
|
||||
if [ "${relpath}" = "" ] ; then
|
||||
relpath=$(${grub_mkrelpath} $path)
|
||||
fi
|
||||
|
||||
# abort if file read through GRUB doesn't match file read through system
|
||||
# facilities
|
||||
if ${grub_fstest} $device cmp $relpath $path > /dev/null 2>&1 ; then : ; else
|
||||
# abort if file is in a filesystem we can't read
|
||||
if ${grub_probe} -t fs $path > /dev/null 2>&1 ; then : ; else
|
||||
return 1
|
||||
fi
|
||||
|
||||
|
@ -132,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
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
230
util/grub-mknetdir.in
Normal file
230
util/grub-mknetdir.in
Normal 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
|
|
@ -36,9 +36,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,59 +48,312 @@ 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.
|
||||
*/
|
||||
|
||||
#ifdef GRUB_MACHINE_PCBIOS
|
||||
static const grub_gpt_part_type_t grub_gpt_partition_type_bios_boot = GRUB_GPT_PARTITION_TYPE_BIOS_BOOT;
|
||||
#endif
|
||||
|
||||
#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 *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)
|
||||
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);
|
||||
|
||||
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 offset,
|
||||
unsigned length)
|
||||
{
|
||||
struct grub_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_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_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)
|
||||
grub_util_error (_("the sectors of the core file are too fragmented"));
|
||||
}
|
||||
|
||||
last_length = length;
|
||||
#ifdef GRUB_MACHINE_PCBIOS
|
||||
current_segment += GRUB_DISK_SECTOR_SIZE >> 4;
|
||||
#endif
|
||||
}
|
||||
|
||||
/* 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 %u"),
|
||||
boot_path, GRUB_DISK_SECTOR_SIZE);
|
||||
boot_img = grub_util_read_image (boot_path);
|
||||
free (boot_path);
|
||||
|
||||
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);
|
||||
#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);
|
||||
|
||||
/* Have FIRST_BLOCK to point to the first blocklist. */
|
||||
first_block = (struct grub_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);
|
||||
|
||||
#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
|
||||
|
||||
#ifdef GRUB_MACHINE_PCBIOS
|
||||
if (dest_dev->disk->partition && fs_probe)
|
||||
{
|
||||
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);
|
||||
|
||||
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);
|
||||
}
|
||||
#endif
|
||||
|
||||
#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 (dest_dev->disk->id & 0x80)
|
||||
/* Replace the jmp (2 bytes) with double nop's. */
|
||||
*boot_drive_check = 0x9090;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef GRUB_MACHINE_PCBIOS
|
||||
{
|
||||
const char *dest_partmap;
|
||||
int multiple_partmaps;
|
||||
|
||||
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;
|
||||
|
@ -111,10 +364,10 @@ setup (const char *dir,
|
|||
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)
|
||||
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;
|
||||
|
||||
|
@ -134,190 +387,18 @@ setup (const char *dir,
|
|||
return 0;
|
||||
}
|
||||
|
||||
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);
|
||||
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;
|
||||
}
|
||||
|
||||
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 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);
|
||||
|
||||
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);
|
||||
else
|
||||
{
|
||||
block->start = grub_cpu_to_le64 (sector);
|
||||
block->len = grub_cpu_to_le16 (1);
|
||||
block->segment = grub_cpu_to_le16 (current_segment);
|
||||
|
||||
block--;
|
||||
if (block->len)
|
||||
grub_util_error (_("the sectors of the core file are too fragmented"));
|
||||
}
|
||||
|
||||
last_length = length;
|
||||
current_segment += GRUB_DISK_SECTOR_SIZE >> 4;
|
||||
}
|
||||
|
||||
/* 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 %u"),
|
||||
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_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)
|
||||
grub_util_error (_("the size of `%s' is too large"), core_path);
|
||||
|
||||
core_img = grub_util_read_image (core_path);
|
||||
|
||||
/* Have FIRST_BLOCK to point to the first blocklist. */
|
||||
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);
|
||||
|
||||
/* Open the root device and the destination device. */
|
||||
root_dev = grub_device_open (root);
|
||||
if (! root_dev)
|
||||
grub_util_error ("%s", grub_errmsg);
|
||||
|
||||
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);
|
||||
|
||||
/* 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);
|
||||
|
||||
if (dest_dev->disk->partition && fs_probe)
|
||||
{
|
||||
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);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
/* 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);
|
||||
|
||||
/* 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)
|
||||
{
|
||||
/* 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);
|
||||
|
||||
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)
|
||||
/* 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)
|
||||
return 0;
|
||||
|
@ -330,81 +411,85 @@ setup (const char *dir,
|
|||
}
|
||||
return 0;
|
||||
}
|
||||
dest_partmap = 0;
|
||||
multiple_partmaps = 0;
|
||||
grub_partition_iterate (dest_dev->disk, identify_partmap);
|
||||
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)
|
||||
{
|
||||
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 (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"));
|
||||
/* 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);
|
||||
|
||||
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;
|
||||
}
|
||||
free (tmp_img);
|
||||
|
||||
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;
|
||||
}
|
||||
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"));
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
grub_util_info ("the core image will be embedded at sector 0x%llx", embed_region.start);
|
||||
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;
|
||||
}
|
||||
|
||||
*install_dos_part = grub_cpu_to_le32 (dos_part);
|
||||
*install_bsd_part = grub_cpu_to_le32 (bsd_part);
|
||||
write_rootdev (core_img, root_dev,
|
||||
boot_img, embed_region.start);
|
||||
|
||||
/* The first blocklist contains the whole sectors. */
|
||||
first_block->start = grub_cpu_to_le64 (embed_region.start + 1);
|
||||
grub_util_info ("the core image will be embedded at sector 0x%llx", embed_region.start);
|
||||
|
||||
/* 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)));
|
||||
/* The first blocklist contains the whole sectors. */
|
||||
first_block->start = grub_cpu_to_le64 (embed_region.start + 1);
|
||||
|
||||
/* Make sure that the second blocklist is a terminator. */
|
||||
block = first_block - 1;
|
||||
block->start = 0;
|
||||
block->len = 0;
|
||||
block->segment = 0;
|
||||
/* 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)));
|
||||
|
||||
/* 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);
|
||||
/* Make sure that the second blocklist is a terminator. */
|
||||
block = first_block - 1;
|
||||
block->start = 0;
|
||||
block->len = 0;
|
||||
block->segment = 0;
|
||||
|
||||
/* FIXME: can this be skipped? */
|
||||
*boot_drive = 0xFF;
|
||||
/* 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);
|
||||
|
||||
*kernel_sector = grub_cpu_to_le64 (embed_region.start);
|
||||
/* 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 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);
|
||||
|
||||
goto finish;
|
||||
goto finish;
|
||||
}
|
||||
#endif
|
||||
|
||||
unable_to_embed:
|
||||
|
||||
|
@ -418,6 +503,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);
|
||||
|
@ -500,7 +588,9 @@ unable_to_embed:
|
|||
{
|
||||
block->start = 0;
|
||||
block->len = 0;
|
||||
#ifdef GRUB_MACHINE_PCBIOS
|
||||
block->segment = 0;
|
||||
#endif
|
||||
|
||||
block--;
|
||||
|
||||
|
@ -525,18 +615,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);
|
||||
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);
|
||||
|
@ -548,7 +659,8 @@ unable_to_embed:
|
|||
fclose (fp);
|
||||
|
||||
/* 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:
|
||||
|
@ -627,14 +739,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 ();
|
||||
|
@ -749,10 +865,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)
|
||||
{
|
||||
|
@ -767,13 +888,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__
|
||||
|
@ -805,7 +931,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,
|
|
@ -41,14 +41,6 @@ for i in /boot/gnumach* ; do
|
|||
basename=`basename $i`
|
||||
dirname=`dirname $i`
|
||||
rel_dirname=`make_system_path_relative_to_its_root $dirname`
|
||||
|
||||
if ! is_path_readable_by_grub ${dirname}/${basename} \
|
||||
${GRUB_DEVICE_BOOT} \
|
||||
${rel_dirname}/${basename} ; then
|
||||
echo "${dirname}/${basename} is not readable by GRUB" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Found GNU Mach: $i" >&2
|
||||
kernels="${kernels} ${rel_dirname}/${basename}"
|
||||
at_least_one=true
|
||||
|
|
|
@ -44,7 +44,7 @@ load_kfreebsd_module ()
|
|||
mod="$1"
|
||||
allow_fail="$2"
|
||||
|
||||
if ! is_path_readable_by_grub "${module_dir}/${mod}.ko" ; then
|
||||
if ! test -e "${module_dir}/${mod}.ko" ; then
|
||||
if [ "${allow_fail}" = "true" ] ; then
|
||||
# Return silently
|
||||
return
|
||||
|
@ -77,13 +77,6 @@ kfreebsd_entry ()
|
|||
prepare_boot_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | sed -e "s/^/\t/")"
|
||||
fi
|
||||
|
||||
if ! is_path_readable_by_grub ${dirname}/${basename} \
|
||||
${GRUB_DEVICE_BOOT} \
|
||||
${rel_dirname}/${basename} ; then
|
||||
echo "${dirname}/${basename} is not readable by GRUB" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
printf '%s\n' "${prepare_boot_cache}"
|
||||
cat << EOF
|
||||
echo '$(printf "$(gettext_quoted "Loading kernel of FreeBSD %s ...")" ${version})'
|
||||
|
@ -102,13 +95,7 @@ EOF
|
|||
zfs)
|
||||
load_kfreebsd_module opensolaris false
|
||||
|
||||
if ! is_path_readable_by_grub ${dirname}/zfs/zpool.cache \
|
||||
${GRUB_DEVICE_BOOT} \
|
||||
${rel_dirname}/zfs/zpool.cache ; then
|
||||
echo "${dirname}/zfs/zpool.cache is not readable by GRUB" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
ls "${dirname}/zfs/zpool.cache" > /dev/null
|
||||
printf '%s\n' "${prepare_boot_cache}"
|
||||
cat << EOF
|
||||
kfreebsd_module ${rel_dirname}/zfs/zpool.cache type=/boot/zfs/zpool.cache
|
||||
|
|
|
@ -83,15 +83,6 @@ EOF
|
|||
EOF
|
||||
fi
|
||||
|
||||
for i in ${basename} ${initrd} ; do
|
||||
if ! is_path_readable_by_grub ${dirname}/${i} \
|
||||
${GRUB_DEVICE_BOOT} \
|
||||
${rel_dirname}/${i} ; then
|
||||
echo "${dirname}/${i} is not readable by GRUB" >&2
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
|
||||
if [ -z "${prepare_boot_cache}" ]; then
|
||||
prepare_boot_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | sed -e "s/^/\t/")"
|
||||
fi
|
||||
|
|
|
@ -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;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue