4 # Make GRUB rescue image
5 # Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009,2010 Free Software Foundation, Inc.
7 # GRUB is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
12 # GRUB is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with GRUB. If not, see <http://www.gnu.org/licenses/>.
20 # Initialize some variables.
21 transform
="@program_transform_name@"
24 exec_prefix
=@exec_prefix@
27 PACKAGE_NAME
=@PACKAGE_NAME@
28 PACKAGE_TARNAME
=@PACKAGE_TARNAME@
29 PACKAGE_VERSION
=@PACKAGE_VERSION@
30 target_cpu
=@target_cpu@
31 native_platform
=@platform@
32 pkglib_DATA
="moddep.lst command.lst fs.lst partmap.lst parttool.lst handler.lst video.lst crypto.lst terminal.lst"
36 multiboot_dir
=${libdir}/$(echo ${PACKAGE_TARNAME} | sed ${transform})/i386-multiboot
37 coreboot_dir
=${libdir}/$(echo ${PACKAGE_TARNAME} | sed ${transform})/i386-coreboot
38 qemu_dir
=${libdir}/$(echo ${PACKAGE_TARNAME} | sed ${transform})/i386-qemu
39 pc_dir
=${libdir}/$(echo ${PACKAGE_TARNAME} | sed ${transform})/i386-pc
40 efi32_dir
=${libdir}/$(echo ${PACKAGE_TARNAME} | sed ${transform})/i386-efi
41 efi64_dir
=${libdir}/$(echo ${PACKAGE_TARNAME} | sed ${transform})/x86_64-efi
44 grub_mkimage
=${bindir}/`echo grub-mkimage | sed ${transform}`
52 Usage: $self [OPTION] SOURCE...
53 Make GRUB rescue image.
55 -h, --help print this message and exit
56 -v, --version print the version information and exit
57 -o, --output=FILE save output in FILE [required]
58 --modules=MODULES pre-load specified modules MODULES
59 --rom-directory=DIR save rom images in DIR [optional]
60 --xorriso=FILE use FILE as xorriso [optional]
61 --grub-mkimage=FILE use FILE as grub-mkimage
63 $self generates a bootable rescue image with specified source files, source
64 directories, or mkisofs options listed by: xorriso -as mkisofs -help
66 Option -- switches to native xorriso command mode.
68 Report bugs to <bug-grub@gnu.org>.
69 Mail xorriso support requests to <bug-xorriso@gnu.org>.
77 if test $# -eq 0; then
78 echo "$0: option requires an argument -- '$opt'" 1>&2
84 # Check the arguments.
95 echo "$self (${PACKAGE_NAME}) ${PACKAGE_VERSION}"
99 modules
=`argument $option "$@"`; shift ;;
101 modules
=`echo "$option" | sed 's/--modules=//'` ;;
104 output_image
=`argument $option "$@"`; shift ;;
106 output_image
=`echo "$option" | sed 's/--output=//'` ;;
109 rom_directory
=`argument $option "$@"`; shift ;;
111 rom_directory
=`echo "$option" | sed 's/--rom-directory=//'` ;;
113 # Intentionally undocumented
114 --override-directory)
115 override_dir
=`argument $option "$@"`
117 PATH
=${override_dir}:$PATH
120 --override-directory=*)
121 override_dir
=`echo "${option}/" | sed 's/--override-directory=//'`
122 PATH
=${override_dir}:$PATH
127 grub_mkimage
=`argument $option "$@"`; shift ;;
129 grub_mkimage
=`echo "$option" | sed 's/--grub-mkimage=//'` ;;
132 xorriso
=`argument $option "$@"`; shift ;;
134 xorriso
=`echo "${option}/" | sed 's/--xorriso=//'` ;;
137 source="${source} ${option} $@"; break ;;
141 if [ "x${output_image}" = x
] ; then
142 echo "output file must be given" >&2
147 set $grub_mkimage dummy
148 if test -f "$1"; then
151 echo "$1: Not found." 1>&2
155 iso9660_dir
=`mktemp -d "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` ||
exit 1
156 mkdir
-p ${iso9660_dir}/boot
/grub
162 mkdir
-p ${iso9660_dir}/boot
/grub
/${platform}
163 for file in ${input_dir}/*.mod
; do
164 if test -f "$file"; then
165 cp -f "$file" ${iso9660_dir}/boot
/grub
/${platform}/
168 for file in ${pkglib_DATA}; do
169 if test -f "${input_dir}/${file}"; then
170 cp -f "${input_dir}/${file}" ${iso9660_dir}/boot/grub/${platform}/
174 mkdir -p ${iso9660_dir}/boot/grub/locale
175 for file in ${input_dir}/po/*.mo; do
176 if test -f "$file"; then
177 cp -f "$file" ${iso9660_dir}/boot/grub/locale/
184 source_directory="$1"
186 if ! test -e "${source_directory}"; then
190 echo "Enabling
$2 support ...
"
192 memdisk_img=`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX
"` || exit 1
193 memdisk_dir=`mktemp -d "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX
"` || exit 1
194 mkdir -p ${memdisk_dir}/boot/grub
196 cat << EOF > ${memdisk_dir}/boot/grub/grub.cfg
197 search --fs-uuid --set=root ${iso_uuid}
198 set prefix=(\${root})/boot/grub/${platform}
199 source \$prefix/grub.cfg
201 (for i in $(cat ${source_directory}/partmap.lst) ${modules} ; do
204 echo "source /boot
/grub
/grub.cfg
") \
205 > ${iso9660_dir}/boot/grub/${platform}/grub.cfg
207 (cd "${memdisk_dir}"; tar -cf - boot) > "${memdisk_img}"
208 rm -rf ${memdisk_dir}
209 $grub_mkimage -O ${platform} -d "${source_directory}" -m "${memdisk_img}" -o "$3" --prefix='(memdisk)/boot/grub' \
210 search iso9660 configfile normal memdisk
tar $4
211 rm -rf ${memdisk_img}
214 if [ "${override_dir}" = "" ] ; then
215 if test -e "${multiboot_dir}" ; then
216 process_input_dir
${multiboot_dir} i386-multiboot
218 if test -e "${coreboot_dir}" ; then
219 process_input_dir
${coreboot_dir} i386-coreboot
221 if test -e "${qemu_dir}" ; then
222 process_input_dir
${qemu_dir} i386-qemu
224 if test -e "${pc_dir}" ; then
225 process_input_dir
${pc_dir} i386-pc
227 if test -e "${efi32_dir}" ; then
228 process_input_dir
${efi32_dir} i386-efi
230 if test -e "${efi64_dir}" ; then
231 process_input_dir
${efi64_dir} x86_64-efi
234 process_input_dir
${override_dir} ${target_cpu}-${native_platform}
241 case "${target_cpu}-${native_platform}" in
242 i386-multiboot
) multiboot_dir
=${override_dir} ;;
243 i386-coreboot
) coreboot_dir
=${override_dir} ;;
244 i386-qemu
) qemu_dir
=${override_dir} ;;
245 i386-pc
) pc_dir
=${override_dir} ;;
246 i386-efi
) efi32_dir
=${override_dir} ;;
247 x86_64-efi
) efi64_dir
=${override_dir} ;;
251 # obtain date-based UUID
252 iso_uuid
=$
(date -u +%Y-
%m-
%d-
%H-
%M-
%S-00
)
253 grub_mkisofs_arguments
="${grub_mkisofs_arguments} --modification-date=$(echo ${iso_uuid} | sed -e s/-//g)"
255 # build BIOS core.img
256 if test -e "${pc_dir}" ; then
257 echo "Enabling BIOS support ..."
258 core_img
=`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` ||
exit 1
259 $grub_mkimage -O i386-pc
-d ${pc_dir}/ -o ${core_img} --prefix=/boot
/grub
/i386-pc \
261 cat ${pc_dir}/cdboot.img ${core_img} > ${iso9660_dir}/boot
/grub
/i386-pc
/eltorito.img
263 embed_img
=`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` ||
exit 1
264 cat ${pc_dir}/boot.img ${core_img} > ${embed_img}
268 (for i
in $
(cat ${pc_dir}/partmap.lst
) ${modules} ; do
271 echo "source /boot/grub/grub.cfg") \
272 > ${iso9660_dir}/boot
/grub
/i386-pc
/grub.cfg
274 grub_mkisofs_arguments
="${grub_mkisofs_arguments} -b boot/grub/i386-pc/eltorito.img -no-emul-boot -boot-info-table \
275 --embedded-boot ${embed_img}"
278 # build multiboot core.img
279 make_image
"${multiboot_dir}" i386-multiboot
"${iso9660_dir}/boot/multiboot.img" "ata at_keyboard"
281 if test -e "${efi64_dir}" ||
test -e "${efi32_dir}"; then
282 efi_dir
=`mktemp -d "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` ||
exit 1
283 mkdir
-p "${efi_dir}/efi/boot"
286 make_image
"${efi64_dir}" x86_64-efi
"${efi_dir}"/efi
/boot
/bootx64.efi
""
288 make_image
"${efi32_dir}" i386-efi
"${efi_dir}"/efi
/boot
/bootia32.efi
""
290 mformat
-C -f 2880 -L 16 -i "${iso9660_dir}"/efi.img
::
291 mcopy
-s -i "${iso9660_dir}"/efi.img
${efi_dir}/efi
::/
293 grub_mkisofs_arguments
="${grub_mkisofs_arguments} --efi-boot efi.img"
296 make_image
"${qemu_dir}" i386-qemu
"${iso9660_dir}/boot/qemu.img" "ata at_keyboard"
297 if [ -e "${iso9660_dir}/boot/qemu.img" ] && [ -d "${rom_directory}" ]; then
298 cp "${iso9660_dir}/boot/qemu.img" "${rom_directory}/qemu.img"
300 make_image
"${coreboot_dir}" i386-coreboot
"${iso9660_dir}/boot/coreboot.elf" "ata at_keyboard"
301 if [ -e "${iso9660_dir}/boot/coreboot.elf" ] && [ -d "${rom_directory}" ]; then
302 cp "${iso9660_dir}/boot/coreboot.elf" "${rom_directory}/coreboot.elf"
306 "${xorriso}" -as mkisofs -graft-points ${grub_mkisofs_arguments} --protective-msdos-label -o ${output_image} -r ${iso9660_dir} --sort-weight 0 / --sort-weight 1 /boot ${source}
307 rm -rf ${iso9660_dir}