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 if test "x$TMP" != x
; then
156 MKTEMP_TEMPLATE
="$TMP/grub-mkrescue.XXXXXXXXXX"
157 elif test "x$TEMP" != x
; then
158 MKTEMP_TEMPLATE
="$TEMP/grub-mkrescue.XXXXXXXXXX"
160 MKTEMP_TEMPLATE
="/tmp/grub-mkrescue.XXXXXXXXXX"
163 iso9660_dir
=`mktemp -d "$MKTEMP_TEMPLATE"`
164 mkdir
-p ${iso9660_dir}/boot
/grub
170 mkdir
-p ${iso9660_dir}/boot
/grub
/${platform}
171 for file in ${input_dir}/*.mod
; do
172 if test -f "$file"; then
173 cp -f "$file" ${iso9660_dir}/boot
/grub
/${platform}/
176 for file in ${pkglib_DATA}; do
177 if test -f "${input_dir}/${file}"; then
178 cp -f "${input_dir}/${file}" ${iso9660_dir}/boot/grub/${platform}/
182 mkdir -p ${iso9660_dir}/boot/grub/locale
183 for file in ${input_dir}/po/*.mo; do
184 if test -f "$file"; then
185 cp -f "$file" ${iso9660_dir}/boot/grub/locale/
192 source_directory="$1"
194 if ! test -e "${source_directory}"; then
198 echo "Enabling
$2 support ...
"
200 memdisk_img=`mktemp "$MKTEMP_TEMPLATE"`
201 memdisk_dir=`mktemp -d "$MKTEMP_TEMPLATE"`
202 mkdir -p ${memdisk_dir}/boot/grub
204 cat << EOF > ${memdisk_dir}/boot/grub/grub.cfg
205 search --fs-uuid --set=root ${iso_uuid}
206 set prefix=(\${root})/boot/grub/${platform}
207 source \$prefix/grub.cfg
209 (for i in $(cat ${source_directory}/partmap.lst) ${modules} ; do
212 echo "source /boot
/grub
/grub.cfg
") \
213 > ${iso9660_dir}/boot/grub/${platform}/grub.cfg
215 (cd "${memdisk_dir}"; tar -cf - boot) > "${memdisk_img}"
216 rm -rf ${memdisk_dir}
217 $grub_mkimage -O ${platform} -d "${source_directory}" -m "${memdisk_img}" -o "$3" --prefix='(memdisk)/boot/grub' \
218 search iso9660 configfile normal memdisk
tar $4
219 rm -rf ${memdisk_img}
222 if [ "${override_dir}" = "" ] ; then
223 if test -e "${multiboot_dir}" ; then
224 process_input_dir
${multiboot_dir} i386-multiboot
226 if test -e "${coreboot_dir}" ; then
227 process_input_dir
${coreboot_dir} i386-coreboot
229 if test -e "${qemu_dir}" ; then
230 process_input_dir
${qemu_dir} i386-qemu
232 if test -e "${pc_dir}" ; then
233 process_input_dir
${pc_dir} i386-pc
235 if test -e "${efi32_dir}" ; then
236 process_input_dir
${efi32_dir} i386-efi
238 if test -e "${efi64_dir}" ; then
239 process_input_dir
${efi64_dir} x86_64-efi
242 process_input_dir
${override_dir} ${target_cpu}-${native_platform}
249 case "${target_cpu}-${native_platform}" in
250 i386-multiboot
) multiboot_dir
=${override_dir} ;;
251 i386-coreboot
) coreboot_dir
=${override_dir} ;;
252 i386-qemu
) qemu_dir
=${override_dir} ;;
253 i386-pc
) pc_dir
=${override_dir} ;;
254 i386-efi
) efi32_dir
=${override_dir} ;;
255 x86_64-efi
) efi64_dir
=${override_dir} ;;
259 # obtain date-based UUID
260 iso_uuid
=$
(date -u +%Y-
%m-
%d-
%H-
%M-
%S-00
)
261 grub_mkisofs_arguments
="${grub_mkisofs_arguments} --modification-date=$(echo ${iso_uuid} | sed -e s/-//g)"
263 # build BIOS core.img
264 if test -e "${pc_dir}" ; then
265 echo "Enabling BIOS support ..."
266 core_img
=`mktemp "$MKTEMP_TEMPLATE"`
267 $grub_mkimage -O i386-pc
-d ${pc_dir}/ -o ${core_img} --prefix=/boot
/grub
/i386-pc \
269 cat ${pc_dir}/cdboot.img ${core_img} > ${iso9660_dir}/boot
/grub
/i386-pc
/eltorito.img
271 embed_img
=`mktemp "$MKTEMP_TEMPLATE"`
272 cat ${pc_dir}/boot.img ${core_img} > ${embed_img}
276 (for i
in $
(cat ${pc_dir}/partmap.lst
) ${modules} ; do
279 echo "source /boot/grub/grub.cfg") \
280 > ${iso9660_dir}/boot
/grub
/i386-pc
/grub.cfg
282 grub_mkisofs_arguments
="${grub_mkisofs_arguments} -b boot/grub/i386-pc/eltorito.img -no-emul-boot -boot-info-table \
283 --embedded-boot ${embed_img}"
286 # build multiboot core.img
287 make_image
"${multiboot_dir}" i386-multiboot
"${iso9660_dir}/boot/multiboot.img" "ata at_keyboard"
289 if test -e "${efi64_dir}" ||
test -e "${efi32_dir}"; then
290 efi_dir
=`mktemp -d "$MKTEMP_TEMPLATE"`
291 mkdir
-p "${efi_dir}/efi/boot"
294 make_image
"${efi64_dir}" x86_64-efi
"${efi_dir}"/efi
/boot
/bootx64.efi
""
296 make_image
"${efi32_dir}" i386-efi
"${efi_dir}"/efi
/boot
/bootia32.efi
""
298 mformat
-C -f 2880 -L 16 -i "${iso9660_dir}"/efi.img
::
299 mcopy
-s -i "${iso9660_dir}"/efi.img
${efi_dir}/efi
::/
301 grub_mkisofs_arguments
="${grub_mkisofs_arguments} --efi-boot efi.img"
304 make_image
"${qemu_dir}" i386-qemu
"${iso9660_dir}/boot/qemu.img" "ata at_keyboard"
305 if [ -e "${iso9660_dir}/boot/qemu.img" ] && [ -d "${rom_directory}" ]; then
306 cp "${iso9660_dir}/boot/qemu.img" "${rom_directory}/qemu.img"
308 make_image
"${coreboot_dir}" i386-coreboot
"${iso9660_dir}/boot/coreboot.elf" "ata at_keyboard"
309 if [ -e "${iso9660_dir}/boot/coreboot.elf" ] && [ -d "${rom_directory}" ]; then
310 cp "${iso9660_dir}/boot/coreboot.elf" "${rom_directory}/coreboot.elf"
314 "${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}
315 rm -rf ${iso9660_dir}