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.
23 exec_prefix
="@exec_prefix@"
24 datarootdir
="@datarootdir@"
27 PACKAGE_NAME
=@PACKAGE_NAME@
28 PACKAGE_TARNAME
=@PACKAGE_TARNAME@
29 PACKAGE_VERSION
=@PACKAGE_VERSION@
31 if [ "x$pkgdatadir" = x
]; then
32 pkgdatadir
="${datadir}/@PACKAGE@"
34 pkglib_DATA
="moddep.lst command.lst fs.lst partmap.lst parttool.lst handler.lst video.lst crypto.lst terminal.lst"
38 multiboot_dir
="${libdir}/@PACKAGE@/i386-multiboot"
39 coreboot_dir
="${libdir}/@PACKAGE@/i386-coreboot"
40 qemu_dir
="${libdir}/@PACKAGE@/i386-qemu"
41 mipsel_qemu_dir
="${libdir}/@PACKAGE@/mipsel-qemu_mips"
42 loongson_dir
="${libdir}/@PACKAGE@/mipsel-loongson"
43 mips_qemu_dir
="${libdir}/@PACKAGE@/mips-qemu_mips"
44 pc_dir
="${libdir}/@PACKAGE@/i386-pc"
45 efi32_dir
="${libdir}/@PACKAGE@/i386-efi"
46 efi64_dir
="${libdir}/@PACKAGE@/x86_64-efi"
47 ia64_dir
="${libdir}/@PACKAGE@/ia64-efi"
50 grub_mkimage
="${bindir}/@grub_mkimage@"
54 export TEXTDOMAIN
=@PACKAGE@
55 export TEXTDOMAINDIR
="@localedir@"
57 localedir
="@datadir@/locale"
59 .
"${pkgdatadir}/grub-mkconfig_lib"
64 gettext_printf
"Usage: %s [OPTION] SOURCE...\n" "$self"
65 # TRANSLATORS: it generates one single image which is bootable through any method.
66 gettext "Make GRUB CD-ROM, disk, pendrive and floppy bootable image."; echo
68 filetrans
="$(gettext FILE)"
69 print_option_help
"-h, --help" "$(gettext "print this message and
exit")"
70 print_option_help
"-v, --version" "$(gettext "print the version information and
exit")"
71 print_option_help
"-o, --output=$filetrans" "$(gettext "save output
in FILE
[required
]")"
72 print_option_help
"--modules=$(gettext "MODULES
")" "$(gettext "pre-load specified modules MODULES
")"
73 print_option_help
"--rom-directory=$(gettext "DIR
")" "$(gettext "save ROM images
in DIR
[optional
]")"
74 # TRANSLATORS: xorriso is a program for creating ISOs and burning CDs
75 print_option_help
"--xorriso=$filetrans" "$(gettext "use FILE as xorriso
[optional
]")"
76 print_option_help
"--grub-mkimage=$filetrans" "$(gettext "use FILE as grub-mkimage
")"
78 gettext_printf
"%s generates a bootable rescue image with specified source files, source directories, or mkisofs options listed by the output of \`%s'\n" "xorriso -as mkisofs -help" "$self" | grub_fmt
80 gettext "Option -- switches to native xorriso command mode."; echo
82 gettext "Report bugs to <bug-grub@gnu.org>."; echo
83 gettext "Mail xorriso support requests to <bug-xorriso@gnu.org>."; echo
90 if test $# -eq 0; then
91 gettext_printf
"%s: option requires an argument -- \`%s'\n" "$0" "$opt" 1>&2
97 # Check the arguments.
108 echo "$self (${PACKAGE_NAME}) ${PACKAGE_VERSION}"
112 modules
=`argument $option "$@"`; shift ;;
114 modules
=`echo "$option" | sed 's/--modules=//'` ;;
117 output_image
=`argument $option "$@"`; shift ;;
119 output_image
=`echo "$option" | sed 's/--output=//'` ;;
122 rom_directory
=`argument $option "$@"`; shift ;;
124 rom_directory
=`echo "$option" | sed 's/--rom-directory=//'` ;;
126 # Intentionally undocumented
127 --override-directory)
128 override_dir
=`argument $option "$@"`
130 PATH
=${override_dir}:$PATH
133 --override-directory=*)
134 override_dir
=`echo "${option}/" | sed 's/--override-directory=//'`
135 PATH
=${override_dir}:$PATH
140 grub_mkimage
=`argument $option "$@"`; shift ;;
142 grub_mkimage
=`echo "$option" | sed 's/--grub-mkimage=//'` ;;
145 xorriso
=`argument $option "$@"`; shift ;;
147 xorriso
=`echo "${option}" | sed 's/--xorriso=//'` ;;
150 source="${source} ${option} $@"; break ;;
154 if [ "x${output_image}" = x
] ; then
155 gettext "output file must be specified" >&2
161 set $grub_mkimage dummy
162 if test -f "$1"; then
165 gettext_printf
"%s: Not found.\n" "$1" 1>&2
169 iso9660_dir
=`mktemp -d "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` ||
exit 1
170 mkdir
-p ${iso9660_dir}/boot
/grub
176 mkdir
-p "${iso9660_dir}/boot/grub/${platform}"
177 for file in "${input_dir}/"*.mod "${input_dir}/"efiemu32.o "${input_dir}/"efiemu64.o
; do
178 if test -f "$file"; then
179 cp -f "$file" "${iso9660_dir}/boot/grub/${platform}/"
182 for file in ${pkglib_DATA}; do
183 if test -f "${input_dir}/${file}"; then
184 cp -f "${input_dir}/${file}" "${iso9660_dir}/boot/grub/${platform}/"
188 mkdir
-p "${iso9660_dir}/boot/grub/locale"
189 for dir
in "${localedir}"/*; do
190 if test -f "$dir/LC_MESSAGES/grub.mo"; then
191 cp -f "$dir/LC_MESSAGES/grub.mo" "${iso9660_dir}/boot/grub/locale/${dir##*/}.mo"
198 source_directory
="$1"
200 if ! test -e "${source_directory}"; then
204 gettext_printf
"Enabling %s support ...\n" "$2"
206 memdisk_img
="`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX
"`" ||
exit 1
207 memdisk_dir
="`mktemp -d "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX
"`" ||
exit 1
208 mkdir
-p "${memdisk_dir}/boot/grub"
211 search --fs-uuid --set=root ${iso_uuid}
212 set prefix=(\${root})/boot/grub
214 for i
in $
(cat "${source_directory}/partmap.lst") ${modules} ; do
217 echo "source \$prefix/grub.cfg") \
218 > "${memdisk_dir}/boot/grub/grub.cfg"
220 (cd "${memdisk_dir}"; tar -cf - boot
) > "${memdisk_img}"
221 rm -rf "${memdisk_dir}"
222 "$grub_mkimage" -O ${platform} -d "${source_directory}" -m "${memdisk_img}" -o "$3" --prefix='(memdisk)/boot/grub' \
223 search iso9660 configfile normal memdisk tar $4
224 rm -rf "${memdisk_img}"
227 if [ "${override_dir}" = "" ] ; then
228 if test -e "${multiboot_dir}" ; then
229 process_input_dir "${multiboot_dir}" i386-multiboot
231 if test -e "${coreboot_dir}" ; then
232 process_input_dir "${coreboot_dir}" i386-coreboot
234 if test -e "${qemu_dir}" ; then
235 process_input_dir "${qemu_dir}" i386-qemu
237 if test -e "${pc_dir}" ; then
238 process_input_dir "${pc_dir}" i386-pc
240 if test -e "${efi32_dir}" ; then
241 process_input_dir "${efi32_dir}" i386-efi
243 if test -e "${efi64_dir}" ; then
244 process_input_dir "${efi64_dir}" x86_64-efi
246 if test -e "${ia64_dir}" ; then
247 process_input_dir "${ia64_dir}" ia64-efi
249 if test -e "${mips_qemu_dir}" ; then
250 process_input_dir "${mips_qemu_dir}" mips-qemu_mips
252 if test -e "${mipsel_qemu_dir}" ; then
253 process_input_dir "${mipsel_qemu_dir}" mipsel-qemu_mips
255 if test -e "${loongson_dir}" ; then
256 process_input_dir "${loongson_dir}" mipsel-loongson
259 . "${override_dir}"/modinfo.sh
260 process_input_dir "${override_dir}" ${grub_modinfo_target_cpu}-${grub_modinfo_platform}
271 case "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" in
272 i386-multiboot
) multiboot_dir
="${override_dir}" ;;
273 i386-coreboot
) coreboot_dir
="${override_dir}" ;;
274 i386-qemu
) qemu_dir
="${override_dir}" ;;
275 i386-pc
) pc_dir
="${override_dir}" ;;
276 i386-efi
) efi32_dir
="${override_dir}" ;;
277 x86_64-efi
) efi64_dir
="${override_dir}" ;;
278 ia64-efi
) ia64_dir
="${override_dir}" ;;
279 mipsel-qemu_mips
) mipsel_qemu_dir
="${override_dir}" ;;
280 mipsel-loongson
) loongson_dir
="${override_dir}" ;;
281 mips-qemu_mips
) mips_qemu_dir
="${override_dir}" ;;
285 # obtain date-based UUID
286 iso_uuid
=$
(date -u +%Y-
%m-
%d-
%H-
%M-
%S-00
)
287 grub_mkisofs_arguments
="${grub_mkisofs_arguments} --modification-date=$(echo ${iso_uuid} | sed -e s/-//g)"
289 # build BIOS core.img
290 if test -e "${pc_dir}" ; then
291 gettext_printf
"Enabling %s support ...\n" "BIOS"
292 load_cfg
="`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX
"`"
293 core_img
="`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX
"`" ||
exit 1
295 (for i
in $
(cat "${pc_dir}/partmap.lst") ${modules} ; do
297 done ;) > "${load_cfg}"
299 "$grub_mkimage" -O i386-pc
-d "${pc_dir}/" -o "${core_img}" -c "$load_cfg" --prefix=/boot
/grub \
301 cat "${pc_dir}/cdboot.img" "${core_img}" > "${iso9660_dir}/boot/grub/i386-pc/eltorito.img"
303 embed_img
="`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX
"`" ||
exit 1
304 cat "${pc_dir}/boot.img" "${core_img}" > "${embed_img}"
308 grub_mkisofs_arguments
="${grub_mkisofs_arguments} -b boot/grub/i386-pc/eltorito.img -no-emul-boot -boot-info-table \
309 --embedded-boot ${embed_img}"
312 # build multiboot core.img
313 make_image
"${multiboot_dir}" i386-multiboot
"${iso9660_dir}/boot/multiboot.img" "pata ahci at_keyboard"
315 if test -e "${efi64_dir}" || test -e "${efi32_dir}" || test -e "${ia64_dir}"; then
316 efi_dir
=`mktemp -d "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` ||
exit 1
317 mkdir
-p "${efi_dir}/efi/boot"
320 make_image
"${ia64_dir}" ia64-efi
"${efi_dir}"/efi
/boot
/bootia64.efi
""
322 make_image
"${efi64_dir}" x86_64-efi
"${efi_dir}"/efi
/boot
/bootx64.efi
""
324 make_image
"${efi32_dir}" i386-efi
"${efi_dir}"/efi
/boot
/bootia32.efi
""
325 if [ -e "${efi_dir}"/efi
/boot
/bootia32.efi
]; then
326 # For old macs. Suggested by Peter Jones.
327 cp "${efi_dir}"/efi
/boot
/bootia32.efi
"${efi_dir}"/efi
/boot
/boot.efi
330 mformat
-C -f 2880 -L 16 -i "${iso9660_dir}"/efi.img
::
331 mcopy
-s -i "${iso9660_dir}"/efi.img
${efi_dir}/efi
::/
333 grub_mkisofs_arguments
="${grub_mkisofs_arguments} --efi-boot efi.img"
336 make_image
"${mipsel_qemu_dir}" mipsel-qemu_mips-elf
"${iso9660_dir}/boot/mipsel-qemu_mips.elf" "pata"
337 if [ -e "${iso9660_dir}/boot/mipsel-qemu_mips.elf" ] && [ -d "${rom_directory}" ]; then
338 cp "${iso9660_dir}/boot/mipsel-qemu_mips.elf" "${rom_directory}/mipsel-qemu_mips.elf"
341 make_image
"${loongson_dir}" mipsel-loongson-elf
"${iso9660_dir}/boot/mipsel-loongson.elf" "pata -C xz"
342 if [ -e "${iso9660_dir}/boot/mipsel-loongson.elf" ] && [ -d "${rom_directory}" ]; then
343 cp "${iso9660_dir}/boot/mipsel-loongson.elf" "${rom_directory}/mipsel-loongson.elf"
345 make_image
"${loongson_dir}" mipsel-yeeloong-flash
"${iso9660_dir}/boot/mipsel-yeeloong.bin" "pata -C xz"
346 if [ -e "${iso9660_dir}/boot/mipsel-yeeloong.bin" ] && [ -d "${rom_directory}" ]; then
347 cp "${iso9660_dir}/boot/mipsel-yeeloong.bin" "${rom_directory}/mipsel-yeeloong.bin"
350 make_image
"${loongson_dir}" mipsel-fuloong2f-flash
"${iso9660_dir}/boot/mipsel-fuloong2f.bin" "pata -C xz"
351 if [ -e "${iso9660_dir}/boot/mipsel-fulong.bin" ] && [ -d "${rom_directory}" ]; then
352 cp "${iso9660_dir}/boot/mipsel-fulong.bin" "${rom_directory}/mipsel-fulong.bin"
355 make_image
"${mips_qemu_dir}" mips-qemu_mips-elf
"${iso9660_dir}/boot/mips-qemu_mips.elf" "pata"
356 if [ -e "${iso9660_dir}/boot/mips-qemu_mips.elf" ] && [ -d "${rom_directory}" ]; then
357 cp "${iso9660_dir}/boot/mips-qemu_mips.elf" "${rom_directory}/mips-qemu_mips.elf"
359 make_image
"${qemu_dir}" i386-qemu
"${iso9660_dir}/boot/qemu.img" "pata at_keyboard"
360 if [ -e "${iso9660_dir}/boot/qemu.img" ] && [ -d "${rom_directory}" ]; then
361 cp "${iso9660_dir}/boot/qemu.img" "${rom_directory}/qemu.img"
363 make_image
"${coreboot_dir}" i386-coreboot
"${iso9660_dir}/boot/coreboot.elf" "pata ahci at_keyboard"
364 if [ -e "${iso9660_dir}/boot/coreboot.elf" ] && [ -d "${rom_directory}" ]; then
365 cp "${iso9660_dir}/boot/coreboot.elf" "${rom_directory}/coreboot.elf"
369 "${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}
370 rm -rf "${iso9660_dir}"