2011-07-25 06:19:30 +00:00
|
|
|
#! /bin/sh
|
|
|
|
set -e
|
|
|
|
|
|
|
|
# Make GRUB rescue image
|
2012-02-03 10:42:22 +00:00
|
|
|
# Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009,2010,2011,2012 Free Software Foundation, Inc.
|
2011-07-25 06:19:30 +00:00
|
|
|
#
|
|
|
|
# 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.
|
2012-01-24 12:17:36 +00:00
|
|
|
|
2011-07-25 06:19:30 +00:00
|
|
|
transform="@program_transform_name@"
|
|
|
|
|
2012-01-24 12:17:36 +00:00
|
|
|
prefix="@prefix@"
|
|
|
|
exec_prefix="@exec_prefix@"
|
|
|
|
datarootdir="@datarootdir@"
|
|
|
|
bindir="@bindir@"
|
|
|
|
libdir="@libdir@"
|
2011-07-25 06:19:30 +00:00
|
|
|
PACKAGE_NAME=@PACKAGE_NAME@
|
|
|
|
PACKAGE_TARNAME=@PACKAGE_TARNAME@
|
|
|
|
PACKAGE_VERSION=@PACKAGE_VERSION@
|
|
|
|
pkglib_DATA="moddep.lst command.lst fs.lst partmap.lst parttool.lst handler.lst video.lst crypto.lst terminal.lst"
|
2012-02-03 10:42:22 +00:00
|
|
|
datadir="@datadir@"
|
2011-07-25 06:19:30 +00:00
|
|
|
|
|
|
|
self=`basename $0`
|
|
|
|
|
2011-12-22 12:05:19 +00:00
|
|
|
source_directory=
|
2011-07-25 06:19:30 +00:00
|
|
|
compression=auto
|
|
|
|
format=
|
2012-01-24 12:17:36 +00:00
|
|
|
grub_mkimage="${bindir}/`echo grub-mkimage | sed ${transform}`"
|
2011-07-25 06:19:30 +00:00
|
|
|
source=
|
|
|
|
|
2012-02-03 10:42:22 +00:00
|
|
|
. "${datadir}/@PACKAGE@/grub-mkconfig_lib"
|
|
|
|
|
2011-07-25 06:19:30 +00:00
|
|
|
# Usage: usage
|
|
|
|
# Print the usage.
|
|
|
|
usage () {
|
2012-02-03 10:42:22 +00:00
|
|
|
formats="i386-coreboot i386-multiboot i386-pc i386-pc-pxe i386-efi i386-ieee1275 i386-qemu x86_64-efi mipsel-yeeloong-flash mipsel-fuloong2f-flash mipsel-loongson-elf powerpc-ieee1275 sparc64-ieee1275-raw sparc64-ieee1275-aout ia64-efi mips-arc mipsel-qemu_mips-elf mips-qemu_mips-flash mipsel-qemu_mips-flash mips-qemu_mips-elf"
|
|
|
|
gettext_printf "Usage: %s [OPTION] SOURCE...\n" "$self"
|
2012-02-08 18:26:01 +00:00
|
|
|
gettext "Generate a standalone image (containing all modules) in the selected format"
|
|
|
|
echo
|
2012-02-03 10:42:22 +00:00
|
|
|
gettext "Make GRUB rescue image."; echo
|
|
|
|
echo
|
|
|
|
printf " -h, --help %s\n" "$(gettext "print this message and exit")"
|
|
|
|
printf " -v, --version %s\n" "$(gettext "print the version information and exit")"
|
|
|
|
printf " -o, --output=%-11s%s\n" "$(gettext FILE)" "$(gettext "save output in FILE [required]")"
|
2012-02-05 10:23:47 +00:00
|
|
|
dir_msg="$(gettext_printf "use images and modules under DIR [default=%s/<platform>]" "${libdir}/$(echo ${PACKAGE_TARNAME} | sed ${transform})")"
|
2012-02-03 10:42:22 +00:00
|
|
|
printf " -d, --directory=%-8s%s\n" \
|
|
|
|
"DIR" "$dir_msg"
|
|
|
|
printf " -O, --format=%-11s%s" "$(gettext "FORMAT")" "$(gettext "generate an image in format")"; echo
|
|
|
|
printf " %s %s\n" "$(gettext "available formats:")" "$formats"
|
|
|
|
echo
|
|
|
|
printf " -C, --compression=(xz|none|auto) %s\n" "$(gettext "choose the compression to use")"
|
|
|
|
printf " --modules=%-14s%s\n" "$(gettext "MODULES")" "$(gettext "pre-load specified modules MODULES")"
|
|
|
|
printf " --grub-mkimage=%-9s%s\n" "$(gettext "FILE")" "$(gettext "use FILE as grub-mkimage")"
|
|
|
|
echo
|
|
|
|
gettext "Report bugs to <bug-grub@gnu.org>."; echo
|
2011-07-25 06:19:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
argument () {
|
|
|
|
opt=$1
|
|
|
|
shift
|
|
|
|
|
|
|
|
if test $# -eq 0; then
|
2012-02-03 10:42:22 +00:00
|
|
|
gettext_printf "%s: option requires an argument -- '%s'\n" "$0" "$opt" 1>&2
|
2011-07-25 06:19:30 +00:00
|
|
|
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)
|
2011-12-22 12:05:19 +00:00
|
|
|
modules=`argument $option "$@"`; shift ;;
|
2011-07-25 06:19:30 +00:00
|
|
|
--modules=*)
|
|
|
|
modules=`echo "$option" | sed 's/--modules=//'` ;;
|
|
|
|
|
|
|
|
-o | --output)
|
|
|
|
output_image=`argument $option "$@"`; shift ;;
|
|
|
|
--output=*)
|
|
|
|
output_image=`echo "$option" | sed 's/--output=//'` ;;
|
|
|
|
|
|
|
|
--directory | -d)
|
2011-12-22 12:05:19 +00:00
|
|
|
source_directory=`argument $option "$@"`; shift ;;
|
2011-07-25 06:19:30 +00:00
|
|
|
--directory=*)
|
2011-12-22 12:05:19 +00:00
|
|
|
source_directory=`echo "$option" | sed 's/--directory=//'` ;;
|
2011-07-25 06:19:30 +00:00
|
|
|
|
|
|
|
--grub-mkimage)
|
|
|
|
grub_mkimage=`argument $option "$@"`; shift ;;
|
|
|
|
--grub-mkimage=*)
|
|
|
|
grub_mkimage=`echo "$option" | sed 's/--grub-mkimage=//'` ;;
|
|
|
|
|
|
|
|
--compression | -C)
|
|
|
|
compression=`argument $option "$@"`; shift ;;
|
|
|
|
--compression=*)
|
2011-12-22 12:05:19 +00:00
|
|
|
compression=`echo "${option}" | sed 's/--compression=//'` ;;
|
2011-07-25 06:19:30 +00:00
|
|
|
|
|
|
|
--format | -O)
|
|
|
|
format=`argument $option "$@"`; shift ;;
|
|
|
|
--format=*)
|
2011-12-22 12:05:19 +00:00
|
|
|
format=`echo "${option}" | sed 's/--format=//'` ;;
|
2011-07-25 06:19:30 +00:00
|
|
|
|
|
|
|
*)
|
|
|
|
source="${source} ${option} $@"; break ;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
if [ "x${output_image}" = x ] ; then
|
2012-02-03 10:42:22 +00:00
|
|
|
gettext "output file must be specified" >&2
|
|
|
|
echo >&2
|
2011-07-25 06:19:30 +00:00
|
|
|
usage
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "x${format}" = x ] ; then
|
2012-02-05 10:23:47 +00:00
|
|
|
gettext "Target format not specified (use the -O option)." >&2
|
2012-02-03 10:42:22 +00:00
|
|
|
echo >&2
|
2011-07-25 06:19:30 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "x$source_directory" = x ] ; then
|
|
|
|
cpu="`echo $format | awk -F - '{ print $1; }'`"
|
|
|
|
platform="`echo $format | awk -F - '{ print $2; }'`"
|
|
|
|
case "$platform" in
|
2011-08-19 20:46:11 +00:00
|
|
|
yeeloong | fuloong | fuloong2f | fuloong2e)
|
2011-07-25 06:19:30 +00:00
|
|
|
platform=loongson ;;
|
|
|
|
esac
|
|
|
|
case "$cpu-$platform" in
|
|
|
|
mips-loongson)
|
|
|
|
cpu=mipsel ;;
|
|
|
|
esac
|
|
|
|
source_directory="${libdir}/$(echo ${PACKAGE_TARNAME} | sed ${transform})/$cpu-$platform"
|
|
|
|
fi
|
|
|
|
|
2012-02-09 13:45:56 +00:00
|
|
|
. "${source_directory}"/modinfo.sh
|
|
|
|
|
2011-07-25 06:19:30 +00:00
|
|
|
set $grub_mkimage dummy
|
|
|
|
if test -f "$1"; then
|
|
|
|
:
|
|
|
|
else
|
|
|
|
echo "$1: Not found." 1>&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
memdisk_dir="`mktemp -d "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"`" || exit 1
|
2012-02-09 13:45:56 +00:00
|
|
|
mkdir -p "${memdisk_dir}"/boot/grub/"${grub_modinfo_target_cpu}-${grub_modinfo_platform}"
|
2011-07-25 06:19:30 +00:00
|
|
|
|
|
|
|
for file in "${source_directory}/"*.mod "${source_directory}/"efiemu32.o "${source_directory}/"efiemu64.o; do
|
|
|
|
if test -f "$file"; then
|
2012-02-09 13:45:56 +00:00
|
|
|
cp -f "$file" "${memdisk_dir}"/boot/grub/"${grub_modinfo_target_cpu}-${grub_modinfo_platform}"
|
2011-07-25 06:19:30 +00:00
|
|
|
fi
|
|
|
|
done
|
2011-12-22 12:05:19 +00:00
|
|
|
|
2011-07-25 06:19:30 +00:00
|
|
|
for file in ${pkglib_DATA}; do
|
|
|
|
if test -f "${source_directory}/${file}"; then
|
2012-02-09 13:45:56 +00:00
|
|
|
cp -f "${source_directory}/${file}" "${memdisk_dir}"/boot/grub/"${grub_modinfo_target_cpu}-${grub_modinfo_platform}"
|
2011-07-25 06:19:30 +00:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
mkdir -p "${memdisk_dir}"/boot/grub/locale
|
|
|
|
for file in "${source_directory}"/po/*.mo; do
|
|
|
|
if test -f "$file"; then
|
|
|
|
cp -f "$file" "${memdisk_dir}"/boot/grub/locale/
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
for file in $source; do
|
|
|
|
cp -f "$file" "${memdisk_dir}"/"$file";
|
|
|
|
done
|
|
|
|
|
|
|
|
memdisk_img=`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1
|
|
|
|
|
|
|
|
(cd "${memdisk_dir}"; tar -cf - * $source) > "${memdisk_img}"
|
|
|
|
rm -rf "${memdisk_dir}"
|
2012-01-24 12:17:36 +00:00
|
|
|
"$grub_mkimage" -O "${format}" -C "$compression" -d "${source_directory}" -m "${memdisk_img}" -o "$output_image" --prefix='(memdisk)/boot/grub' memdisk tar $modules
|
2011-07-25 06:19:30 +00:00
|
|
|
rm -rf "${memdisk_img}"
|
|
|
|
|
|
|
|
exit 0
|