merge mainline to ia64
This commit is contained in:
commit
0f35c665e6
595 changed files with 62746 additions and 9109 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) config.log
|
||||
|
||||
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=$@:$<
|
489
util/bash-completion.d/grub-completion.bash.in
Normal file
489
util/bash-completion.d/grub-completion.bash.in
Normal 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
|
|
@ -96,7 +96,7 @@ main (int argc, char *argv[])
|
|||
if (b == EOF)
|
||||
goto abort;
|
||||
|
||||
printf ("/* THIS CHUNK OF BYTES IS AUTOMATICALY GENERATED */\n"
|
||||
printf ("/* THIS CHUNK OF BYTES IS AUTOMATICALLY GENERATED */\n"
|
||||
"unsigned char %s[] =\n{\n", sym);
|
||||
|
||||
while (1)
|
||||
|
|
|
@ -485,12 +485,15 @@ compare_devices (const void *a, const void *b)
|
|||
{
|
||||
const struct device *left = (const struct device *) a;
|
||||
const struct device *right = (const struct device *) b;
|
||||
int ret;
|
||||
ret = strcmp (left->kernel, right->kernel);
|
||||
if (ret)
|
||||
return ret;
|
||||
else
|
||||
return strcmp (left->stable, right->stable);
|
||||
|
||||
if (left->kernel && right->kernel)
|
||||
{
|
||||
int ret = strcmp (left->kernel, right->kernel);
|
||||
if (ret)
|
||||
return ret;
|
||||
}
|
||||
|
||||
return strcmp (left->stable, right->stable);
|
||||
}
|
||||
#endif /* __linux__ */
|
||||
|
||||
|
@ -533,6 +536,10 @@ grub_util_iterate_devices (int NESTED_FUNC_ATTR (*hook) (const char *, int),
|
|||
necessary. */
|
||||
for (entry = readdir (dir); entry; entry = readdir (dir))
|
||||
{
|
||||
/* Skip current and parent directory entries. */
|
||||
if (strcmp (entry->d_name, ".") == 0 ||
|
||||
strcmp (entry->d_name, "..") == 0)
|
||||
continue;
|
||||
/* Skip partition entries. */
|
||||
if (strstr (entry->d_name, "-part"))
|
||||
continue;
|
||||
|
@ -601,7 +608,7 @@ grub_util_iterate_devices (int NESTED_FUNC_ATTR (*hook) (const char *, int),
|
|||
#endif /* __linux__ */
|
||||
|
||||
/* IDE disks. */
|
||||
for (i = 0; i < 26; i++)
|
||||
for (i = 0; i < 96; i++)
|
||||
{
|
||||
char name[16];
|
||||
|
||||
|
@ -655,7 +662,7 @@ grub_util_iterate_devices (int NESTED_FUNC_ATTR (*hook) (const char *, int),
|
|||
#endif /* __linux__ */
|
||||
|
||||
/* The rest is SCSI disks. */
|
||||
for (i = 0; i < 26; i++)
|
||||
for (i = 0; i < 48; i++)
|
||||
{
|
||||
char name[16];
|
||||
|
||||
|
|
|
@ -28,46 +28,83 @@
|
|||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <getopt.h>
|
||||
#include <argp.h>
|
||||
|
||||
#include "progname.h"
|
||||
|
||||
#define DEFAULT_ENVBLK_SIZE 1024
|
||||
#define DEFAULT_ENVBLK_PATH DEFAULT_DIRECTORY "/" GRUB_ENVBLK_DEFCFG
|
||||
|
||||
static struct option options[] = {
|
||||
{"help", no_argument, 0, 'h'},
|
||||
{"version", no_argument, 0, 'V'},
|
||||
{"verbose", no_argument, 0, 'v'},
|
||||
{0, 0, 0, 0}
|
||||
static struct argp_option options[] = {
|
||||
{0, 0, 0, OPTION_DOC, N_("Commands:"), 1},
|
||||
{"create", 0, 0, OPTION_DOC|OPTION_NO_USAGE,
|
||||
N_("Create a blank environment block file."), 0},
|
||||
{"list", 0, 0, OPTION_DOC|OPTION_NO_USAGE,
|
||||
N_("List the current variables."), 0},
|
||||
{"set [name=value ...]", 0, 0, OPTION_DOC|OPTION_NO_USAGE,
|
||||
N_("Set variables."), 0},
|
||||
{"unset [name ....]", 0, 0, OPTION_DOC|OPTION_NO_USAGE,
|
||||
N_("Delete variables."), 0},
|
||||
|
||||
{0, 0, 0, OPTION_DOC, N_("Options:"), -1},
|
||||
{"verbose", 'v', 0, 0, N_("Print verbose messages."), 0},
|
||||
|
||||
{ 0, 0, 0, 0, 0, 0 }
|
||||
};
|
||||
|
||||
/* Print the version information. */
|
||||
static void
|
||||
usage (int status)
|
||||
print_version (FILE *stream, struct argp_state *state)
|
||||
{
|
||||
if (status)
|
||||
fprintf (stderr, "Try `%s --help' for more information.\n", program_name);
|
||||
else
|
||||
printf ("\
|
||||
Usage: %s [OPTIONS] [FILENAME] COMMAND\n\
|
||||
\n\
|
||||
Tool to edit environment block.\n\
|
||||
\nCommands:\n\
|
||||
create create a blank environment block file\n\
|
||||
list list the current variables\n\
|
||||
set [name=value ...] set variables\n\
|
||||
unset [name ....] delete variables\n\
|
||||
\nOptions:\n\
|
||||
-h, --help display this message and exit\n\
|
||||
-V, --version print version information and exit\n\
|
||||
-v, --verbose print verbose messages\n\
|
||||
\n\
|
||||
If not given explicitly, FILENAME defaults to %s.\n\
|
||||
\n\
|
||||
Report bugs to <%s>.\n",
|
||||
program_name, DEFAULT_DIRECTORY "/" GRUB_ENVBLK_DEFCFG, PACKAGE_BUGREPORT);
|
||||
|
||||
exit (status);
|
||||
fprintf (stream, "%s (%s) %s\n", program_name, PACKAGE_NAME, PACKAGE_VERSION);
|
||||
}
|
||||
void (*argp_program_version_hook) (FILE *, struct argp_state *) = print_version;
|
||||
|
||||
/* Set the bug report address */
|
||||
const char *argp_program_bug_address = "<"PACKAGE_BUGREPORT">";
|
||||
|
||||
error_t argp_parser (int key, char *arg, struct argp_state *state)
|
||||
{
|
||||
switch (key)
|
||||
{
|
||||
case 'v':
|
||||
verbosity++;
|
||||
break;
|
||||
|
||||
case ARGP_KEY_NO_ARGS:
|
||||
fprintf (stderr, "%s",
|
||||
_("You need to specify at least one command.\n"));
|
||||
argp_usage (state);
|
||||
break;
|
||||
|
||||
default:
|
||||
return ARGP_ERR_UNKNOWN;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static char *
|
||||
help_filter (int key, const char *text, void *input __attribute__ ((unused)))
|
||||
{
|
||||
switch (key)
|
||||
{
|
||||
case ARGP_KEY_HELP_POST_DOC:
|
||||
return xasprintf(text, DEFAULT_ENVBLK_PATH);
|
||||
|
||||
default:
|
||||
return (char *) text;
|
||||
}
|
||||
}
|
||||
|
||||
struct argp argp = {
|
||||
options, argp_parser, N_("FILENAME COMMAND"),
|
||||
"\n"N_("\
|
||||
Tool to edit environment block.")
|
||||
"\v"N_("\
|
||||
If FILENAME is '-', the default value %s is used."),
|
||||
NULL, help_filter, NULL
|
||||
};
|
||||
|
||||
static void
|
||||
create_envblk_file (const char *name)
|
||||
|
@ -227,55 +264,32 @@ main (int argc, char *argv[])
|
|||
{
|
||||
char *filename;
|
||||
char *command;
|
||||
int index, arg_count;
|
||||
|
||||
set_program_name (argv[0]);
|
||||
|
||||
grub_util_init_nls ();
|
||||
|
||||
/* Check for options. */
|
||||
while (1)
|
||||
/* Parse our arguments */
|
||||
if (argp_parse (&argp, argc, argv, 0, &index, 0) != 0)
|
||||
{
|
||||
int c = getopt_long (argc, argv, "hVv", options, 0);
|
||||
|
||||
if (c == -1)
|
||||
break;
|
||||
else
|
||||
switch (c)
|
||||
{
|
||||
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;
|
||||
}
|
||||
fprintf (stderr, "%s", _("Error in parsing command line arguments\n"));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* Obtain the filename. */
|
||||
if (optind >= argc)
|
||||
{
|
||||
fprintf (stderr, "no filename specified\n");
|
||||
usage (1);
|
||||
}
|
||||
arg_count = argc - index;
|
||||
|
||||
if (optind + 1 >= argc)
|
||||
if (arg_count == 1)
|
||||
{
|
||||
filename = DEFAULT_DIRECTORY "/" GRUB_ENVBLK_DEFCFG;
|
||||
command = argv[optind];
|
||||
filename = DEFAULT_ENVBLK_PATH;
|
||||
command = argv[index++];
|
||||
}
|
||||
else
|
||||
{
|
||||
filename = argv[optind];
|
||||
command = argv[optind + 1];
|
||||
filename = argv[index++];
|
||||
if (strcmp (filename, "-") == 0)
|
||||
filename = DEFAULT_ENVBLK_PATH;
|
||||
command = argv[index++];
|
||||
}
|
||||
|
||||
if (strcmp (command, "create") == 0)
|
||||
|
@ -283,13 +297,16 @@ main (int argc, char *argv[])
|
|||
else if (strcmp (command, "list") == 0)
|
||||
list_variables (filename);
|
||||
else if (strcmp (command, "set") == 0)
|
||||
set_variables (filename, argc - optind - 2, argv + optind + 2);
|
||||
set_variables (filename, argc - index, argv + index);
|
||||
else if (strcmp (command, "unset") == 0)
|
||||
unset_variables (filename, argc - optind - 2, argv + optind + 2);
|
||||
unset_variables (filename, argc - index, argv + index);
|
||||
else
|
||||
{
|
||||
fprintf (stderr, "unknown command %s\n", command);
|
||||
usage (1);
|
||||
char *program = xstrdup(program_name);
|
||||
fprintf (stderr, _("Unknown command `%s'.\n"), command);
|
||||
argp_help (&argp, stderr, ARGP_HELP_STD_USAGE, program);
|
||||
free(program);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
#include <grub/term.h>
|
||||
#include <grub/mm.h>
|
||||
#include <grub/lib/hexdump.h>
|
||||
#include <grub/lib/crc.h>
|
||||
#include <grub/crypto.h>
|
||||
#include <grub/command.h>
|
||||
#include <grub/i18n.h>
|
||||
|
||||
|
@ -38,9 +38,9 @@
|
|||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <getopt.h>
|
||||
|
||||
#include "progname.h"
|
||||
#include "argp.h"
|
||||
|
||||
static grub_err_t
|
||||
execute_command (char *name, int n, char **args)
|
||||
|
@ -49,7 +49,7 @@ execute_command (char *name, int n, char **args)
|
|||
|
||||
cmd = grub_command_find (name);
|
||||
if (! cmd)
|
||||
grub_util_error ("can\'t find command %s", name);
|
||||
grub_util_error (_("can\'t find command %s"), name);
|
||||
|
||||
return (cmd->func) (cmd, n, args);
|
||||
}
|
||||
|
@ -78,7 +78,7 @@ read_file (char *pathname, int (*hook) (grub_off_t ofs, char *buf, int len))
|
|||
|
||||
dev = grub_device_open (0);
|
||||
if ((! dev) || (! dev->disk))
|
||||
grub_util_error ("can\'t open device");
|
||||
grub_util_error (_("can\'t open device"));
|
||||
|
||||
grub_util_info ("total sectors : %lld",
|
||||
(unsigned long long) dev->disk->total_sectors);
|
||||
|
@ -93,7 +93,7 @@ read_file (char *pathname, int (*hook) (grub_off_t ofs, char *buf, int len))
|
|||
len = (leng > BUF_SIZE) ? BUF_SIZE : leng;
|
||||
|
||||
if (grub_disk_read (dev->disk, 0, skip, len, buf))
|
||||
grub_util_error ("disk read fails at offset %lld, length %d",
|
||||
grub_util_error (_("disk read fails at offset %lld, length %d"),
|
||||
skip, len);
|
||||
|
||||
if (hook (skip, buf, len))
|
||||
|
@ -107,10 +107,11 @@ read_file (char *pathname, int (*hook) (grub_off_t ofs, char *buf, int len))
|
|||
return;
|
||||
}
|
||||
|
||||
grub_file_filter_disable_compression ();
|
||||
file = grub_file_open (pathname);
|
||||
if (!file)
|
||||
{
|
||||
grub_util_error ("cannot open file %s", pathname);
|
||||
grub_util_error (_("cannot open file %s"), pathname);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -118,7 +119,7 @@ read_file (char *pathname, int (*hook) (grub_off_t ofs, char *buf, int len))
|
|||
|
||||
if (skip > file->size)
|
||||
{
|
||||
grub_util_error ("invalid skip value %lld", (unsigned long long) skip);
|
||||
grub_util_error (_("invalid skip value %lld"), (unsigned long long) skip);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -136,7 +137,8 @@ read_file (char *pathname, int (*hook) (grub_off_t ofs, char *buf, int len))
|
|||
sz = grub_file_read (file, buf, (len > BUF_SIZE) ? BUF_SIZE : len);
|
||||
if (sz < 0)
|
||||
{
|
||||
grub_util_error ("read error at offset %llu: %s", ofs, grub_errmsg);
|
||||
grub_util_error (_("read error at offset %llu: %s"), ofs,
|
||||
grub_errmsg);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -162,7 +164,7 @@ cmd_cp (char *src, char *dest)
|
|||
|
||||
if ((int) fwrite (buf, 1, len, ff) != len)
|
||||
{
|
||||
grub_util_error ("write error");
|
||||
grub_util_error (_("write error"));
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -172,7 +174,7 @@ cmd_cp (char *src, char *dest)
|
|||
ff = fopen (dest, "wb");
|
||||
if (ff == NULL)
|
||||
{
|
||||
grub_util_error ("open error");
|
||||
grub_util_error (_("open error"));
|
||||
return;
|
||||
}
|
||||
read_file (src, cp_hook);
|
||||
|
@ -190,7 +192,7 @@ cmd_cmp (char *src, char *dest)
|
|||
{
|
||||
if ((int) fread (buf_1, 1, len, ff) != len)
|
||||
{
|
||||
grub_util_error ("read error at offset %llu: %s", ofs, grub_errmsg);
|
||||
grub_util_error (_("read error at offset %llu: %s"), ofs, grub_errmsg);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -201,7 +203,7 @@ cmd_cmp (char *src, char *dest)
|
|||
for (i = 0; i < len; i++, ofs++)
|
||||
if (buf_1[i] != buf[i])
|
||||
{
|
||||
grub_util_error ("compare fail at offset %llu", ofs);
|
||||
grub_util_error (_("compare fail at offset %llu"), ofs);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
@ -211,12 +213,12 @@ cmd_cmp (char *src, char *dest)
|
|||
ff = fopen (dest, "rb");
|
||||
if (ff == NULL)
|
||||
{
|
||||
grub_util_error ("open error");
|
||||
grub_util_error (_("open error"));
|
||||
return;
|
||||
}
|
||||
|
||||
if ((skip) && (fseeko (ff, skip, SEEK_SET)))
|
||||
grub_util_error ("seek error");
|
||||
grub_util_error (_("seek error"));
|
||||
|
||||
read_file (src, cmp_hook);
|
||||
fclose (ff);
|
||||
|
@ -238,33 +240,43 @@ cmd_hex (char *pathname)
|
|||
static void
|
||||
cmd_crc (char *pathname)
|
||||
{
|
||||
grub_uint32_t crc = 0;
|
||||
grub_uint8_t crc32_context[GRUB_MD_CRC32->contextsize];
|
||||
GRUB_MD_CRC32->init(crc32_context);
|
||||
|
||||
auto int crc_hook (grub_off_t ofs, char *buf, int len);
|
||||
int crc_hook (grub_off_t ofs, char *buf, int len)
|
||||
{
|
||||
(void) ofs;
|
||||
|
||||
crc = grub_getcrc32 (crc, buf, len);
|
||||
GRUB_MD_CRC32->write(crc32_context, buf, len);
|
||||
return 0;
|
||||
}
|
||||
|
||||
read_file (pathname, crc_hook);
|
||||
printf ("%08x\n", crc);
|
||||
GRUB_MD_CRC32->final(crc32_context);
|
||||
printf ("%08x\n",
|
||||
grub_be_to_cpu32(*(grub_uint32_t*)GRUB_MD_CRC32->read(crc32_context)));
|
||||
}
|
||||
|
||||
static char *root = NULL;
|
||||
static int args_count = 0;
|
||||
static int nparm = 0;
|
||||
static int num_disks = 1;
|
||||
static char **images = NULL;
|
||||
static int cmd = 0;
|
||||
static char *debug_str = NULL;
|
||||
static char **args = NULL;
|
||||
|
||||
static void
|
||||
fstest (char **images, int num_disks, int cmd, int n, char **args)
|
||||
fstest (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);
|
||||
|
@ -273,21 +285,23 @@ 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))
|
||||
grub_util_error ("loopback command fails");
|
||||
if (execute_command ("loopback", 2, argv))
|
||||
grub_util_error (_("loopback command fails"));
|
||||
|
||||
grub_free (loop_name);
|
||||
grub_free (host_file);
|
||||
}
|
||||
|
||||
grub_lvm_fini ();
|
||||
grub_mdraid_fini ();
|
||||
grub_mdraid09_fini ();
|
||||
grub_mdraid1x_fini ();
|
||||
grub_raid_fini ();
|
||||
grub_raid_init ();
|
||||
grub_mdraid_init ();
|
||||
grub_mdraid09_init ();
|
||||
grub_mdraid1x_init ();
|
||||
grub_lvm_init ();
|
||||
|
||||
switch (cmd)
|
||||
|
@ -311,15 +325,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);
|
||||
|
@ -328,203 +343,175 @@ fstest (char **images, int num_disks, int cmd, int n, char **args)
|
|||
}
|
||||
}
|
||||
|
||||
static struct option options[] = {
|
||||
{"root", required_argument, 0, 'r'},
|
||||
{"skip", required_argument, 0, 's'},
|
||||
{"length", required_argument, 0, 'n'},
|
||||
{"diskcount", required_argument, 0, 'c'},
|
||||
{"debug", required_argument, 0, 'd'},
|
||||
{"help", no_argument, 0, 'h'},
|
||||
{"version", no_argument, 0, 'V'},
|
||||
{"verbose", no_argument, 0, 'v'},
|
||||
{0, 0, 0, 0}
|
||||
static struct argp_option options[] = {
|
||||
{0, 0, 0 , OPTION_DOC, N_("Commands:"), 1},
|
||||
{N_("ls PATH"), 0, 0 , OPTION_DOC, N_("List files in PATH."), 1},
|
||||
{N_("cp FILE LOCAL"), 0, 0, OPTION_DOC, N_("Copy FILE to local file LOCAL."), 1},
|
||||
{N_("cmp FILE LOCAL"), 0, 0, OPTION_DOC, N_("Compare FILE with local file LOCAL."), 1},
|
||||
{N_("hex FILE"), 0, 0 , OPTION_DOC, N_("Hex dump FILE."), 1},
|
||||
{N_("crc FILE"), 0, 0 , OPTION_DOC, N_("Get crc32 checksum of FILE."), 1},
|
||||
{N_("blocklist FILE"), 0, 0, OPTION_DOC, N_("Display blocklist of FILE."), 1},
|
||||
|
||||
{"root", 'r', N_("DEVICE_NAME"), 0, N_("Set root device."), 2},
|
||||
{"skip", 's', "N", 0, N_("Skip N bytes from output file."), 2},
|
||||
{"length", 'n', "N", 0, N_("Handle N bytes in output file."), 2},
|
||||
{"diskcount", 'c', "N", 0, N_("N input files."), 2},
|
||||
{"debug", 'd', "S", 0, N_("Set debug environment variable."), 2},
|
||||
{"verbose", 'v', NULL, OPTION_ARG_OPTIONAL, N_("Print verbose messages."), 2},
|
||||
{0, 0, 0, 0, 0, 0}
|
||||
};
|
||||
|
||||
/* Print the version information. */
|
||||
static void
|
||||
usage (int status)
|
||||
print_version (FILE *stream, struct argp_state *state)
|
||||
{
|
||||
if (status)
|
||||
fprintf (stderr, "Try `%s --help' for more information.\n", program_name);
|
||||
else
|
||||
printf ("\
|
||||
Usage: %s [OPTION]... IMAGE_PATH COMMANDS\n\
|
||||
\n\
|
||||
Debug tool for filesystem driver.\n\
|
||||
\nCommands:\n\
|
||||
ls PATH list files in PATH\n\
|
||||
cp FILE LOCAL copy FILE to local file LOCAL\n\
|
||||
cmp FILE LOCAL compare FILE with local file LOCAL\n\
|
||||
hex FILE Hex dump FILE\n\
|
||||
crc FILE Get crc32 checksum of FILE\n\
|
||||
blocklist FILE display blocklist of FILE\n\
|
||||
\nOptions:\n\
|
||||
-r, --root=DEVICE_NAME set root device\n\
|
||||
-s, --skip=N skip N bytes from output file\n\
|
||||
-n, --length=N handle N bytes in output file\n\
|
||||
-c, --diskcount=N N input files\n\
|
||||
-d, --debug=S Set debug environment variable\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);
|
||||
fprintf (stream, "%s (%s) %s\n", program_name, PACKAGE_NAME, PACKAGE_VERSION);
|
||||
}
|
||||
void (*argp_program_version_hook) (FILE *, struct argp_state *) = print_version;
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
error_t
|
||||
argp_parser (int key, char *arg, struct argp_state *state)
|
||||
{
|
||||
char *debug_str = NULL, *root = NULL, *default_root, *alloc_root;
|
||||
int i, cmd, num_opts, image_index, num_disks = 1;
|
||||
char *p;
|
||||
|
||||
set_program_name (argv[0]);
|
||||
switch (key)
|
||||
{
|
||||
case 'r':
|
||||
root = arg;
|
||||
return 0;
|
||||
|
||||
grub_util_init_nls ();
|
||||
case 's':
|
||||
skip = grub_strtoul (arg, &p, 0);
|
||||
if (*p == 's')
|
||||
skip <<= GRUB_DISK_SECTOR_BITS;
|
||||
return 0;
|
||||
|
||||
/* Find the first non option entry. */
|
||||
for (num_opts = 1; num_opts < argc; num_opts++)
|
||||
if (argv[num_opts][0] == '-')
|
||||
{
|
||||
if ((argv[num_opts][2] == 0) && (num_opts < argc - 1) &&
|
||||
((argv[num_opts][1] == 'r') ||
|
||||
(argv[num_opts][1] == 's') ||
|
||||
(argv[num_opts][1] == 'n') ||
|
||||
(argv[num_opts][1] == 'c') ||
|
||||
(argv[num_opts][1] == 'd')))
|
||||
num_opts++;
|
||||
}
|
||||
else
|
||||
case 'n':
|
||||
leng = grub_strtoul (arg, &p, 0);
|
||||
if (*p == 's')
|
||||
leng <<= GRUB_DISK_SECTOR_BITS;
|
||||
return 0;
|
||||
|
||||
case 'c':
|
||||
num_disks = grub_strtoul (arg, NULL, 0);
|
||||
if (num_disks < 1)
|
||||
{
|
||||
fprintf (stderr, "%s", _("Invalid disk count.\n"));
|
||||
argp_usage (state);
|
||||
}
|
||||
if (args_count != 0)
|
||||
{
|
||||
fprintf (stderr, "%s", _("Disk count must precede disks list.\n"));
|
||||
argp_usage (state);
|
||||
}
|
||||
return 0;
|
||||
|
||||
case 'd':
|
||||
debug_str = arg;
|
||||
return 0;
|
||||
|
||||
case 'v':
|
||||
verbosity++;
|
||||
return 0;
|
||||
|
||||
case ARGP_KEY_END:
|
||||
if (args_count < num_disks)
|
||||
{
|
||||
fprintf (stderr, "%s", _("No command is specified.\n"));
|
||||
argp_usage (state);
|
||||
}
|
||||
if (args_count - 1 - num_disks < nparm)
|
||||
{
|
||||
fprintf (stderr, "%s", _("Not enough parameters to command.\n"));
|
||||
argp_usage (state);
|
||||
}
|
||||
return 0;
|
||||
|
||||
case ARGP_KEY_ARG:
|
||||
break;
|
||||
|
||||
/* Check for options. */
|
||||
while (1)
|
||||
{
|
||||
int c = getopt_long (num_opts, argv, "r:s:n:c:d:hVv", options, 0);
|
||||
char *p;
|
||||
|
||||
if (c == -1)
|
||||
break;
|
||||
else
|
||||
switch (c)
|
||||
{
|
||||
case 'r':
|
||||
root = optarg;
|
||||
break;
|
||||
|
||||
case 's':
|
||||
skip = grub_strtoul (optarg, &p, 0);
|
||||
if (*p == 's')
|
||||
skip <<= GRUB_DISK_SECTOR_BITS;
|
||||
break;
|
||||
|
||||
case 'n':
|
||||
leng = grub_strtoul (optarg, &p, 0);
|
||||
if (*p == 's')
|
||||
leng <<= GRUB_DISK_SECTOR_BITS;
|
||||
break;
|
||||
|
||||
case 'c':
|
||||
num_disks = grub_strtoul (optarg, NULL, 0);
|
||||
if (num_disks < 1)
|
||||
{
|
||||
fprintf (stderr, "Invalid disk count.\n");
|
||||
usage (1);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'd':
|
||||
debug_str = 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;
|
||||
}
|
||||
default:
|
||||
return ARGP_ERR_UNKNOWN;
|
||||
}
|
||||
|
||||
/* Obtain PATH. */
|
||||
if (optind + num_disks - 1 >= argc)
|
||||
if (args_count < num_disks)
|
||||
{
|
||||
fprintf (stderr, "Not enough pathname.\n");
|
||||
usage (1);
|
||||
if (arg[0] != '/')
|
||||
{
|
||||
fprintf (stderr, "%s", _("Must use absolute path.\n"));
|
||||
argp_usage (state);
|
||||
}
|
||||
if (args_count == 0)
|
||||
images = xmalloc (num_disks * sizeof (images[0]));
|
||||
images[args_count] = xstrdup (arg);
|
||||
args_count++;
|
||||
return 0;
|
||||
}
|
||||
|
||||
image_index = optind;
|
||||
for (i = 0; i < num_disks; i++, optind++)
|
||||
if (argv[optind][0] != '/')
|
||||
{
|
||||
fprintf (stderr, "Must use absolute path.\n");
|
||||
usage (1);
|
||||
}
|
||||
|
||||
cmd = 0;
|
||||
if (optind < argc)
|
||||
if (args_count == num_disks)
|
||||
{
|
||||
int nparm = 0;
|
||||
|
||||
if (!grub_strcmp (argv[optind], "ls"))
|
||||
if (!grub_strcmp (arg, "ls"))
|
||||
{
|
||||
cmd = CMD_LS;
|
||||
}
|
||||
else if (!grub_strcmp (argv[optind], "cp"))
|
||||
else if (!grub_strcmp (arg, "cp"))
|
||||
{
|
||||
cmd = CMD_CP;
|
||||
nparm = 2;
|
||||
}
|
||||
else if (!grub_strcmp (argv[optind], "cmp"))
|
||||
else if (!grub_strcmp (arg, "cmp"))
|
||||
{
|
||||
cmd = CMD_CMP;
|
||||
nparm = 2;
|
||||
}
|
||||
else if (!grub_strcmp (argv[optind], "hex"))
|
||||
else if (!grub_strcmp (arg, "hex"))
|
||||
{
|
||||
cmd = CMD_HEX;
|
||||
nparm = 1;
|
||||
}
|
||||
else if (!grub_strcmp (argv[optind], "crc"))
|
||||
else if (!grub_strcmp (arg, "crc"))
|
||||
{
|
||||
cmd = CMD_CRC;
|
||||
nparm = 1;
|
||||
}
|
||||
else if (!grub_strcmp (argv[optind], "blocklist"))
|
||||
else if (!grub_strcmp (arg, "blocklist"))
|
||||
{
|
||||
cmd = CMD_BLOCKLIST;
|
||||
nparm = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf (stderr, "Invalid command %s.\n", argv[optind]);
|
||||
usage (1);
|
||||
fprintf (stderr, _("Invalid command %s.\n"), arg);
|
||||
argp_usage (state);
|
||||
}
|
||||
|
||||
if (optind + 1 + nparm > argc)
|
||||
{
|
||||
fprintf (stderr, "Invalid parameter for command %s.\n",
|
||||
argv[optind]);
|
||||
usage (1);
|
||||
}
|
||||
|
||||
optind++;
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf (stderr, "No command is specified.\n");
|
||||
usage (1);
|
||||
args_count++;
|
||||
return 0;
|
||||
}
|
||||
|
||||
args[args_count - 1 - num_disks] = xstrdup (arg);
|
||||
args_count++;
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct argp argp = {
|
||||
options, argp_parser, N_("IMAGE_PATH COMMANDS"),
|
||||
N_("Debug tool for filesystem driver."),
|
||||
NULL, NULL, NULL
|
||||
};
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
char *default_root, *alloc_root;
|
||||
|
||||
set_program_name (argv[0]);
|
||||
|
||||
grub_util_init_nls ();
|
||||
|
||||
args = xmalloc (argc * sizeof (args[0]));
|
||||
|
||||
argp_parse (&argp, argc, argv, 0, 0, 0);
|
||||
|
||||
/* Initialize all modules. */
|
||||
grub_init_all ();
|
||||
|
||||
|
@ -552,7 +539,7 @@ main (int argc, char *argv[])
|
|||
free (alloc_root);
|
||||
|
||||
/* Do it. */
|
||||
fstest (argv + image_index, num_disks, cmd, argc - optind, argv + optind);
|
||||
fstest (args_count - 1 - num_disks, args);
|
||||
|
||||
/* Free resources. */
|
||||
grub_fini_all ();
|
||||
|
|
|
@ -19,29 +19,32 @@
|
|||
# Initialize some variables.
|
||||
transform="@program_transform_name@"
|
||||
|
||||
prefix=@prefix@
|
||||
exec_prefix=@exec_prefix@
|
||||
sbindir=@sbindir@
|
||||
bindir=@bindir@
|
||||
libdir=@libdir@
|
||||
prefix="@prefix@"
|
||||
exec_prefix="@exec_prefix@"
|
||||
sbindir="@sbindir@"
|
||||
bindir="@bindir@"
|
||||
libdir="@libdir@"
|
||||
sysconfdir="@sysconfdir@"
|
||||
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
|
||||
pkglibdir="${libdir}/`echo ${PACKAGE_TARNAME}/${target_cpu}-${platform} | sed ${transform}`"
|
||||
localedir="@datadir@/locale"
|
||||
|
||||
self=`basename $0`
|
||||
self="`basename $0`"
|
||||
|
||||
grub_setup=${sbindir}/`echo grub-setup | sed ${transform}`
|
||||
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_setup="${sbindir}/`echo grub-setup | sed ${transform}`"
|
||||
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,20 +83,32 @@ 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
|
||||
--allow-floppy Make the drive also bootable as floppy
|
||||
(default for fdX devices). May break on some BIOSes.
|
||||
--recheck probe a device map even if it already exists
|
||||
--force install even if problems are detected
|
||||
EOF
|
||||
|
@ -83,32 +116,42 @@ 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
|
||||
}
|
||||
|
||||
argument () {
|
||||
opt=$1
|
||||
opt="$1"
|
||||
shift
|
||||
|
||||
if test $# -eq 0; then
|
||||
echo "$0: option requires an argument -- '$opt'" 1>&2
|
||||
exit 1
|
||||
fi
|
||||
echo $1
|
||||
echo "$1"
|
||||
}
|
||||
|
||||
allow_floppy=""
|
||||
|
||||
# Check the arguments.
|
||||
while test $# -gt 0
|
||||
do
|
||||
|
@ -134,52 +177,76 @@ do
|
|||
--font=*)
|
||||
;;
|
||||
|
||||
# Accept for compatibility
|
||||
--root-directory)
|
||||
rootdir=`argument $option "$@"`; shift;;
|
||||
rootdir="`argument $option "$@"`"; shift;;
|
||||
--root-directory=*)
|
||||
rootdir=`echo "$option" | sed 's/--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="`argument "$option" "$@"`"; shift;;
|
||||
--grub-setup=*)
|
||||
grub_setup=`echo "$option" | sed 's/--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="`argument $option "$@"`"; shift;;
|
||||
--grub-mkimage=*)
|
||||
grub_mkimage=`echo "$option" | sed 's/--grub-mkimage=//'` ;;
|
||||
grub_mkimage="`echo "$option" | sed 's/--grub-mkimage=//'`" ;;
|
||||
|
||||
--grub-mkrelpath)
|
||||
grub_mkrelpath="`argument "$option" "$@"`"; shift;;
|
||||
--grub-mkrelpath=*)
|
||||
grub_mkrelpath="`echo "$option" | sed 's/--grub-mkrelpath=//'`" ;;
|
||||
|
||||
--grub-mkdevicemap)
|
||||
grub_mkdevicemap=`argument $option "$@"`; shift;;
|
||||
grub_mkdevicemap="`argument "$option" "$@"`"; shift;;
|
||||
--grub-mkdevicemap=*)
|
||||
grub_mkdevicemap=`echo "$option" | sed 's/--grub-mkdevicemap=//'` ;;
|
||||
grub_mkdevicemap="`echo "$option" | sed 's/--grub-mkdevicemap=//'`" ;;
|
||||
|
||||
--grub-probe)
|
||||
grub_probe=`argument $option "$@"`; shift;;
|
||||
grub_probe="`argument "$option" "$@"`"; shift;;
|
||||
--grub-probe=*)
|
||||
grub_probe=`echo "$option" | sed 's/--grub-probe=//'` ;;
|
||||
grub_probe="`echo "$option" | sed 's/--grub-probe=//'`" ;;
|
||||
|
||||
--no-floppy)
|
||||
no_floppy="--no-floppy" ;;
|
||||
--recheck)
|
||||
recheck=yes ;;
|
||||
--removable)
|
||||
removable=yes ;;
|
||||
|
||||
--allow-floppy)
|
||||
allow_floppy="--allow-floppy" ;;
|
||||
|
||||
--disk-module)
|
||||
if [ "${target_cpu}-${platform}" = "i386-pc" ] ; then
|
||||
disk_module=`argument $option "$@"`; shift;
|
||||
disk_module="`argument "$option" "$@"`"; shift;
|
||||
fi ;;
|
||||
--disk-module=*)
|
||||
if [ "${target_cpu}-${platform}" = "i386-pc" ] ; then
|
||||
disk_module=`echo "$option" | sed 's/--disk-module=//'`
|
||||
disk_module="`echo "$option" | sed 's/--disk-module=//'`"
|
||||
fi ;;
|
||||
|
||||
--no-nvram)
|
||||
update_nvram=no ;;
|
||||
|
||||
# This is an undocumented feature...
|
||||
--debug)
|
||||
debug=yes ;;
|
||||
--debug-image)
|
||||
debug_image=`argument $option "$@"`; shift;;
|
||||
debug_image="`argument "$option" "$@"`"; shift;;
|
||||
--debug-image=*)
|
||||
debug_image=`echo "$option" | sed 's/--debug-image=//'` ;;
|
||||
debug_image="`echo "$option" | sed 's/--debug-image=//'`" ;;
|
||||
|
||||
-f | --force)
|
||||
setup_force="--force" ;;
|
||||
|
@ -199,10 +266,8 @@ do
|
|||
esac
|
||||
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
|
||||
|
@ -210,29 +275,25 @@ fi
|
|||
|
||||
# If the debugging feature is enabled, print commands.
|
||||
setup_verbose=
|
||||
if test $debug = yes; then
|
||||
if test x"$debug" = xyes; 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}`
|
||||
device_map=${grubdir}/device.map
|
||||
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.
|
||||
if [ "${target_cpu}-${platform}" = "i386-pc" ] || [ "${target_cpu}-${platform}" = "sparc64-ieee1275" ] ; then
|
||||
|
@ -245,7 +306,7 @@ if [ "${target_cpu}-${platform}" = "i386-pc" ] || [ "${target_cpu}-${platform}"
|
|||
fi
|
||||
fi
|
||||
|
||||
set $grub_mkimage dummy
|
||||
set "$grub_mkimage" dummy
|
||||
if test -f "$1"; then
|
||||
:
|
||||
else
|
||||
|
@ -253,7 +314,7 @@ else
|
|||
exit 1
|
||||
fi
|
||||
|
||||
set $grub_mkdevicemap dummy
|
||||
set "$grub_mkdevicemap" dummy
|
||||
if test -f "$1"; then
|
||||
:
|
||||
else
|
||||
|
@ -261,12 +322,93 @@ 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
|
||||
|
||||
# If --recheck is specified, remove the device map, if present.
|
||||
if test $recheck = yes; then
|
||||
rm -f $device_map
|
||||
rm -f "$device_map"
|
||||
fi
|
||||
|
||||
# Create the device map file if it is not present.
|
||||
|
@ -276,11 +418,11 @@ else
|
|||
# Create a safe temporary file.
|
||||
test -n "$mklog" && log_file=`$mklog`
|
||||
|
||||
$grub_mkdevicemap --device-map=$device_map $no_floppy || exit 1
|
||||
"$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 \
|
||||
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
|
||||
|
@ -288,42 +430,42 @@ if test -n "$tmp"; then
|
|||
fi
|
||||
|
||||
# Copy the GRUB images to the GRUB directory.
|
||||
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
|
||||
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 ${pkglibdir}/*.mod ${pkglibdir}/*.lst; do
|
||||
cp -f $file ${grubdir} || exit 1
|
||||
for file in "${pkglibdir}"/*.mod "${pkglibdir}"/*.lst; do
|
||||
cp -f "$file" "${grubdir}" || exit 1
|
||||
done
|
||||
if [ "${target_cpu}-${platform}" = "i386-pc" ] || [ "${target_cpu}-${platform}" = "sparc64-ieee1275" ] ; then
|
||||
for file in ${pkglibdir}/*.img ${pkglibdir}/efiemu??.o; do
|
||||
if test -f $file; then
|
||||
cp -f $file ${grubdir} || exit 1
|
||||
for file in "${pkglibdir}"/*.img "${pkglibdir}"/efiemu??.o; do
|
||||
if test -f "$file"; then
|
||||
cp -f "$file" "${grubdir}" || exit 1
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
# Copy gettext files
|
||||
mkdir -p ${grubdir}/locale/
|
||||
for dir in ${localedir}/*; do
|
||||
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
|
||||
|
||||
# Write device to a variable so we don't have to traverse /dev every time.
|
||||
grub_device=`$grub_probe --target=device ${grubdir}` || exit 1
|
||||
grub_device="`"$grub_probe" --device-map="${device_map}" --target=device "${grubdir}"`" || exit 1
|
||||
|
||||
if ! test -f ${grubdir}/grubenv; then
|
||||
$grub_editenv ${grubdir}/grubenv create
|
||||
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 ${grub_device}`
|
||||
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
|
||||
fs_module="`"$grub_probe" --device-map="${device_map}" --target=fs --device "${grub_device}"`"
|
||||
if test "x$fs_module" = x ; then
|
||||
echo "Auto-detection of a filesystem of ${grub_device} failed." 1>&2
|
||||
echo "Please report this together with the output of \"$grub_probe --device-map=\"${device_map}\" --target=fs -v ${grubdir}\" to <bug-grub@gnu.org>" 1>&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
@ -331,18 +473,24 @@ fi
|
|||
# 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";
|
||||
for x in `"$grub_probe" --device-map="${device_map}" --target=partmap --device "${grub_device}" 2> /dev/null`; do
|
||||
case "$x" in
|
||||
netbsd | openbsd)
|
||||
partmap_module="$partmap_module part_bsd";;
|
||||
"") ;;
|
||||
*)
|
||||
partmap_module="$partmap_module part_$x";;
|
||||
esac
|
||||
done
|
||||
|
||||
# Device abstraction module, if any (lvm, raid).
|
||||
devabstraction_module=`$grub_probe --target=abstraction --device ${grub_device}`
|
||||
devabstraction_module="`"$grub_probe" --device-map="${device_map}" --target=abstraction --device "${grub_device}"`"
|
||||
|
||||
# The order in this list is critical. Be careful when modifying it.
|
||||
modules="$modules $disk_module"
|
||||
modules="$modules $fs_module $partmap_module $devabstraction_module"
|
||||
|
||||
relative_grubdir=`make_system_path_relative_to_its_root ${grubdir}` || exit 1
|
||||
relative_grubdir="`"$grub_mkrelpath" "${grubdir}"`" || exit 1
|
||||
if [ "x${relative_grubdir}" = "x" ] ; then
|
||||
relative_grubdir=/
|
||||
fi
|
||||
|
@ -350,10 +498,10 @@ fi
|
|||
prefix_drive=
|
||||
config_opt=
|
||||
|
||||
rm -f ${grubdir}/load.cfg
|
||||
rm -f "${grubdir}/load.cfg"
|
||||
|
||||
if [ "x${debug_image}" != x ]; then
|
||||
echo "set debug='${debug_image}'" >> ${grubdir}/load.cfg
|
||||
echo "set debug='${debug_image}'" >> "${grubdir}/load.cfg"
|
||||
config_opt="-c ${grubdir}/load.cfg "
|
||||
fi
|
||||
|
||||
|
@ -362,27 +510,28 @@ if [ "x${devabstraction_module}" = "x" ] ; then
|
|||
if echo "${install_device}" | grep -qx "(.*)" ; then
|
||||
install_drive="${install_device}"
|
||||
else
|
||||
install_drive="`$grub_probe --target=drive --device ${install_device}`" || exit 1
|
||||
install_drive="`"$grub_probe" --device-map="${device_map}" --target=drive --device "${install_device}"`" || exit 1
|
||||
fi
|
||||
install_drive="`echo ${install_drive} | sed -e s/,[a-z0-9,]*//g`"
|
||||
install_drive="`echo "${install_drive}" | sed -e s/,[a-z0-9,]*//g`"
|
||||
fi
|
||||
grub_drive="`$grub_probe --target=drive --device ${grub_device}`" || exit 1
|
||||
grub_drive="`"$grub_probe" --device-map="${device_map}" --target=drive --device "${grub_device}"`" || exit 1
|
||||
|
||||
# Strip partition number
|
||||
grub_drive="`echo ${grub_drive} | sed -e s/,[a-z0-9,]*//g`"
|
||||
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)
|
||||
uuid="`$grub_probe --target=fs_uuid --device ${grub_device}`"
|
||||
uuid="`"$grub_probe" --device-map="${device_map}" --target=fs_uuid --device "${grub_device}"`"
|
||||
if [ "x${uuid}" = "x" ] ; then
|
||||
echo "UUID needed with ata mod, but the filesystem containing ${grubdir} does not support UUIDs." 1>&2
|
||||
exit 1
|
||||
fi
|
||||
echo "search.fs_uuid ${uuid} root " >> ${grubdir}/load.cfg
|
||||
echo 'set prefix=($root)'"${relative_grubdir}" >> ${grubdir}/load.cfg
|
||||
echo "search.fs_uuid ${uuid} root " >> "${grubdir}/load.cfg"
|
||||
echo 'set prefix=($root)'"${relative_grubdir}" >> "${grubdir}/load.cfg"
|
||||
config_opt="-c ${grubdir}/load.cfg "
|
||||
modules="$modules search_fs_uuid"
|
||||
elif [ "x${grub_drive}" != "x${install_drive}" ] ; then
|
||||
uuid="`$grub_probe --target=fs_uuid --device ${grub_device}`"
|
||||
uuid="`"$grub_probe" --device-map="${device_map}" --target=fs_uuid --device "${grub_device}"`"
|
||||
if [ "x${uuid}" = "x" ] ; then
|
||||
echo "You attempted a cross-disk install, but the filesystem containing ${grubdir} does not support UUIDs." 1>&2
|
||||
exit 1
|
||||
|
@ -391,28 +540,117 @@ 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.
|
||||
if [ x"$grub_partition" = x ]; then
|
||||
prefix_drive="()"
|
||||
else
|
||||
prefix_drive="(,$grub_partition)"
|
||||
fi
|
||||
fi
|
||||
else
|
||||
prefix_drive=`$grub_probe --target=drive --device ${grub_device}` || exit 1
|
||||
prefix_drive=`"$grub_probe" --device-map="${device_map}" --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}" "${bootdir}"/grub.elf
|
||||
elif [ "${target_cpu}-${platform}" = "i386-ieee1275" ] || [ "${target_cpu}-${platform}" = "powerpc-ieee1275" ]; then
|
||||
cp "${grubdir}/core.${imgext}" "${grubdir}/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" ${allow_floppy} ${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" --device-map="${device_map}" --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
6
util/grub-kbdcomp.in
Normal file
|
@ -0,0 +1,6 @@
|
|||
#!/bin/sh
|
||||
|
||||
grub_mklayout=${bindir}/`echo grub-mklayout | sed ${transform}`
|
||||
|
||||
ckbcomp "$@" | $grub_mklayout -o "$1".gkb
|
||||
|
|
@ -17,6 +17,8 @@
|
|||
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <grub/types.h>
|
||||
#include <grub/macho.h>
|
||||
#include <stdio.h>
|
||||
|
|
122
util/grub-menulst2cfg.c
Normal file
122
util/grub-menulst2cfg.c
Normal file
|
@ -0,0 +1,122 @@
|
|||
/*
|
||||
* 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 <config.h>
|
||||
|
||||
#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;
|
||||
}
|
|
@ -22,6 +22,7 @@ transform="@program_transform_name@"
|
|||
prefix=@prefix@
|
||||
exec_prefix=@exec_prefix@
|
||||
sbindir=@sbindir@
|
||||
bindir=@bindir@
|
||||
libdir=@libdir@
|
||||
sysconfdir=@sysconfdir@
|
||||
PACKAGE_NAME=@PACKAGE_NAME@
|
||||
|
@ -35,8 +36,11 @@ grub_mkconfig_dir=${sysconfdir}/grub.d
|
|||
|
||||
self=`basename $0`
|
||||
|
||||
grub_mkdevicemap=${sbindir}/`echo grub-mkdevicemap | sed ${transform}`
|
||||
grub_probe=${sbindir}/`echo grub-probe | sed ${transform}`
|
||||
grub_mkdevicemap=${sbindir}/`echo grub-mkdevicemap | sed "${transform}"`
|
||||
grub_probe=${sbindir}/`echo grub-probe | sed "${transform}"`
|
||||
grub_script_check="${bindir}/`echo grub-script-check | sed "${transform}"`"
|
||||
|
||||
GRUB_PREFIX=`echo '/@bootdirname@/@grubdirname@' | sed "s,//*,/,g"`
|
||||
|
||||
# Usage: usage
|
||||
# Print the usage.
|
||||
|
@ -93,18 +97,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 +150,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
|
||||
|
@ -178,20 +170,6 @@ fi
|
|||
|
||||
for x in ${GRUB_TERMINAL_OUTPUT}; do
|
||||
if [ "x${x}" = "xgfxterm" ]; then
|
||||
# If this platform supports gfxterm, try to use it.
|
||||
if ! test -e ${GRUB_PREFIX}/gfxterm.mod ; then
|
||||
if [ "x$termoutdefault" != "x1" ]; then
|
||||
echo "gfxterm isn't available on your platform" >&2 ; exit 1
|
||||
fi
|
||||
GRUB_TERMINAL_OUTPUT=
|
||||
break;
|
||||
fi
|
||||
if [ ! -s "${GRUB_PREFIX}/video.lst" ] ; then
|
||||
if [ "x$termoutdefault" != "x1" ]; then
|
||||
echo "No suitable backend could be found for gfxterm." >&2 ; exit 1
|
||||
fi
|
||||
GRUB_TERMINAL_OUTPUT=
|
||||
fi
|
||||
if [ -n "$GRUB_FONT" ] ; then
|
||||
if is_path_readable_by_grub ${GRUB_FONT} > /dev/null ; then
|
||||
GRUB_FONT_PATH=${GRUB_FONT}
|
||||
|
@ -200,7 +178,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 +233,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 \
|
||||
|
@ -266,8 +245,7 @@ export GRUB_DEFAULT \
|
|||
GRUB_TERMINAL_OUTPUT \
|
||||
GRUB_SERIAL_COMMAND \
|
||||
GRUB_DISABLE_LINUX_UUID \
|
||||
GRUB_DISABLE_LINUX_RECOVERY \
|
||||
GRUB_DISABLE_NETBSD_RECOVERY \
|
||||
GRUB_DISABLE_RECOVERY \
|
||||
GRUB_VIDEO_BACKEND \
|
||||
GRUB_GFXMODE \
|
||||
GRUB_BACKGROUND \
|
||||
|
@ -314,8 +292,15 @@ for i in ${grub_mkconfig_dir}/* ; do
|
|||
done
|
||||
|
||||
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}
|
||||
if ! ${grub_script_check} ${grub_cfg}.new; then
|
||||
echo "Syntax errors are detected in generated GRUB config file." >&2
|
||||
echo "Ensure that there are no errors in /etc/default/grub" >&2
|
||||
echo "and /etc/grub.d/* files or please file a bug report with" >&2
|
||||
echo "${grub_cfg}.new file attached." >&2
|
||||
else
|
||||
# none of the children aborted with error, install the new grub.cfg
|
||||
mv -f ${grub_cfg}.new ${grub_cfg}
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "done" >&2
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -187,8 +187,20 @@ version_find_latest ()
|
|||
echo "$a"
|
||||
}
|
||||
|
||||
# One layer of quotation is eaten by "", the second by sed, and the third by
|
||||
# printf; so this turns ' into \'. Note that you must use the output of
|
||||
# this function in a printf format string.
|
||||
gettext_quoted () {
|
||||
$gettext "$@" | sed "s/'/'\\\\''/g"
|
||||
$gettext "$@" | sed "s/'/'\\\\\\\\''/g"
|
||||
}
|
||||
|
||||
# Run the first argument through gettext_quoted, and then pass that and all
|
||||
# remaining arguments to printf. This is a useful abbreviation and tends to
|
||||
# be easier to type.
|
||||
gettext_printf () {
|
||||
local format="$1"
|
||||
shift
|
||||
printf "$(gettext_quoted "$format")" "$@"
|
||||
}
|
||||
|
||||
uses_abstraction () {
|
||||
|
|
|
@ -1170,7 +1170,8 @@ main (int argc, char *argv[])
|
|||
font_info.style = ft_face->style_flags;
|
||||
font_info.size = size;
|
||||
|
||||
FT_Set_Pixel_Sizes (ft_face, size, size);
|
||||
if (FT_Set_Pixel_Sizes (ft_face, size, size))
|
||||
grub_util_error ("can't set %dx%d font size", size, size);
|
||||
add_font (&font_info, ft_face, file_format != PF2);
|
||||
FT_Done_Face (ft_face);
|
||||
}
|
||||
|
|
|
@ -45,7 +45,16 @@
|
|||
|
||||
#define ALIGN_ADDR(x) (ALIGN_UP((x), image_target->voidp_sizeof))
|
||||
|
||||
#ifdef HAVE_LIBLZMA
|
||||
#include <lzma.h>
|
||||
#endif
|
||||
|
||||
#define TARGET_NO_FIELD 0xffffffff
|
||||
|
||||
typedef enum {
|
||||
COMPRESSION_AUTO, COMPRESSION_NONE, COMPRESSION_XZ
|
||||
} grub_compression_t;
|
||||
|
||||
struct image_target_desc
|
||||
{
|
||||
const char *name;
|
||||
|
@ -60,7 +69,8 @@ struct image_target_desc
|
|||
enum
|
||||
{
|
||||
PLATFORM_FLAGS_NONE = 0,
|
||||
PLATFORM_FLAGS_LZMA = 1
|
||||
PLATFORM_FLAGS_LZMA = 1,
|
||||
PLATFORM_FLAGS_DECOMPRESSORS = 2
|
||||
} flags;
|
||||
unsigned prefix;
|
||||
unsigned prefix_end;
|
||||
|
@ -75,6 +85,7 @@ struct image_target_desc
|
|||
unsigned install_dos_part, install_bsd_part;
|
||||
grub_uint64_t link_addr;
|
||||
unsigned mod_gap, mod_align;
|
||||
grub_compression_t default_compression;
|
||||
};
|
||||
|
||||
struct image_target_desc image_targets[] =
|
||||
|
@ -248,40 +259,42 @@ struct image_target_desc image_targets[] =
|
|||
.voidp_sizeof = 4,
|
||||
.bigendian = 0,
|
||||
.id = IMAGE_YEELOONG_FLASH,
|
||||
.flags = PLATFORM_FLAGS_NONE,
|
||||
.flags = PLATFORM_FLAGS_DECOMPRESSORS,
|
||||
.prefix = GRUB_KERNEL_MIPS_YEELOONG_PREFIX,
|
||||
.prefix_end = GRUB_KERNEL_MIPS_YEELOONG_PREFIX_END,
|
||||
.raw_size = GRUB_KERNEL_MIPS_YEELOONG_RAW_SIZE,
|
||||
.raw_size = 0,
|
||||
.total_module_size = GRUB_KERNEL_MIPS_YEELOONG_TOTAL_MODULE_SIZE,
|
||||
.compressed_size = GRUB_KERNEL_MIPS_YEELOONG_COMPRESSED_SIZE,
|
||||
.kernel_image_size = GRUB_KERNEL_MIPS_YEELOONG_KERNEL_IMAGE_SIZE,
|
||||
.compressed_size = TARGET_NO_FIELD,
|
||||
.kernel_image_size = TARGET_NO_FIELD,
|
||||
.section_align = 1,
|
||||
.vaddr_offset = 0,
|
||||
.install_dos_part = TARGET_NO_FIELD,
|
||||
.install_bsd_part = TARGET_NO_FIELD,
|
||||
.link_addr = GRUB_KERNEL_MIPS_YEELOONG_LINK_ADDR,
|
||||
.elf_target = EM_MIPS,
|
||||
.link_align = GRUB_KERNEL_MIPS_YEELOONG_LINK_ALIGN
|
||||
.link_align = GRUB_KERNEL_MIPS_YEELOONG_LINK_ALIGN,
|
||||
.default_compression = COMPRESSION_NONE
|
||||
},
|
||||
{
|
||||
.name = "mipsel-yeeloong-elf",
|
||||
.voidp_sizeof = 4,
|
||||
.bigendian = 0,
|
||||
.id = IMAGE_YEELOONG_ELF,
|
||||
.flags = PLATFORM_FLAGS_NONE,
|
||||
.flags = PLATFORM_FLAGS_DECOMPRESSORS,
|
||||
.prefix = GRUB_KERNEL_MIPS_YEELOONG_PREFIX,
|
||||
.prefix_end = GRUB_KERNEL_MIPS_YEELOONG_PREFIX_END,
|
||||
.raw_size = GRUB_KERNEL_MIPS_YEELOONG_RAW_SIZE,
|
||||
.raw_size = 0,
|
||||
.total_module_size = GRUB_KERNEL_MIPS_YEELOONG_TOTAL_MODULE_SIZE,
|
||||
.compressed_size = GRUB_KERNEL_MIPS_YEELOONG_COMPRESSED_SIZE,
|
||||
.kernel_image_size = GRUB_KERNEL_MIPS_YEELOONG_KERNEL_IMAGE_SIZE,
|
||||
.compressed_size = TARGET_NO_FIELD,
|
||||
.kernel_image_size = TARGET_NO_FIELD,
|
||||
.section_align = 1,
|
||||
.vaddr_offset = 0,
|
||||
.install_dos_part = TARGET_NO_FIELD,
|
||||
.install_bsd_part = TARGET_NO_FIELD,
|
||||
.link_addr = GRUB_KERNEL_MIPS_YEELOONG_LINK_ADDR,
|
||||
.elf_target = EM_MIPS,
|
||||
.link_align = GRUB_KERNEL_MIPS_YEELOONG_LINK_ALIGN
|
||||
.link_align = GRUB_KERNEL_MIPS_YEELOONG_LINK_ALIGN,
|
||||
.default_compression = COMPRESSION_NONE
|
||||
},
|
||||
{
|
||||
.name = "powerpc-ieee1275",
|
||||
|
@ -493,9 +506,66 @@ compress_kernel_lzma (char *kernel_img, size_t kernel_size,
|
|||
*core_size += raw_size;
|
||||
}
|
||||
|
||||
#ifdef HAVE_LIBLZMA
|
||||
static void
|
||||
compress_kernel_xz (char *kernel_img, size_t kernel_size,
|
||||
char **core_img, size_t *core_size, size_t raw_size)
|
||||
{
|
||||
lzma_stream strm = LZMA_STREAM_INIT;
|
||||
lzma_ret xzret;
|
||||
lzma_options_lzma lzopts = {
|
||||
.dict_size = 1 << 16,
|
||||
.preset_dict = NULL,
|
||||
.preset_dict_size = 0,
|
||||
.lc = 3,
|
||||
.lp = 0,
|
||||
.pb = 2,
|
||||
.mode = LZMA_MODE_NORMAL,
|
||||
.nice_len = 64,
|
||||
.mf = LZMA_MF_BT4,
|
||||
.depth = 0,
|
||||
};
|
||||
lzma_filter fltrs[] = {
|
||||
{ .id = LZMA_FILTER_LZMA2, .options = &lzopts},
|
||||
{ .id = LZMA_VLI_UNKNOWN, .options = NULL}
|
||||
};
|
||||
|
||||
if (kernel_size < raw_size)
|
||||
grub_util_error (_("the core image is too small"));
|
||||
|
||||
xzret = lzma_stream_encoder (&strm, fltrs, LZMA_CHECK_NONE);
|
||||
if (xzret != LZMA_OK)
|
||||
grub_util_error (_("cannot compress the kernel image"));
|
||||
|
||||
*core_img = xmalloc (kernel_size);
|
||||
memcpy (*core_img, kernel_img, raw_size);
|
||||
|
||||
*core_size = kernel_size - raw_size;
|
||||
strm.next_in = (unsigned char *) kernel_img + raw_size;
|
||||
strm.avail_in = kernel_size - raw_size;
|
||||
strm.next_out = (unsigned char *) *core_img + raw_size;
|
||||
strm.avail_out = *core_size;
|
||||
|
||||
while (1)
|
||||
{
|
||||
xzret = lzma_code (&strm, LZMA_FINISH);
|
||||
if (xzret == LZMA_OK)
|
||||
continue;
|
||||
if (xzret == LZMA_STREAM_END)
|
||||
break;
|
||||
grub_util_error (_("cannot compress the kernel image"));
|
||||
}
|
||||
|
||||
*core_size -= strm.avail_out;
|
||||
|
||||
*core_size += raw_size;
|
||||
}
|
||||
#endif
|
||||
|
||||
static void
|
||||
compress_kernel (struct image_target_desc *image_target, char *kernel_img,
|
||||
size_t kernel_size, char **core_img, size_t *core_size)
|
||||
size_t kernel_size, char **core_img, size_t *core_size,
|
||||
grub_compression_t comp)
|
||||
{
|
||||
if (image_target->flags & PLATFORM_FLAGS_LZMA)
|
||||
{
|
||||
|
@ -504,6 +574,20 @@ compress_kernel (struct image_target_desc *image_target, char *kernel_img,
|
|||
return;
|
||||
}
|
||||
|
||||
#ifdef HAVE_LIBLZMA
|
||||
if (image_target->flags & PLATFORM_FLAGS_DECOMPRESSORS
|
||||
&& (comp == COMPRESSION_XZ))
|
||||
{
|
||||
compress_kernel_xz (kernel_img, kernel_size, core_img,
|
||||
core_size, image_target->raw_size);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (image_target->flags & PLATFORM_FLAGS_DECOMPRESSORS
|
||||
&& (comp != COMPRESSION_NONE))
|
||||
grub_util_error ("unknown compression %d\n", comp);
|
||||
|
||||
*core_img = xmalloc (kernel_size);
|
||||
memcpy (*core_img, kernel_img, kernel_size);
|
||||
*core_size = kernel_size;
|
||||
|
@ -527,7 +611,8 @@ struct fixup_block_list
|
|||
static void
|
||||
generate_image (const char *dir, char *prefix, FILE *out, char *mods[],
|
||||
char *memdisk_path, char *config_path,
|
||||
struct image_target_desc *image_target, int note)
|
||||
struct image_target_desc *image_target, int note,
|
||||
grub_compression_t comp)
|
||||
{
|
||||
char *kernel_img, *core_img;
|
||||
size_t kernel_size, total_module_size, core_size, exec_size;
|
||||
|
@ -539,6 +624,10 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[],
|
|||
grub_uint64_t start_address;
|
||||
void *rel_section;
|
||||
grub_size_t reloc_size, align;
|
||||
|
||||
if (comp == COMPRESSION_AUTO)
|
||||
comp = image_target->default_compression;
|
||||
|
||||
path_list = grub_util_resolve_dependencies (dir, "moddep.lst", mods);
|
||||
|
||||
kernel_path = grub_util_get_path (dir, "kernel.img");
|
||||
|
@ -653,13 +742,19 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[],
|
|||
offset += config_size;
|
||||
}
|
||||
|
||||
if ((image_target->flags & PLATFORM_FLAGS_DECOMPRESSORS)
|
||||
&& (image_target->total_module_size != TARGET_NO_FIELD))
|
||||
*((grub_uint32_t *) (kernel_img + image_target->total_module_size))
|
||||
= grub_host_to_target32 (total_module_size);
|
||||
|
||||
grub_util_info ("kernel_img=%p, kernel_size=0x%x", kernel_img, kernel_size);
|
||||
compress_kernel (image_target, kernel_img, kernel_size + total_module_size,
|
||||
&core_img, &core_size);
|
||||
&core_img, &core_size, comp);
|
||||
|
||||
grub_util_info ("the core size is 0x%x", core_size);
|
||||
|
||||
if (image_target->total_module_size != TARGET_NO_FIELD)
|
||||
if (!(image_target->flags & PLATFORM_FLAGS_DECOMPRESSORS)
|
||||
&& image_target->total_module_size != TARGET_NO_FIELD)
|
||||
*((grub_uint32_t *) (core_img + image_target->total_module_size))
|
||||
= grub_host_to_target32 (total_module_size);
|
||||
if (image_target->kernel_image_size != TARGET_NO_FIELD)
|
||||
|
@ -680,6 +775,53 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[],
|
|||
= grub_host_to_target32 (-2);
|
||||
}
|
||||
|
||||
if (image_target->flags & PLATFORM_FLAGS_DECOMPRESSORS)
|
||||
{
|
||||
char *full_img;
|
||||
size_t full_size;
|
||||
char *decompress_path, *decompress_img;
|
||||
size_t decompress_size;
|
||||
const char *name;
|
||||
|
||||
switch (comp)
|
||||
{
|
||||
case COMPRESSION_XZ:
|
||||
name = "xz_decompress.img";
|
||||
break;
|
||||
case COMPRESSION_NONE:
|
||||
name = "none_decompress.img";
|
||||
break;
|
||||
default:
|
||||
grub_util_error ("unknown compression %d\n", comp);
|
||||
}
|
||||
|
||||
decompress_path = grub_util_get_path (dir, name);
|
||||
decompress_size = grub_util_get_image_size (decompress_path);
|
||||
decompress_img = grub_util_read_image (decompress_path);
|
||||
|
||||
*((grub_uint32_t *) (decompress_img + GRUB_KERNEL_MIPS_YEELOONG_COMPRESSED_SIZE))
|
||||
= grub_host_to_target32 (core_size);
|
||||
|
||||
*((grub_uint32_t *) (decompress_img + GRUB_KERNEL_MIPS_YEELOONG_UNCOMPRESSED_SIZE))
|
||||
= grub_host_to_target32 (kernel_size + total_module_size);
|
||||
|
||||
full_size = core_size + decompress_size;
|
||||
|
||||
full_img = xmalloc (full_size);
|
||||
memset (full_img, 0, full_size);
|
||||
|
||||
memcpy (full_img, decompress_img, decompress_size);
|
||||
|
||||
memcpy (full_img + decompress_size, core_img, core_size);
|
||||
|
||||
memset (full_img + decompress_size + core_size, 0,
|
||||
full_size - (decompress_size + core_size));
|
||||
|
||||
free (core_img);
|
||||
core_img = full_img;
|
||||
core_size = full_size;
|
||||
}
|
||||
|
||||
switch (image_target->id)
|
||||
{
|
||||
case IMAGE_I386_PC:
|
||||
|
@ -1218,6 +1360,7 @@ static struct option options[] =
|
|||
{"output", required_argument, 0, 'o'},
|
||||
{"note", no_argument, 0, 'n'},
|
||||
{"format", required_argument, 0, 'O'},
|
||||
{"compression", required_argument, 0, 'C'},
|
||||
{"help", no_argument, 0, 'h'},
|
||||
{"version", no_argument, 0, 'V'},
|
||||
{"verbose", no_argument, 0, 'v'},
|
||||
|
@ -1260,6 +1403,7 @@ Make a bootable image of GRUB.\n\
|
|||
-o, --output=FILE output a generated image to FILE [default=stdout]\n\
|
||||
-O, --format=FORMAT generate an image in format\n\
|
||||
available formats: %s\n\
|
||||
-C, --compression=(xz|none|auto) choose the compression to use\n\
|
||||
-h, --help display this message and exit\n\
|
||||
-V, --version print version information and exit\n\
|
||||
-v, --verbose print verbose messages\n\
|
||||
|
@ -1286,6 +1430,7 @@ main (int argc, char *argv[])
|
|||
FILE *fp = stdout;
|
||||
int note = 0;
|
||||
struct image_target_desc *image_target = NULL;
|
||||
grub_compression_t comp = COMPRESSION_AUTO;
|
||||
|
||||
set_program_name (argv[0]);
|
||||
|
||||
|
@ -1293,7 +1438,7 @@ main (int argc, char *argv[])
|
|||
|
||||
while (1)
|
||||
{
|
||||
int c = getopt_long (argc, argv, "d:p:m:c:o:O:f:hVvn", options, 0);
|
||||
int c = getopt_long (argc, argv, "d:p:m:c:o:O:f:C:hVvn", options, 0);
|
||||
|
||||
if (c == -1)
|
||||
break;
|
||||
|
@ -1350,6 +1495,22 @@ main (int argc, char *argv[])
|
|||
config = xstrdup (optarg);
|
||||
break;
|
||||
|
||||
case 'C':
|
||||
if (grub_strcmp (optarg, "xz") == 0)
|
||||
{
|
||||
#ifdef HAVE_LIBLZMA
|
||||
comp = COMPRESSION_XZ;
|
||||
#else
|
||||
grub_util_error ("grub-mkimage is compiled without XZ support",
|
||||
optarg);
|
||||
#endif
|
||||
}
|
||||
else if (grub_strcmp (optarg, "none") == 0)
|
||||
comp = COMPRESSION_NONE;
|
||||
else
|
||||
grub_util_error ("Unknown compression format %s", optarg);
|
||||
break;
|
||||
|
||||
case 'h':
|
||||
usage (0);
|
||||
break;
|
||||
|
@ -1408,7 +1569,7 @@ main (int argc, char *argv[])
|
|||
|
||||
generate_image (dir, prefix ? : DEFAULT_DIRECTORY, fp,
|
||||
argv + optind, memdisk, config,
|
||||
image_target, note);
|
||||
image_target, note, comp);
|
||||
|
||||
fclose (fp);
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
500
util/grub-mklayout.c
Normal file
500
util/grub-mklayout.c
Normal file
|
@ -0,0 +1,500 @@
|
|||
/*
|
||||
* 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 <config.h>
|
||||
|
||||
#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
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
|
|
@ -16,6 +16,8 @@
|
|||
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <grub/types.h>
|
||||
#include <grub/crypto.h>
|
||||
#include <grub/emu/misc.h>
|
||||
|
|
|
@ -17,6 +17,8 @@
|
|||
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <grub/util/misc.h>
|
||||
#include <grub/emu/misc.h>
|
||||
|
|
|
@ -152,15 +152,7 @@ else
|
|||
exit 1
|
||||
fi
|
||||
|
||||
if test "x$TMP" != x; then
|
||||
MKTEMP_TEMPLATE="$TMP/grub-mkrescue.XXXXXXXXXX"
|
||||
elif test "x$TEMP" != x; then
|
||||
MKTEMP_TEMPLATE="$TEMP/grub-mkrescue.XXXXXXXXXX"
|
||||
else
|
||||
MKTEMP_TEMPLATE="/tmp/grub-mkrescue.XXXXXXXXXX"
|
||||
fi
|
||||
|
||||
iso9660_dir=`mktemp -d "$MKTEMP_TEMPLATE"`
|
||||
iso9660_dir=`mktemp -d "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1
|
||||
mkdir -p ${iso9660_dir}/boot/grub
|
||||
|
||||
process_input_dir ()
|
||||
|
@ -197,12 +189,12 @@ make_image ()
|
|||
|
||||
echo "Enabling $2 support ..."
|
||||
|
||||
memdisk_img=`mktemp "$MKTEMP_TEMPLATE"`
|
||||
memdisk_dir=`mktemp -d "$MKTEMP_TEMPLATE"`
|
||||
memdisk_img=`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1
|
||||
memdisk_dir=`mktemp -d "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1
|
||||
mkdir -p ${memdisk_dir}/boot/grub
|
||||
|
||||
cat << EOF > ${memdisk_dir}/boot/grub/grub.cfg
|
||||
search --fs-uuid --set ${iso_uuid}
|
||||
search --fs-uuid --set=root ${iso_uuid}
|
||||
set prefix=(\${root})/boot/grub/${platform}
|
||||
source \$prefix/grub.cfg
|
||||
EOF
|
||||
|
@ -263,12 +255,12 @@ grub_mkisofs_arguments="${grub_mkisofs_arguments} --modification-date=$(echo ${i
|
|||
# build BIOS core.img
|
||||
if test -e "${pc_dir}" ; then
|
||||
echo "Enabling BIOS support ..."
|
||||
core_img=`mktemp "$MKTEMP_TEMPLATE"`
|
||||
core_img=`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1
|
||||
$grub_mkimage -O i386-pc -d ${pc_dir}/ -o ${core_img} --prefix=/boot/grub/i386-pc \
|
||||
iso9660 biosdisk
|
||||
cat ${pc_dir}/cdboot.img ${core_img} > ${iso9660_dir}/boot/grub/i386-pc/eltorito.img
|
||||
|
||||
embed_img=`mktemp "$MKTEMP_TEMPLATE"`
|
||||
embed_img=`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1
|
||||
cat ${pc_dir}/boot.img ${core_img} > ${embed_img}
|
||||
|
||||
rm -f ${core_img}
|
||||
|
@ -287,7 +279,7 @@ fi
|
|||
make_image "${multiboot_dir}" i386-multiboot "${iso9660_dir}/boot/multiboot.img" "ata at_keyboard"
|
||||
|
||||
if test -e "${efi64_dir}" || test -e "${efi32_dir}"; then
|
||||
efi_dir=`mktemp -d "$MKTEMP_TEMPLATE"`
|
||||
efi_dir=`mktemp -d "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1
|
||||
mkdir -p "${efi_dir}/efi/boot"
|
||||
|
||||
# build bootx64.efi
|
||||
|
|
|
@ -142,6 +142,7 @@ probe (const char *path, char *device_name)
|
|||
int is_raid5 = 0;
|
||||
int is_raid6 = 0;
|
||||
int raid_level;
|
||||
grub_disk_t raid_disk;
|
||||
|
||||
raid_level = probe_raid_level (dev->disk);
|
||||
if (raid_level >= 0)
|
||||
|
@ -149,6 +150,7 @@ probe (const char *path, char *device_name)
|
|||
is_raid = 1;
|
||||
is_raid5 |= (raid_level == 5);
|
||||
is_raid6 |= (raid_level == 6);
|
||||
raid_disk = dev->disk;
|
||||
}
|
||||
|
||||
if ((is_lvm) && (dev->disk->dev->memberlist))
|
||||
|
@ -161,6 +163,7 @@ probe (const char *path, char *device_name)
|
|||
is_raid = 1;
|
||||
is_raid5 |= (raid_level == 5);
|
||||
is_raid6 |= (raid_level == 6);
|
||||
raid_disk = list->disk;
|
||||
}
|
||||
|
||||
tmp = list->next;
|
||||
|
@ -175,7 +178,8 @@ probe (const char *path, char *device_name)
|
|||
printf ("raid5rec ");
|
||||
if (is_raid6)
|
||||
printf ("raid6rec ");
|
||||
printf ("mdraid ");
|
||||
if (raid_disk->dev->raidname)
|
||||
printf ("%s ", raid_disk->dev->raidname (raid_disk));
|
||||
}
|
||||
|
||||
if (is_lvm)
|
||||
|
@ -226,48 +230,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);
|
||||
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);
|
||||
}
|
||||
|
@ -277,7 +249,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);
|
||||
}
|
||||
|
@ -421,6 +394,15 @@ main (int argc, char *argv[])
|
|||
/* Initialize all modules. */
|
||||
grub_init_all ();
|
||||
|
||||
grub_lvm_fini ();
|
||||
grub_mdraid09_fini ();
|
||||
grub_mdraid1x_fini ();
|
||||
grub_raid_fini ();
|
||||
grub_raid_init ();
|
||||
grub_mdraid09_init ();
|
||||
grub_mdraid1x_init ();
|
||||
grub_lvm_init ();
|
||||
|
||||
/* Do it. */
|
||||
if (argument_is_device)
|
||||
probe (NULL, argument);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -73,6 +73,7 @@ main (int argc, char *argv[])
|
|||
{
|
||||
char *argument;
|
||||
char *input;
|
||||
int lineno = 0;
|
||||
FILE *file = 0;
|
||||
int verbose = 0;
|
||||
int found_input = 0;
|
||||
|
@ -111,6 +112,7 @@ main (int argc, char *argv[])
|
|||
cmdline[i] = '\0';
|
||||
}
|
||||
|
||||
lineno++;
|
||||
*line = grub_strdup (cmdline);
|
||||
|
||||
free (cmdline);
|
||||
|
@ -189,5 +191,11 @@ main (int argc, char *argv[])
|
|||
|
||||
if (file) fclose (file);
|
||||
|
||||
return (found_input && script == 0);
|
||||
if (found_input && script == 0)
|
||||
{
|
||||
fprintf (stderr, "error: line no: %u\n", lineno);
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
|
|
994
util/grub-setup.c
Normal file
994
util/grub-setup.c
Normal file
|
@ -0,0 +1,994 @@
|
|||
/* 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/disk.h>
|
||||
#include <grub/file.h>
|
||||
#include <grub/fs.h>
|
||||
#include <grub/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/i18n.h>
|
||||
#include <grub/util/raid.h>
|
||||
#include <grub/util/lvm.h>
|
||||
#ifdef GRUB_MACHINE_IEEE1275
|
||||
#include <grub/util/ofpath.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <dirent.h>
|
||||
#include <assert.h>
|
||||
#include <grub/emu/getroot.h>
|
||||
#include "progname.h"
|
||||
#include <grub/reed_solomon.h>
|
||||
|
||||
#define _GNU_SOURCE 1
|
||||
#include <argp.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, int allow_floppy)
|
||||
{
|
||||
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;
|
||||
struct grub_boot_blocklist *first_block, *block;
|
||||
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;
|
||||
|
||||
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);
|
||||
|
||||
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
|
||||
{
|
||||
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 (!allow_floppy && !grub_util_biosdisk_is_floppy (dest_dev->disk))
|
||||
/* Replace the jmp (2 bytes) with double nop's. */
|
||||
*boot_drive_check = 0x9090;
|
||||
}
|
||||
#endif
|
||||
|
||||
#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;
|
||||
int i;
|
||||
grub_fs_t fs;
|
||||
unsigned int nsec;
|
||||
|
||||
/* 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 != container)
|
||||
return 0;
|
||||
if (dest_partmap == NULL)
|
||||
{
|
||||
dest_partmap = p->partmap;
|
||||
return 0;
|
||||
}
|
||||
if (dest_partmap == p->partmap)
|
||||
return 0;
|
||||
multiple_partmaps = 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
grub_partition_iterate (dest_dev->disk, identify_partmap);
|
||||
|
||||
fs = grub_fs_probe (dest_dev);
|
||||
if (!fs)
|
||||
grub_errno = GRUB_ERR_NONE;
|
||||
|
||||
#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
|
||||
|
||||
if (! dest_partmap)
|
||||
{
|
||||
grub_util_warn (_("Attempting to install GRUB to a partitionless disk or to a partition. 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;
|
||||
}
|
||||
|
||||
/* 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);
|
||||
|
||||
free (tmp_img);
|
||||
|
||||
if (!dest_partmap->embed)
|
||||
{
|
||||
grub_util_warn ("Partition style '%s' doesn't support embeding",
|
||||
dest_partmap->name);
|
||||
goto unable_to_embed;
|
||||
}
|
||||
|
||||
nsec = core_sectors;
|
||||
err = dest_partmap->embed (dest_dev->disk, &nsec,
|
||||
GRUB_EMBED_PCBIOS, §ors);
|
||||
if (nsec > 2 * core_sectors)
|
||||
nsec = 2 * core_sectors;
|
||||
|
||||
if (err)
|
||||
{
|
||||
grub_util_warn ("%s", grub_errmsg);
|
||||
grub_errno = GRUB_ERR_NONE;
|
||||
goto unable_to_embed;
|
||||
}
|
||||
|
||||
/* Clean out the blocklists. */
|
||||
block = first_block;
|
||||
while (block->len)
|
||||
{
|
||||
grub_memset (block, 0, sizeof (block));
|
||||
|
||||
block--;
|
||||
|
||||
if ((char *) block <= core_img)
|
||||
grub_util_error ("No terminator in the core image");
|
||||
}
|
||||
|
||||
save_first_sector (sectors[0] + grub_partition_get_start (container),
|
||||
0, GRUB_DISK_SECTOR_SIZE);
|
||||
|
||||
block = first_block;
|
||||
for (i = 1; i < nsec; i++)
|
||||
save_blocklists (sectors[i] + grub_partition_get_start (container),
|
||||
0, GRUB_DISK_SECTOR_SIZE);
|
||||
|
||||
write_rootdev (core_img, root_dev, boot_img, first_sector);
|
||||
|
||||
core_img = realloc (core_img, nsec * GRUB_DISK_SECTOR_SIZE);
|
||||
first_block = (struct grub_boot_blocklist *) (core_img
|
||||
+ GRUB_DISK_SECTOR_SIZE
|
||||
- sizeof (*block));
|
||||
|
||||
*(grub_uint32_t *) (core_img + GRUB_DISK_SECTOR_SIZE
|
||||
+ GRUB_KERNEL_I386_PC_REED_SOLOMON_REDUNDANCY)
|
||||
= grub_host_to_target32 (nsec * GRUB_DISK_SECTOR_SIZE - core_size);
|
||||
|
||||
grub_reed_solomon_add_redundancy (core_img + GRUB_KERNEL_I386_PC_NO_REED_SOLOMON_PART + GRUB_DISK_SECTOR_SIZE,
|
||||
core_size - GRUB_KERNEL_I386_PC_NO_REED_SOLOMON_PART - GRUB_DISK_SECTOR_SIZE,
|
||||
nsec * GRUB_DISK_SECTOR_SIZE
|
||||
- core_size);
|
||||
|
||||
/* Make sure that the second blocklist is a terminator. */
|
||||
block = first_block - 1;
|
||||
block->start = 0;
|
||||
block->len = 0;
|
||||
block->segment = 0;
|
||||
|
||||
/* Write the core image onto the disk. */
|
||||
for (i = 0; i < nsec; i++)
|
||||
grub_disk_write (dest_dev->disk, sectors[i], 0,
|
||||
GRUB_DISK_SECTOR_SIZE,
|
||||
core_img + i * GRUB_DISK_SECTOR_SIZE);
|
||||
|
||||
grub_free (sectors);
|
||||
|
||||
goto finish;
|
||||
}
|
||||
#endif
|
||||
|
||||
unable_to_embed:
|
||||
|
||||
if (must_embed)
|
||||
grub_util_error (_("embedding is not possible, but this is required when "
|
||||
"the root device is on a RAID array or LVM volume"));
|
||||
|
||||
#ifdef GRUB_MACHINE_PCBIOS
|
||||
if (dest_dev->disk->id != root_dev->disk->id)
|
||||
grub_util_error (_("embedding is not possible, but this is required for "
|
||||
"cross-disk install"));
|
||||
#endif
|
||||
|
||||
grub_util_warn (_("Embedding is not possible. GRUB can only be installed in this "
|
||||
"setup by using blocklists. However, blocklists are UNRELIABLE and "
|
||||
"their use is discouraged."));
|
||||
if (! force)
|
||||
grub_util_error (_("will not proceed with blocklists"));
|
||||
|
||||
/* 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);
|
||||
core_path_dev = grub_make_system_path_relative_to_its_root (core_path_dev_full);
|
||||
free (core_path_dev_full);
|
||||
|
||||
/* 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 ((i == 0) ? _("attempting to read the core image `%s' from GRUB")
|
||||
: _("attempting to read the core image `%s' from GRUB again"),
|
||||
core_path_dev);
|
||||
|
||||
grub_disk_cache_invalidate_all ();
|
||||
|
||||
grub_file_filter_disable_compression ();
|
||||
file = grub_file_open (core_path_dev);
|
||||
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_dev);
|
||||
|
||||
/* Clean out the blocklists. */
|
||||
block = first_block;
|
||||
while (block->len)
|
||||
{
|
||||
block->start = 0;
|
||||
block->len = 0;
|
||||
#ifdef GRUB_MACHINE_PCBIOS
|
||||
block->segment = 0;
|
||||
#endif
|
||||
|
||||
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_dev);
|
||||
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"));
|
||||
|
||||
#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);
|
||||
|
||||
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);
|
||||
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 * 2, fp);
|
||||
fclose (fp);
|
||||
|
||||
finish:
|
||||
|
||||
/* Write the boot image onto the disk. */
|
||||
if (grub_disk_write (dest_dev->disk, BOOT_SECTOR,
|
||||
0, GRUB_DISK_SECTOR_SIZE, boot_img))
|
||||
grub_util_error ("%s", grub_errmsg);
|
||||
|
||||
|
||||
/* Sync is a Good Thing. */
|
||||
sync ();
|
||||
|
||||
free (core_path);
|
||||
free (core_img);
|
||||
free (boot_img);
|
||||
grub_device_close (dest_dev);
|
||||
grub_device_close (root_dev);
|
||||
}
|
||||
|
||||
static struct argp_option options[] = {
|
||||
{"boot-image", 'b', N_("FILE"), 0,
|
||||
N_("Use FILE as the boot image [default=%s]"), 0},
|
||||
{"core-image", 'c', N_("FILE"), 0,
|
||||
N_("Use FILE as the core image [default=%s]"), 0},
|
||||
{"directory", 'd', N_("DIR"), 0,
|
||||
N_("Use GRUB files in the directory DIR [default=%s]"), 0},
|
||||
{"device-map", 'm', N_("FILE"), 0,
|
||||
N_("Use FILE as the device map [default=%s]"), 0},
|
||||
{"root-device", 'r', N_("DEV"), 0,
|
||||
N_("Use DEV as the root device [default=guessed]"), 0},
|
||||
{"force", 'f', 0, 0,
|
||||
N_("Install even if problems are detected"), 0},
|
||||
{"skip-fs-probe",'s',0, 0,
|
||||
N_("Do not probe for filesystems in DEVICE"), 0},
|
||||
{"verbose", 'v', 0, 0,
|
||||
N_("Print verbose messages."), 0},
|
||||
{"allow-floppy", 'a', 0, 0,
|
||||
N_("Make the drive also bootable as floppy (default for fdX devices). May break on some BIOSes."), 0},
|
||||
|
||||
{ 0, 0, 0, 0, 0, 0 }
|
||||
};
|
||||
|
||||
static char *
|
||||
help_filter (int key, const char *text, void *input __attribute__ ((unused)))
|
||||
{
|
||||
switch (key)
|
||||
{
|
||||
case 'b':
|
||||
return xasprintf (text, DEFAULT_BOOT_FILE);
|
||||
|
||||
case 'c':
|
||||
return xasprintf (text, DEFAULT_CORE_FILE);
|
||||
|
||||
case 'd':
|
||||
return xasprintf (text, DEFAULT_DIRECTORY);
|
||||
|
||||
case 'm':
|
||||
return xasprintf (text, DEFAULT_DEVICE_MAP);
|
||||
|
||||
default:
|
||||
return (char *) text;
|
||||
}
|
||||
}
|
||||
|
||||
struct arguments
|
||||
{
|
||||
char *boot_file;
|
||||
char *core_file;
|
||||
char *dir;
|
||||
char *dev_map;
|
||||
char *root_dev;
|
||||
int force;
|
||||
int fs_probe;
|
||||
int allow_floppy;
|
||||
char *device;
|
||||
};
|
||||
|
||||
/* Print the version information. */
|
||||
static void
|
||||
print_version (FILE *stream, struct argp_state *state)
|
||||
{
|
||||
fprintf (stream, "%s (%s) %s\n", program_name, PACKAGE_NAME, PACKAGE_VERSION);
|
||||
}
|
||||
void (*argp_program_version_hook) (FILE *, struct argp_state *) = print_version;
|
||||
|
||||
/* Set the bug report address */
|
||||
const char *argp_program_bug_address = "<"PACKAGE_BUGREPORT">";
|
||||
|
||||
static error_t
|
||||
argp_parser (int key, char *arg, struct argp_state *state)
|
||||
{
|
||||
/* Get the input argument from argp_parse, which we
|
||||
know is a pointer to our arguments structure. */
|
||||
struct arguments *arguments = state->input;
|
||||
|
||||
char *p;
|
||||
|
||||
switch (key)
|
||||
{
|
||||
case 'a':
|
||||
arguments->allow_floppy = 1;
|
||||
break;
|
||||
|
||||
case 'b':
|
||||
if (arguments->boot_file)
|
||||
free (arguments->boot_file);
|
||||
|
||||
arguments->boot_file = xstrdup (arg);
|
||||
break;
|
||||
|
||||
case 'c':
|
||||
if (arguments->core_file)
|
||||
free (arguments->core_file);
|
||||
|
||||
arguments->core_file = xstrdup (arg);
|
||||
break;
|
||||
|
||||
case 'd':
|
||||
if (arguments->dir)
|
||||
free (arguments->dir);
|
||||
|
||||
arguments->dir = xstrdup (arg);
|
||||
break;
|
||||
|
||||
case 'm':
|
||||
if (arguments->dev_map)
|
||||
free (arguments->dev_map);
|
||||
|
||||
arguments->dev_map = xstrdup (arg);
|
||||
break;
|
||||
|
||||
case 'r':
|
||||
if (arguments->root_dev)
|
||||
free (arguments->root_dev);
|
||||
|
||||
arguments->root_dev = xstrdup (arg);
|
||||
break;
|
||||
|
||||
case 'f':
|
||||
arguments->force = 1;
|
||||
break;
|
||||
|
||||
case 's':
|
||||
arguments->fs_probe = 0;
|
||||
break;
|
||||
|
||||
case 'v':
|
||||
verbosity++;
|
||||
break;
|
||||
|
||||
case ARGP_KEY_ARG:
|
||||
if (state->arg_num == 0)
|
||||
arguments->device = xstrdup(arg);
|
||||
else
|
||||
{
|
||||
/* Too many arguments. */
|
||||
fprintf (stderr, _("Unknown extra argument `%s'.\n"), arg);
|
||||
argp_usage (state);
|
||||
}
|
||||
break;
|
||||
|
||||
case ARGP_KEY_NO_ARGS:
|
||||
fprintf (stderr, "%s", _("No device is specified.\n"));
|
||||
argp_usage (state);
|
||||
break;
|
||||
|
||||
default:
|
||||
return ARGP_ERR_UNKNOWN;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct argp argp = {
|
||||
options, argp_parser, N_("DEVICE"),
|
||||
"\n"N_("\
|
||||
Set up images to boot from DEVICE.\n\
|
||||
\n\
|
||||
You should not normally run this program directly. Use grub-install instead.")
|
||||
"\v"N_("\
|
||||
DEVICE must be an OS device (e.g. /dev/sda)."),
|
||||
NULL, help_filter, NULL
|
||||
};
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
char *root_dev = NULL;
|
||||
char *dest_dev = NULL;
|
||||
int must_embed = 0;
|
||||
struct arguments arguments;
|
||||
|
||||
set_program_name (argv[0]);
|
||||
|
||||
grub_util_init_nls ();
|
||||
|
||||
/* Default option values. */
|
||||
memset (&arguments, 0, sizeof (struct arguments));
|
||||
arguments.fs_probe = 1;
|
||||
|
||||
/* Parse our arguments */
|
||||
if (argp_parse (&argp, argc, argv, 0, 0, &arguments) != 0)
|
||||
{
|
||||
fprintf (stderr, "%s", _("Error in parsing command line arguments\n"));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
#ifdef GRUB_MACHINE_IEEE1275
|
||||
arguments.force = 1;
|
||||
#endif
|
||||
|
||||
if (verbosity > 1)
|
||||
grub_env_set ("debug", "all");
|
||||
|
||||
/* Initialize the emulated biosdisk driver. */
|
||||
grub_util_biosdisk_init (arguments.dev_map ? : DEFAULT_DEVICE_MAP);
|
||||
|
||||
/* Initialize all modules. */
|
||||
grub_init_all ();
|
||||
|
||||
grub_lvm_fini ();
|
||||
grub_mdraid09_fini ();
|
||||
grub_mdraid1x_fini ();
|
||||
grub_raid_fini ();
|
||||
grub_raid_init ();
|
||||
grub_mdraid09_init ();
|
||||
grub_mdraid1x_init ();
|
||||
grub_lvm_init ();
|
||||
|
||||
dest_dev = get_device_name (arguments.device);
|
||||
if (! dest_dev)
|
||||
{
|
||||
/* Possibly, the user specified an OS device file. */
|
||||
dest_dev = grub_util_get_grub_dev (arguments.device);
|
||||
if (! dest_dev)
|
||||
{
|
||||
char *program = xstrdup(program_name);
|
||||
fprintf (stderr, _("Invalid device `%s'.\n"), arguments.device);
|
||||
argp_help (&argp, stderr, ARGP_HELP_STD_USAGE, program);
|
||||
free(program);
|
||||
exit(1);
|
||||
}
|
||||
grub_util_info ("transformed OS device `%s' into GRUB device `%s'",
|
||||
arguments.device, dest_dev);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* For simplicity. */
|
||||
dest_dev = xstrdup (dest_dev);
|
||||
grub_util_info ("Using `%s' as GRUB device", dest_dev);
|
||||
}
|
||||
|
||||
if (arguments.root_dev)
|
||||
{
|
||||
root_dev = get_device_name (arguments.root_dev);
|
||||
|
||||
if (! root_dev)
|
||||
grub_util_error (_("invalid root device `%s'"), arguments.root_dev);
|
||||
|
||||
root_dev = xstrdup (root_dev);
|
||||
}
|
||||
else
|
||||
{
|
||||
char *root_device =
|
||||
grub_guess_root_device (arguments.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,
|
||||
arguments.dir ? : DEFAULT_DIRECTORY);
|
||||
}
|
||||
|
||||
#ifdef __linux__
|
||||
if (grub_util_lvm_isvolume (root_dev))
|
||||
must_embed = 1;
|
||||
|
||||
if (root_dev[0] == 'm' && root_dev[1] == 'd'
|
||||
&& ((root_dev[2] >= '0' && root_dev[2] <= '9') || root_dev[2] == '/'))
|
||||
{
|
||||
/* FIXME: we can avoid this on RAID1. */
|
||||
must_embed = 1;
|
||||
}
|
||||
|
||||
if (dest_dev[0] == 'm' && dest_dev[1] == 'd'
|
||||
&& ((dest_dev[2] >= '0' && dest_dev[2] <= '9') || dest_dev[2] == '/'))
|
||||
{
|
||||
char **devicelist;
|
||||
int i;
|
||||
|
||||
devicelist = grub_util_raid_getmembers (dest_dev);
|
||||
|
||||
for (i = 0; devicelist[i]; i++)
|
||||
{
|
||||
setup (arguments.dir ? : DEFAULT_DIRECTORY,
|
||||
arguments.boot_file ? : DEFAULT_BOOT_FILE,
|
||||
arguments.core_file ? : DEFAULT_CORE_FILE,
|
||||
root_dev, grub_util_get_grub_dev (devicelist[i]), 1,
|
||||
arguments.force, arguments.fs_probe,
|
||||
arguments.allow_floppy);
|
||||
}
|
||||
}
|
||||
else
|
||||
#endif
|
||||
/* Do the real work. */
|
||||
setup (arguments.dir ? : DEFAULT_DIRECTORY,
|
||||
arguments.boot_file ? : DEFAULT_BOOT_FILE,
|
||||
arguments.core_file ? : DEFAULT_CORE_FILE,
|
||||
root_dev, dest_dev, must_embed, arguments.force,
|
||||
arguments.fs_probe, arguments.allow_floppy);
|
||||
|
||||
/* Free resources. */
|
||||
grub_fini_all ();
|
||||
grub_util_biosdisk_fini ();
|
||||
|
||||
free (arguments.boot_file);
|
||||
free (arguments.core_file);
|
||||
free (arguments.dir);
|
||||
free (arguments.root_dev);
|
||||
free (arguments.dev_map);
|
||||
free (arguments.device);
|
||||
free (root_dev);
|
||||
free (dest_dev);
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -23,7 +23,7 @@ prefix=@prefix@
|
|||
exec_prefix=@exec_prefix@
|
||||
libdir=@libdir@
|
||||
locale_dir=`echo ${GRUB_PREFIX}/locale | sed ${transform}`
|
||||
grub_lang=`echo $LANG | cut -d _ -f 1`
|
||||
grub_lang=`echo $LANG | cut -d . -f 1`
|
||||
|
||||
. ${libdir}/grub/grub-mkconfig_lib
|
||||
|
||||
|
@ -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}"
|
||||
|
|
|
@ -81,14 +81,16 @@ do
|
|||
menuentry "${OS} ${KERNEL}" ${CLASS} {
|
||||
EOF
|
||||
prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | sed -e "s/^/\t/"
|
||||
message="$(gettext_printf "Loading GNU Mach ...")"
|
||||
cat << EOF
|
||||
echo '$(gettext_quoted "Loading GNU Mach ...")'
|
||||
echo '$message'
|
||||
multiboot ${kernel} root=device:${GRUB_DEVICE#/dev/}
|
||||
EOF
|
||||
save_default_entry | sed -e "s/^/\t/"
|
||||
prepare_grub_to_access_device ${GRUB_DEVICE} | sed -e "s/^/\t/"
|
||||
message="$(gettext_printf "Loading the Hurd ...")"
|
||||
cat << EOF
|
||||
echo '$(gettext_quoted "Loading the Hurd ...")'
|
||||
echo '$message'
|
||||
module /hurd/${hurd_fs}.static ${hurd_fs} --readonly \\
|
||||
--multiboot-command-line='\${kernel-command-line}' \\
|
||||
--host-priv-port='\${host-port}' \\
|
||||
|
@ -103,14 +105,15 @@ EOF
|
|||
menuentry "${OS} ${KERNEL} (recovery mode)" ${CLASS} {
|
||||
EOF
|
||||
prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | sed -e "s/^/\t/"
|
||||
message="$(gettext_printf "Loading GNU Mach ...")"
|
||||
cat << EOF
|
||||
echo '$(gettext_quoted "Loading GNU Mach ...")'
|
||||
echo '$message'
|
||||
multiboot ${kernel} root=device:${GRUB_DEVICE#/dev/} -s
|
||||
EOF
|
||||
save_default_entry | sed -e "s/^/\t/"
|
||||
prepare_grub_to_access_device ${GRUB_DEVICE} | sed -e "s/^/\t/"
|
||||
message="$(gettext_printf "Loading the Hurd ...")"
|
||||
cat << EOF
|
||||
echo '$(gettext_quoted "Loading the Hurd ...")'
|
||||
echo '$message'
|
||||
module /hurd/${hurd_fs}.static ${hurd_fs} \\
|
||||
--multiboot-command-line='\${kernel-command-line}' \\
|
||||
--host-priv-port='\${host-port}' \\
|
||||
|
|
|
@ -68,19 +68,26 @@ kfreebsd_entry ()
|
|||
{
|
||||
os="$1"
|
||||
version="$2"
|
||||
recovery="$3" # not used yet
|
||||
args="$4" # not used yet
|
||||
title="$(gettext_quoted "%s, with kFreeBSD %s")"
|
||||
recovery="$3"
|
||||
args="$4"
|
||||
if ${recovery} ; then
|
||||
title="$(gettext_quoted "%s, with kFreeBSD %s (recovery mode)")"
|
||||
else
|
||||
title="$(gettext_quoted "%s, with kFreeBSD %s")"
|
||||
fi
|
||||
printf "menuentry '${title}' ${CLASS} {\n" "${os}" "${version}"
|
||||
save_default_entry | sed -e "s/^/\t/"
|
||||
if ! ${recovery} ; then
|
||||
save_default_entry | sed -e "s/^/\t/"
|
||||
fi
|
||||
if [ -z "${prepare_boot_cache}" ]; then
|
||||
prepare_boot_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | sed -e "s/^/\t/")"
|
||||
fi
|
||||
|
||||
printf '%s\n' "${prepare_boot_cache}"
|
||||
message="$(gettext_printf "Loading kernel of FreeBSD %s ..." ${version})"
|
||||
cat << EOF
|
||||
echo '$(printf "$(gettext_quoted "Loading kernel of FreeBSD %s ...")" ${version})'
|
||||
kfreebsd ${rel_dirname}/${basename}
|
||||
echo '$message'
|
||||
kfreebsd ${rel_dirname}/${basename} ${args}
|
||||
EOF
|
||||
|
||||
if test -n "${devices}" ; then
|
||||
|
@ -138,8 +145,22 @@ while [ "x$list" != "x" ] ; do
|
|||
esac
|
||||
|
||||
case ${GRUB_FS} in
|
||||
zfs) kfreebsd_device=$(grub-probe -t fs_label --device ${GRUB_DEVICE}) ;;
|
||||
*) kfreebsd_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=${kfreebsd_fs}id/${GRUB_DEVICE_UUID}
|
||||
# Debian GNU/kFreeBSD can't remount root if it's supplied as UUID but
|
||||
# as an UUID
|
||||
if [ "x${GRUB_DISTRIBUTOR}" = "xDebian" ] \
|
||||
&& ! (cat /etc/fstab | awk '!/^[[:space:]]*#/ && $2=="/" { print $1; }' \
|
||||
| grep "${kfreebsd_fs}id/${GRUB_DEVICE_UUID}" > /dev/null); then
|
||||
kfreebsd_device=${GRUB_DEVICE}
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
version=`echo $basename | sed -e "s,^[^0-9]*-,,g;s/\.gz$//g"`
|
||||
|
@ -158,7 +179,10 @@ while [ "x$list" != "x" ] ; do
|
|||
module_dir_rel=$(make_system_path_relative_to_its_root $module_dir)
|
||||
fi
|
||||
|
||||
kfreebsd_entry "${OS}" "${version}"
|
||||
kfreebsd_entry "${OS}" "${version}" false
|
||||
if [ "x${GRUB_DISABLE_RECOVERY}" != "xtrue" ]; then
|
||||
kfreebsd_entry "${OS}" "${version}" true "-s"
|
||||
fi
|
||||
|
||||
list=`echo $list | tr ' ' '\n' | grep -vx $kfreebsd | tr '\n' ' '`
|
||||
done
|
||||
|
|
|
@ -63,7 +63,9 @@ linux_entry ()
|
|||
title="$(gettext_quoted "%s, with Linux %s")"
|
||||
fi
|
||||
printf "menuentry '${title}' ${CLASS} {\n" "${os}" "${version}"
|
||||
save_default_entry | sed -e "s/^/\t/"
|
||||
if ! ${recovery} ; then
|
||||
save_default_entry | sed -e "s/^/\t/"
|
||||
fi
|
||||
|
||||
# Use ELILO's generic "efifb" when it's known to be available.
|
||||
# FIXME: We need an interface to select vesafb in case efifb can't be used.
|
||||
|
@ -78,6 +80,11 @@ EOF
|
|||
EOF
|
||||
fi
|
||||
else
|
||||
if [ "x$GRUB_GFXPAYLOAD_LINUX" != xtext ]; then
|
||||
cat << EOF
|
||||
load_video
|
||||
EOF
|
||||
fi
|
||||
cat << EOF
|
||||
set gfxpayload=$GRUB_GFXPAYLOAD_LINUX
|
||||
EOF
|
||||
|
@ -87,13 +94,15 @@ EOF
|
|||
prepare_boot_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | sed -e "s/^/\t/")"
|
||||
fi
|
||||
printf '%s\n' "${prepare_boot_cache}"
|
||||
message="$(gettext_printf "Loading Linux %s ..." ${version})"
|
||||
cat << EOF
|
||||
echo '$(printf "$(gettext_quoted "Loading Linux %s ...")" ${version})'
|
||||
echo '$message'
|
||||
linux ${rel_dirname}/${basename} root=${linux_root_device_thisversion} ro ${args}
|
||||
EOF
|
||||
if test -n "${initrd}" ; then
|
||||
message="$(gettext_printf "Loading initial ramdisk ...")"
|
||||
cat << EOF
|
||||
echo '$(gettext_quoted "Loading initial ramdisk ...")'
|
||||
echo '$message'
|
||||
initrd ${rel_dirname}/${initrd}
|
||||
EOF
|
||||
fi
|
||||
|
@ -102,7 +111,7 @@ EOF
|
|||
EOF
|
||||
}
|
||||
|
||||
list=`for i in /boot/vmlinu[zx]-* /vmlinu[zx]-* ; do
|
||||
list=`for i in /boot/vmlinuz-* /boot/vmlinux-* /vmlinuz-* /vmlinux-* ; do
|
||||
if grub_file_is_not_garbage "$i" ; then echo -n "$i " ; fi
|
||||
done`
|
||||
prepare_boot_cache=
|
||||
|
@ -127,16 +136,26 @@ while [ "x$list" != "x" ] ; do
|
|||
break
|
||||
fi
|
||||
done
|
||||
|
||||
initramfs=
|
||||
for i in "config-${version}" "config-${alt_version}"; do
|
||||
if test -e "${dirname}/${i}" ; then
|
||||
initramfs=`grep CONFIG_INITRAMFS_SOURCE= "${dirname}/${i}" | cut -f2 -d= | tr -d \"`
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
if test -n "${initrd}" ; then
|
||||
echo "Found initrd image: ${dirname}/${initrd}" >&2
|
||||
else
|
||||
# "UUID=" magic is parsed by initrds. Since there's no initrd, it can't work here.
|
||||
elif test -z "${initramfs}" ; then
|
||||
# "UUID=" magic is parsed by initrd or initramfs. Since there's
|
||||
# no initrd or builtin initramfs, it can't work here.
|
||||
linux_root_device_thisversion=${GRUB_DEVICE}
|
||||
fi
|
||||
|
||||
linux_entry "${OS}" "${version}" false \
|
||||
"${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}"
|
||||
if [ "x${GRUB_DISABLE_LINUX_RECOVERY}" != "xtrue" ]; then
|
||||
if [ "x${GRUB_DISABLE_RECOVERY}" != "xtrue" ]; then
|
||||
linux_entry "${OS}" "${version}" true \
|
||||
"single ${GRUB_CMDLINE_LINUX}"
|
||||
fi
|
||||
|
|
|
@ -80,7 +80,7 @@ for k in $(ls -t /netbsd*) ; do
|
|||
echo "Found NetBSD kernel: $k" >&2
|
||||
netbsd_entry "knetbsd" "$k" false "${GRUB_CMDLINE_NETBSD_DEFAULT}"
|
||||
netbsd_entry "multiboot" "$k" false "${GRUB_CMDLINE_NETBSD_DEFAULT}"
|
||||
if [ "x${GRUB_DISABLE_NETBSD_RECOVERY}" != "xtrue" ]; then
|
||||
if [ "x${GRUB_DISABLE_RECOVERY}" != "xtrue" ]; then
|
||||
netbsd_entry "knetbsd" "$k" true "-s"
|
||||
netbsd_entry "multiboot" "$k" true "-s"
|
||||
fi
|
||||
|
|
|
@ -65,20 +65,24 @@ linux_entry ()
|
|||
title="$(gettext_quoted "%s, with Linux %s and XEN %s")"
|
||||
fi
|
||||
printf "menuentry '${title}' ${CLASS} {\n" "${os}" "${version}" "${xen_version}"
|
||||
save_default_entry | sed -e "s/^/\t/"
|
||||
if ! ${recovery} ; then
|
||||
save_default_entry | sed -e "s/^/\t/"
|
||||
fi
|
||||
|
||||
if [ -z "${prepare_boot_cache}" ]; then
|
||||
prepare_boot_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | sed -e "s/^/\t/")"
|
||||
fi
|
||||
printf '%s\n' "${prepare_boot_cache}"
|
||||
message="$(gettext_printf "Loading Linux %s ..." ${version})"
|
||||
cat << EOF
|
||||
echo '$(printf "$(gettext_quoted "Loading Linux %s ...")" ${version})'
|
||||
echo '$message'
|
||||
multiboot ${rel_xen_dirname}/${xen_basename} placeholder ${xen_args}
|
||||
module ${rel_dirname}/${basename} placeholder root=${linux_root_device_thisversion} ro ${args}
|
||||
EOF
|
||||
if test -n "${initrd}" ; then
|
||||
message="$(gettext_printf "Loading initial ramdisk ...")"
|
||||
cat << EOF
|
||||
echo '$(gettext_quoted "Loading initial ramdisk ...")'
|
||||
echo '$message'
|
||||
module ${rel_dirname}/${initrd}
|
||||
EOF
|
||||
fi
|
||||
|
@ -104,6 +108,7 @@ while [ "x${xen_list}" != "x" ] ; do
|
|||
xen_dirname=`dirname ${current_xen}`
|
||||
rel_xen_dirname=`make_system_path_relative_to_its_root $xen_dirname`
|
||||
xen_version=`echo $xen_basename | sed -e "s,.gz$,,g;s,^xen-,,g"`
|
||||
echo "submenu \"Xen ${xen_version}\" {"
|
||||
while [ "x$list" != "x" ] ; do
|
||||
linux=`version_find_latest $list`
|
||||
echo "Found linux image: $linux" >&2
|
||||
|
@ -132,12 +137,13 @@ while [ "x${xen_list}" != "x" ] ; do
|
|||
|
||||
linux_entry "${OS}" "${version}" "${xen_version}" false \
|
||||
"${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}" "${GRUB_CMDLINE_XEN} ${GRUB_CMDLINE_XEN_DEFAULT}"
|
||||
if [ "x${GRUB_DISABLE_LINUX_RECOVERY}" != "xtrue" ]; then
|
||||
if [ "x${GRUB_DISABLE_RECOVERY}" != "xtrue" ]; then
|
||||
linux_entry "${OS}" "${version}" "${xen_version}" true \
|
||||
"single ${GRUB_CMDLINE_LINUX}" "${GRUB_CMDLINE_XEN}"
|
||||
fi
|
||||
|
||||
list=`echo $list | tr ' ' '\n' | grep -vx $linux | tr '\n' ' '`
|
||||
done
|
||||
echo "}"
|
||||
xen_list=`echo $xen_list | tr ' ' '\n' | grep -vx $current_xen | tr '\n' ' '`
|
||||
done
|
||||
|
|
|
@ -40,7 +40,7 @@ fi
|
|||
|
||||
osx_entry() {
|
||||
cat << EOF
|
||||
menuentry "${LONGNAME} (${2}-bit) (on ${DEVICE})" {
|
||||
menuentry "${LONGNAME} (${2}-bit) (on ${DEVICE})" --class osx --class darwin --class os {
|
||||
EOF
|
||||
save_default_entry | sed -e "s/^/\t/"
|
||||
prepare_grub_to_access_device ${DEVICE} | sed -e "s/^/\t/"
|
||||
|
@ -105,13 +105,13 @@ for OS in ${OSPROBED} ; do
|
|||
chain)
|
||||
|
||||
cat << EOF
|
||||
menuentry "${LONGNAME} (on ${DEVICE})" {
|
||||
menuentry "${LONGNAME} (on ${DEVICE})" --class windows --class os {
|
||||
EOF
|
||||
save_default_entry | sed -e "s/^/\t/"
|
||||
prepare_grub_to_access_device ${DEVICE} | sed -e "s/^/\t/"
|
||||
|
||||
case ${LONGNAME} in
|
||||
Windows\ Vista*|Windows\ 7*)
|
||||
Windows\ Vista*|Windows\ 7*|Windows\ Server\ 2008*)
|
||||
;;
|
||||
*)
|
||||
cat << EOF
|
||||
|
@ -147,7 +147,7 @@ EOF
|
|||
fi
|
||||
|
||||
cat << EOF
|
||||
menuentry "${LLABEL} (on ${DEVICE})" {
|
||||
menuentry "${LLABEL} (on ${DEVICE})" --class gnu-linux --class gnu --class os {
|
||||
EOF
|
||||
save_default_entry | sed -e "s/^/\t/"
|
||||
if [ -z "${prepare_boot_cache}" ]; then
|
||||
|
@ -174,7 +174,7 @@ EOF
|
|||
;;
|
||||
hurd)
|
||||
cat << EOF
|
||||
menuentry "${LONGNAME} (on ${DEVICE})" {
|
||||
menuentry "${LONGNAME} (on ${DEVICE})" --class hurd --class gnu --class os {
|
||||
EOF
|
||||
save_default_entry | sed -e "s/^/\t/"
|
||||
prepare_grub_to_access_device ${DEVICE} | sed -e "s/^/\t/"
|
||||
|
|
|
@ -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
|
|
@ -1,836 +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/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/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;
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <dirent.h>
|
||||
#include <assert.h>
|
||||
#include "progname.h"
|
||||
|
||||
#define _GNU_SOURCE 1
|
||||
#include <getopt.h>
|
||||
|
||||
#define DEFAULT_BOOT_FILE "boot.img"
|
||||
#define DEFAULT_CORE_FILE "core.img"
|
||||
|
||||
#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)
|
||||
|
||||
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)
|
||||
{
|
||||
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;
|
||||
grub_uint16_t current_segment
|
||||
= GRUB_BOOT_MACHINE_KERNEL_SEG + (GRUB_DISK_SECTOR_SIZE >> 4);
|
||||
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 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)
|
||||
{
|
||||
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> 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);
|
||||
install_prefix = (char *) (core_img + GRUB_DISK_SECTOR_SIZE +
|
||||
GRUB_KERNEL_MACHINE_PREFIX);
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
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)
|
||||
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;
|
||||
}
|
||||
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 (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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
grub_util_info ("the core image will be embedded at sector 0x%llx", embed_region.start);
|
||||
|
||||
*install_dos_part = grub_cpu_to_le32 (dos_part);
|
||||
*install_bsd_part = grub_cpu_to_le32 (bsd_part);
|
||||
if (prefix)
|
||||
strcpy (install_prefix, prefix);
|
||||
|
||||
/* The first blocklist contains the whole sectors. */
|
||||
first_block->start = grub_cpu_to_le64 (embed_region.start + 1);
|
||||
|
||||
/* 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)));
|
||||
|
||||
/* Make sure that the second blocklist is a terminator. */
|
||||
block = first_block - 1;
|
||||
block->start = 0;
|
||||
block->len = 0;
|
||||
block->segment = 0;
|
||||
|
||||
/* 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);
|
||||
|
||||
/* FIXME: can this be skipped? */
|
||||
*boot_drive = 0xFF;
|
||||
|
||||
*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);
|
||||
|
||||
goto finish;
|
||||
|
||||
unable_to_embed:
|
||||
|
||||
if (must_embed)
|
||||
grub_util_error (_("embedding is not possible, but this is required when "
|
||||
"the root device is on a RAID array or LVM volume"));
|
||||
|
||||
grub_util_warn (_("Embedding is not possible. GRUB can only be installed in this "
|
||||
"setup by using blocklists. However, blocklists are UNRELIABLE and "
|
||||
"their use is discouraged."));
|
||||
if (! force)
|
||||
grub_util_error (_("if you really want blocklists, use --force"));
|
||||
|
||||
/* 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);
|
||||
core_path_dev = grub_make_system_path_relative_to_its_root (core_path_dev_full);
|
||||
free (core_path_dev_full);
|
||||
|
||||
/* 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 ((i == 0) ? _("attempting to read the core image `%s' from GRUB")
|
||||
: _("attempting to read the core image `%s' from GRUB again"),
|
||||
core_path_dev);
|
||||
|
||||
grub_disk_cache_invalidate_all ();
|
||||
|
||||
file = grub_file_open (core_path_dev);
|
||||
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_dev);
|
||||
|
||||
/* Clean out the blocklists. */
|
||||
block = first_block;
|
||||
while (block->len)
|
||||
{
|
||||
block->start = 0;
|
||||
block->len = 0;
|
||||
block->segment = 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. */
|
||||
file = grub_file_open (core_path_dev);
|
||||
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"));
|
||||
|
||||
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 the first two sectors of the core image onto the disk. */
|
||||
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 * 2, fp);
|
||||
fclose (fp);
|
||||
|
||||
/* 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);
|
||||
|
||||
finish:
|
||||
|
||||
/* Sync is a Good Thing. */
|
||||
sync ();
|
||||
|
||||
free (prefix);
|
||||
free (core_path);
|
||||
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'},
|
||||
{"force", no_argument, 0, 'f'},
|
||||
{"skip-fs-probe", no_argument, 0, 's'},
|
||||
{"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\
|
||||
-f, --force install even if problems are detected\n\
|
||||
-s, --skip-fs-probe do not probe for filesystems in DEVICE\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);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
int must_embed = 0, force = 0, fs_probe = 1;
|
||||
|
||||
set_program_name (argv[0]);
|
||||
|
||||
grub_util_init_nls ();
|
||||
|
||||
/* Check for options. */
|
||||
while (1)
|
||||
{
|
||||
int c = getopt_long (argc, argv, "b:c:d:m:r:hVvf", options, 0);
|
||||
|
||||
if (c == -1)
|
||||
break;
|
||||
else
|
||||
switch (c)
|
||||
{
|
||||
case 'b':
|
||||
if (boot_file)
|
||||
free (boot_file);
|
||||
|
||||
boot_file = xstrdup (optarg);
|
||||
break;
|
||||
|
||||
case 'c':
|
||||
if (core_file)
|
||||
free (core_file);
|
||||
|
||||
core_file = xstrdup (optarg);
|
||||
break;
|
||||
|
||||
case 'd':
|
||||
if (dir)
|
||||
free (dir);
|
||||
|
||||
dir = xstrdup (optarg);
|
||||
break;
|
||||
|
||||
case 'm':
|
||||
if (dev_map)
|
||||
free (dev_map);
|
||||
|
||||
dev_map = xstrdup (optarg);
|
||||
break;
|
||||
|
||||
case 'r':
|
||||
if (root_dev)
|
||||
free (root_dev);
|
||||
|
||||
root_dev = xstrdup (optarg);
|
||||
break;
|
||||
|
||||
case 'f':
|
||||
force = 1;
|
||||
break;
|
||||
|
||||
case 's':
|
||||
fs_probe = 0;
|
||||
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");
|
||||
|
||||
/* Obtain DEST_DEV. */
|
||||
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);
|
||||
}
|
||||
|
||||
/* Initialize the emulated biosdisk driver. */
|
||||
grub_util_biosdisk_init (dev_map ? : DEFAULT_DEVICE_MAP);
|
||||
|
||||
/* Initialize all modules. */
|
||||
grub_init_all ();
|
||||
|
||||
dest_dev = get_device_name (argv[optind]);
|
||||
if (! dest_dev)
|
||||
{
|
||||
/* Possibly, the user specified an OS device file. */
|
||||
dest_dev = grub_util_get_grub_dev (argv[optind]);
|
||||
if (! dest_dev)
|
||||
{
|
||||
fprintf (stderr, _("Invalid device `%s'.\n"), argv[optind]);
|
||||
usage (1);
|
||||
}
|
||||
}
|
||||
else
|
||||
/* For simplicity. */
|
||||
dest_dev = xstrdup (dest_dev);
|
||||
|
||||
if (root_dev)
|
||||
{
|
||||
char *tmp = get_device_name (root_dev);
|
||||
|
||||
if (! tmp)
|
||||
grub_util_error (_("invalid root device `%s'"), root_dev);
|
||||
|
||||
tmp = xstrdup (tmp);
|
||||
free (root_dev);
|
||||
root_dev = tmp;
|
||||
}
|
||||
else
|
||||
{
|
||||
root_dev = grub_util_get_grub_dev (grub_guess_root_device (dir ? : DEFAULT_DIRECTORY));
|
||||
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'"));
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef __linux__
|
||||
if (grub_util_lvm_isvolume (root_dev))
|
||||
must_embed = 1;
|
||||
|
||||
if (root_dev[0] == 'm' && root_dev[1] == 'd'
|
||||
&& ((root_dev[2] >= '0' && root_dev[2] <= '9') || root_dev[2] == '/'))
|
||||
{
|
||||
/* FIXME: we can avoid this on RAID1. */
|
||||
must_embed = 1;
|
||||
}
|
||||
|
||||
if (dest_dev[0] == 'm' && dest_dev[1] == 'd'
|
||||
&& ((dest_dev[2] >= '0' && dest_dev[2] <= '9') || dest_dev[2] == '/'))
|
||||
{
|
||||
char **devicelist;
|
||||
int i;
|
||||
|
||||
devicelist = grub_util_raid_getmembers (dest_dev);
|
||||
|
||||
for (i = 0; devicelist[i]; i++)
|
||||
{
|
||||
setup (dir ? : DEFAULT_DIRECTORY,
|
||||
boot_file ? : DEFAULT_BOOT_FILE,
|
||||
core_file ? : DEFAULT_CORE_FILE,
|
||||
root_dev, grub_util_get_grub_dev (devicelist[i]), 1, force, fs_probe);
|
||||
}
|
||||
}
|
||||
else
|
||||
#endif
|
||||
/* Do the real work. */
|
||||
setup (dir ? : DEFAULT_DIRECTORY,
|
||||
boot_file ? : DEFAULT_BOOT_FILE,
|
||||
core_file ? : DEFAULT_CORE_FILE,
|
||||
root_dev, dest_dev, must_embed, force, fs_probe);
|
||||
|
||||
/* Free resources. */
|
||||
grub_fini_all ();
|
||||
grub_util_biosdisk_fini ();
|
||||
|
||||
free (boot_file);
|
||||
free (core_file);
|
||||
free (dir);
|
||||
free (dev_map);
|
||||
free (root_dev);
|
||||
free (dest_dev);
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -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
|
|
@ -121,13 +121,13 @@ if [ "x${modules}" = "x" ] ; then
|
|||
modules=`cd ${input_dir}/ && ls *.mod`
|
||||
fi
|
||||
|
||||
map_file=`mktemp`
|
||||
map_file=`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1
|
||||
cat >${map_file} <<EOF
|
||||
# EXTN XLate CREATOR TYPE Comment
|
||||
grub.img Raw 'UNIX' 'tbxi' "bootstrap"
|
||||
EOF
|
||||
|
||||
iso_dir=`mktemp -d`
|
||||
iso_dir=`mktemp -d "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1
|
||||
boot_dir=${iso_dir}/boot/grub
|
||||
mkdir ${iso_dir}/boot
|
||||
mkdir ${boot_dir}
|
||||
|
|
28
util/raid.c
28
util/raid.c
|
@ -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++;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
|
|
@ -1,635 +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 ();
|
||||
|
||||
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. */
|
||||
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 ();
|
||||
|
||||
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