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 pkglib_DATA
="moddep.lst command.lst fs.lst partmap.lst parttool.lst handler.lst video.lst crypto.lst terminal.lst"
34 multiboot_dir
="${libdir}/$(echo ${PACKAGE_TARNAME} | sed ${transform})/i386-multiboot"
35 coreboot_dir
="${libdir}/$(echo ${PACKAGE_TARNAME} | sed ${transform})/i386-coreboot"
36 qemu_dir
="${libdir}/$(echo ${PACKAGE_TARNAME} | sed ${transform})/i386-qemu"
37 pc_dir
="${libdir}/$(echo ${PACKAGE_TARNAME} | sed ${transform})/i386-pc"
38 efi32_dir
="${libdir}/$(echo ${PACKAGE_TARNAME} | sed ${transform})/i386-efi"
39 efi64_dir
="${libdir}/$(echo ${PACKAGE_TARNAME} | sed ${transform})/x86_64-efi"
42 grub_mkimage
="${bindir}/`echo grub-mkimage | sed ${transform}`"
50 Usage: $self [OPTION] SOURCE...
51 Make GRUB rescue image.
53 -h, --help print this message and exit
54 -v, --version print the version information and exit
55 -o, --output=FILE save output in FILE [required]
56 --modules=MODULES pre-load specified modules MODULES
57 --rom-directory=DIR save rom images in DIR [optional]
58 --xorriso=FILE use FILE as xorriso [optional]
59 --grub-mkimage=FILE use FILE as grub-mkimage
61 $self generates a bootable rescue image with specified source files, source
62 directories, or mkisofs options listed by: xorriso -as mkisofs -help
64 Option -- switches to native xorriso command mode.
66 Report bugs to <bug-grub@gnu.org>.
67 Mail xorriso support requests to <bug-xorriso@gnu.org>.
75 if test $# -eq 0; then
76 echo "$0: option requires an argument -- '$opt'" 1>&2
82 # Check the arguments.
93 echo "$self (${PACKAGE_NAME}) ${PACKAGE_VERSION}"
97 modules
=`argument $option "$@"`; shift ;;
99 modules
=`echo "$option" | sed 's/--modules=//'` ;;
102 output_image
=`argument $option "$@"`; shift ;;
104 output_image
=`echo "$option" | sed 's/--output=//'` ;;
107 rom_directory
=`argument $option "$@"`; shift ;;
109 rom_directory
=`echo "$option" | sed 's/--rom-directory=//'` ;;
111 # Intentionally undocumented
112 --override-directory)
113 override_dir
=`argument $option "$@"`
115 PATH
=${override_dir}:$PATH
118 --override-directory=*)
119 override_dir
=`echo "${option}/" | sed 's/--override-directory=//'`
120 PATH
=${override_dir}:$PATH
125 grub_mkimage
=`argument $option "$@"`; shift ;;
127 grub_mkimage
=`echo "$option" | sed 's/--grub-mkimage=//'` ;;
130 xorriso
=`argument $option "$@"`; shift ;;
132 xorriso
=`echo "${option}/" | sed 's/--xorriso=//'` ;;
135 source="${source} ${option} $@"; break ;;
139 if [ "x${output_image}" = x
] ; then
140 echo "output file must be given" >&2
145 set $grub_mkimage dummy
146 if test -f "$1"; then
149 echo "$1: Not found." 1>&2
153 iso9660_dir
=`mktemp -d "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` ||
exit 1
154 mkdir
-p ${iso9660_dir}/boot
/grub
160 mkdir
-p ${iso9660_dir}/boot
/grub
/${platform}
161 for file in "${input_dir}/"*.mod "${input_dir}/"efiemu32.o "${input_dir}/"efiemu64.o
; do
162 if test -f "$file"; then
163 cp -f "$file" ${iso9660_dir}/boot
/grub
/${platform}/
166 for file in ${pkglib_DATA}; do
167 if test -f "${input_dir}/${file}"; then
168 cp -f "${input_dir}/${file}" ${iso9660_dir}/boot/grub/${platform}/
172 mkdir -p ${iso9660_dir}/boot/grub/locale
173 for file in ${input_dir}/po/*.mo; do
174 if test -f "$file"; then
175 cp -f "$file" ${iso9660_dir}/boot/grub/locale/
182 source_directory="$1"
184 if ! test -e "${source_directory}"; then
188 echo "Enabling
$2 support ...
"
190 memdisk_img=`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX
"` || exit 1
191 memdisk_dir=`mktemp -d "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX
"` || exit 1
192 mkdir -p ${memdisk_dir}/boot/grub
194 cat << EOF > ${memdisk_dir}/boot/grub/grub.cfg
195 search --fs-uuid --set=root ${iso_uuid}
196 set prefix=(\${root})/boot/grub/${platform}
197 source \$prefix/grub.cfg
199 (for i in $(cat ${source_directory}/partmap.lst) ${modules} ; do
202 echo "source /boot
/grub
/grub.cfg
") \
203 > ${iso9660_dir}/boot/grub/${platform}/grub.cfg
205 (cd "${memdisk_dir}"; tar -cf - boot) > "${memdisk_img}"
206 rm -rf ${memdisk_dir}
207 $grub_mkimage -O ${platform} -d "${source_directory}" -m "${memdisk_img}" -o "$3" --prefix='(memdisk)/boot/grub' \
208 search iso9660 configfile normal memdisk
tar $4
209 rm -rf ${memdisk_img}
212 if [ "${override_dir}" = "" ] ; then
213 if test -e "${multiboot_dir}" ; then
214 process_input_dir
${multiboot_dir} i386-multiboot
216 if test -e "${coreboot_dir}" ; then
217 process_input_dir
${coreboot_dir} i386-coreboot
219 if test -e "${qemu_dir}" ; then
220 process_input_dir
${qemu_dir} i386-qemu
222 if test -e "${pc_dir}" ; then
223 process_input_dir
${pc_dir} i386-pc
225 if test -e "${efi32_dir}" ; then
226 process_input_dir
${efi32_dir} i386-efi
228 if test -e "${efi64_dir}" ; then
229 process_input_dir
${efi64_dir} x86_64-efi
232 .
"${override_dir}"/modinfo.sh
233 process_input_dir
"${override_dir}" ${grub_modinfo_target_cpu}-${grub_modinfo_platform}
240 case "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" in
241 i386-multiboot) multiboot_dir=${override_dir} ;;
242 i386-coreboot) coreboot_dir=${override_dir} ;;
243 i386-qemu) qemu_dir=${override_dir} ;;
244 i386-pc) pc_dir=${override_dir} ;;
245 i386-efi) efi32_dir=${override_dir} ;;
246 x86_64-efi) efi64_dir=${override_dir} ;;
250 # obtain date-based UUID
251 iso_uuid=$(date -u +%Y-%m-%d-%H-%M-%S-00)
252 grub_mkisofs_arguments="${grub_mkisofs_arguments} --modification-date=$
(echo ${iso_uuid} |
sed -e s
/-//g
)"
254 # build BIOS core.img
255 if test -e "${pc_dir}" ; then
256 echo "Enabling BIOS support ...
"
257 core_img=`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX
"` || exit 1
258 $grub_mkimage -O i386-pc -d ${pc_dir}/ -o ${core_img} --prefix=/boot/grub/i386-pc \
260 cat ${pc_dir}/cdboot.img ${core_img} > ${iso9660_dir}/boot/grub/i386-pc/eltorito.img
262 embed_img=`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX
"` || exit 1
263 cat ${pc_dir}/boot.img ${core_img} > ${embed_img}
267 (for i in $(cat ${pc_dir}/partmap.lst) ${modules} ; do
270 echo "source /boot
/grub
/grub.cfg
") \
271 > ${iso9660_dir}/boot/grub/i386-pc/grub.cfg
273 grub_mkisofs_arguments="${grub_mkisofs_arguments} -b boot
/grub
/i386-pc
/eltorito.img
-no-emul-boot -boot-info-table \
274 --embedded-boot ${embed_img}"
277 # build multiboot core.img
278 make_image "${multiboot_dir}" i386-multiboot "${iso9660_dir}/boot
/multiboot.img
" "pata ahci at_keyboard
"
280 if test -e "${efi64_dir}" || test -e "${efi32_dir}"; then
281 efi_dir=`mktemp -d "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX
"` || exit 1
282 mkdir -p "${efi_dir}/efi
/boot
"
285 make_image "${efi64_dir}" x86_64-efi "${efi_dir}"/efi/boot/bootx64.efi ""
287 make_image "${efi32_dir}" i386-efi "${efi_dir}"/efi/boot/bootia32.efi ""
288 if [ -e "${efi_dir}"/efi/boot/bootia32.efi ]; then
289 # For old macs. Suggested by Peter Jones.
290 cp "${efi_dir}"/efi/boot/bootia32.efi "${efi_dir}"/efi/boot/boot.efi
293 mformat -C -f 2880 -L 16 -i "${iso9660_dir}"/efi.img ::
294 mcopy -s -i "${iso9660_dir}"/efi.img ${efi_dir}/efi ::/
296 grub_mkisofs_arguments="${grub_mkisofs_arguments} --efi-boot efi.img
"
299 make_image "${qemu_dir}" i386-qemu "${iso9660_dir}/boot
/qemu.img
" "pata at_keyboard
"
300 if [ -e "${iso9660_dir}/boot
/qemu.img
" ] && [ -d "${rom_directory}" ]; then
301 cp "${iso9660_dir}/boot
/qemu.img
" "${rom_directory}/qemu.img
"
303 make_image "${coreboot_dir}" i386-coreboot "${iso9660_dir}/boot
/coreboot.elf
" "pata ahci at_keyboard
"
304 if [ -e "${iso9660_dir}/boot
/coreboot.elf
" ] && [ -d "${rom_directory}" ]; then
305 cp "${iso9660_dir}/boot
/coreboot.elf
" "${rom_directory}/coreboot.elf
"
309 "${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}
310 rm -rf ${iso9660_dir}