]> git.proxmox.com Git - grub2.git/blame - util/grub-mkrescue.in
Unify file copying setup across different install scripts. Add
[grub2.git] / util / grub-mkrescue.in
CommitLineData
fc2208b0
RM
1
2# Make GRUB rescue image
8c411768 3# Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009,2010 Free Software Foundation, Inc.
fc2208b0
RM
4#
5# GRUB is free software: you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation, either version 3 of the License, or
8# (at your option) any later version.
9#
10# GRUB is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13# GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with GRUB. If not, see <http://www.gnu.org/licenses/>.
17
18# Initialize some variables.
48b391e9 19
48b391e9
VS
20prefix="@prefix@"
21exec_prefix="@exec_prefix@"
22datarootdir="@datarootdir@"
23bindir="@bindir@"
24libdir="@libdir@"
fc2208b0
RM
25PACKAGE_NAME=@PACKAGE_NAME@
26PACKAGE_TARNAME=@PACKAGE_TARNAME@
27PACKAGE_VERSION=@PACKAGE_VERSION@
a32d5c71 28datadir="@datadir@"
c8d9ead6 29if [ "x$pkgdatadir" = x ]; then
2311c5ca 30 pkgdatadir="${datadir}/@PACKAGE@"
c8d9ead6 31fi
8c411768 32pkglib_DATA="moddep.lst command.lst fs.lst partmap.lst parttool.lst handler.lst video.lst crypto.lst terminal.lst"
fc2208b0 33
0ea7c4f9
GS
34self=`basename $0`
35
2311c5ca
VS
36multiboot_dir="${libdir}/@PACKAGE@/i386-multiboot"
37coreboot_dir="${libdir}/@PACKAGE@/i386-coreboot"
38qemu_dir="${libdir}/@PACKAGE@/i386-qemu"
070038f8 39mipsel_qemu_dir="${libdir}/@PACKAGE@/mipsel-qemu_mips"
3f2bdd8f 40loongson_dir="${libdir}/@PACKAGE@/mipsel-loongson"
070038f8 41mips_qemu_dir="${libdir}/@PACKAGE@/mips-qemu_mips"
2311c5ca
VS
42pc_dir="${libdir}/@PACKAGE@/i386-pc"
43efi32_dir="${libdir}/@PACKAGE@/i386-efi"
44efi64_dir="${libdir}/@PACKAGE@/x86_64-efi"
070038f8 45ia64_dir="${libdir}/@PACKAGE@/ia64-efi"
7e70395f 46rom_directory=
d1d368e4 47override_dir=
fd49ceb3 48grub_mkimage="${bindir}/@grub_mkimage@"
fc2208b0 49
a6085973
TS
50xorriso=xorriso
51
9cc3ee5c
VS
52export TEXTDOMAIN=@PACKAGE@
53export TEXTDOMAINDIR="@localedir@"
54
a20f6ad0
VS
55localedir="@datadir@/locale"
56
c8d9ead6 57. "${pkgdatadir}/grub-mkconfig_lib"
a32d5c71 58
fc2208b0
RM
59# Usage: usage
60# Print the usage.
61usage () {
a32d5c71 62 gettext_printf "Usage: %s [OPTION] SOURCE...\n" "$self"
e7d2559b 63 # TRANSLATORS: it generates one single image which is bootable through any method.
67093bc0 64 gettext "Make GRUB CD-ROM, disk, pendrive and floppy bootable image."; echo
a32d5c71 65 echo
e7d2559b 66 filetrans="$(gettext FILE)"
9f9d3f69
VS
67 print_option_help "-h, --help" "$(gettext "print this message and exit")"
68 print_option_help "-v, --version" "$(gettext "print the version information and exit")"
69 print_option_help "-o, --output=$filetrans" "$(gettext "save output in FILE [required]")"
70 print_option_help "--modules=$(gettext "MODULES")" "$(gettext "pre-load specified modules MODULES")"
aa428238
VS
71 grub_print_install_files_help
72 print_option_help "--install-modules=$(gettext "MODULES")" "$(gettext "install only MODULES and their dependencies on bootable media")"
9f9d3f69 73 print_option_help "--rom-directory=$(gettext "DIR")" "$(gettext "save ROM images in DIR [optional]")"
e7d2559b 74 # TRANSLATORS: xorriso is a program for creating ISOs and burning CDs
9f9d3f69
VS
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")"
a32d5c71 77 echo
9f9d3f69 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
a32d5c71
VS
79 echo
80 gettext "Option -- switches to native xorriso command mode."; echo
81 echo
82 gettext "Report bugs to <bug-grub@gnu.org>."; echo
83 gettext "Mail xorriso support requests to <bug-xorriso@gnu.org>."; echo
fc2208b0
RM
84}
85
86# Check the arguments.
7a64e28d
BC
87while test $# -gt 0
88do
aa428238
VS
89 grub_process_install_options "$@"
90 case "$grub_process_install_options_consumed" in
91 1) shift; continue;;
92 2) shift; shift; continue;;
93 esac
94
7a64e28d
BC
95 option=$1
96 shift
97
fc2208b0
RM
98 case "$option" in
99 -h | --help)
100 usage
101 exit 0 ;;
102 -v | --version)
0ea7c4f9 103 echo "$self (${PACKAGE_NAME}) ${PACKAGE_VERSION}"
fc2208b0 104 exit 0 ;;
7a64e28d
BC
105
106 --modules)
b02c7c8f 107 modules=`argument $option "$@"`; shift ;;
fc2208b0
RM
108 --modules=*)
109 modules=`echo "$option" | sed 's/--modules=//'` ;;
7a64e28d
BC
110
111 -o | --output)
b02c7c8f 112 output_image=`argument $option "$@"`; shift ;;
fc2208b0
RM
113 --output=*)
114 output_image=`echo "$option" | sed 's/--output=//'` ;;
7a64e28d 115
d6d0c209
BC
116 --rom-directory)
117 rom_directory=`argument $option "$@"`; shift ;;
7e70395f
VS
118 --rom-directory=*)
119 rom_directory=`echo "$option" | sed 's/--rom-directory=//'` ;;
d6d0c209 120
efda854e 121 # Intentionally undocumented
7a64e28d 122 --override-directory)
b02c7c8f 123 override_dir=`argument $option "$@"`
7a64e28d
BC
124 shift
125 PATH=${override_dir}:$PATH
126 export PATH
127 ;;
efda854e
RM
128 --override-directory=*)
129 override_dir=`echo "${option}/" | sed 's/--override-directory=//'`
130 PATH=${override_dir}:$PATH
131 export PATH
132 ;;
d6d0c209
BC
133
134 --grub-mkimage)
135 grub_mkimage=`argument $option "$@"`; shift ;;
7fb5c25f
CW
136 --grub-mkimage=*)
137 grub_mkimage=`echo "$option" | sed 's/--grub-mkimage=//'` ;;
b2ffba9c
BC
138
139 --xorriso)
140 xorriso=`argument $option "$@"`; shift ;;
a6085973 141 --xorriso=*)
182c872a 142 xorriso=`echo "${option}" | sed 's/--xorriso=//'` ;;
b2ffba9c 143
fc2208b0 144 *)
b02c7c8f 145 source="${source} ${option} $@"; break ;;
fc2208b0
RM
146 esac
147done
148
74ff1dd5 149if [ "x${output_image}" = x ] ; then
b525fd83 150 gettext "output file must be specified" >&2
a32d5c71 151 echo >&2
74ff1dd5
FZ
152 usage
153 exit 1
154fi
155
7fb5c25f
CW
156set $grub_mkimage dummy
157if test -f "$1"; then
158 :
159else
a32d5c71 160 gettext_printf "%s: Not found.\n" "$1" 1>&2
7fb5c25f
CW
161 exit 1
162fi
163
b65ea155 164iso9660_dir=`mktemp -d "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1
fc2208b0
RM
165mkdir -p ${iso9660_dir}/boot/grub
166
efda854e
RM
167process_input_dir ()
168{
aa428238 169 grub_install_files "$1" "${iso9660_dir}/boot/grub" "$2"
efda854e
RM
170}
171
7e70395f
VS
172make_image ()
173{
174 source_directory="$1"
175 platform=$2
176 if ! test -e "${source_directory}"; then
177 return;
efda854e 178 fi
fc2208b0 179
a32d5c71 180 gettext_printf "Enabling %s support ...\n" "$2"
7e70395f 181
92cd0f6e
VS
182 memdisk_img="`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"`" || exit 1
183 memdisk_dir="`mktemp -d "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"`" || exit 1
184 mkdir -p "${memdisk_dir}/boot/grub"
fc2208b0 185
92cd0f6e 186 (cat << EOF
c982589f 187search --fs-uuid --set=root ${iso_uuid}
92cd0f6e 188set prefix=(\${root})/boot/grub
fc2208b0 189EOF
92cd0f6e 190 for i in $(cat "${source_directory}/partmap.lst") ${modules} ; do
fc2208b0
RM
191 echo "insmod $i"
192 done ; \
92cd0f6e
VS
193 echo "source \$prefix/grub.cfg") \
194 > "${memdisk_dir}/boot/grub/grub.cfg"
fc2208b0 195
3eaac1a1 196 (cd "${memdisk_dir}"; tar -cf - boot) > "${memdisk_img}"
92cd0f6e
VS
197 rm -rf "${memdisk_dir}"
198 "$grub_mkimage" -O ${platform} -d "${source_directory}" -m "${memdisk_img}" -o "$3" --prefix='(memdisk)/boot/grub' \
ee62c427 199 search iso9660 configfile normal memdisk tar $4
92cd0f6e 200 rm -rf "${memdisk_img}"
7e70395f
VS
201}
202
efda854e 203if [ "${override_dir}" = "" ] ; then
7210dca9 204 if test -e "${multiboot_dir}" ; then
070038f8 205 process_input_dir "${multiboot_dir}" i386-multiboot
7e70395f
VS
206 fi
207 if test -e "${coreboot_dir}" ; then
070038f8 208 process_input_dir "${coreboot_dir}" i386-coreboot
7e70395f
VS
209 fi
210 if test -e "${qemu_dir}" ; then
070038f8 211 process_input_dir "${qemu_dir}" i386-qemu
fc2208b0 212 fi
efda854e 213 if test -e "${pc_dir}" ; then
070038f8 214 process_input_dir "${pc_dir}" i386-pc
efda854e 215 fi
ac0289ba 216 if test -e "${efi32_dir}" ; then
070038f8 217 process_input_dir "${efi32_dir}" i386-efi
ac0289ba
VS
218 fi
219 if test -e "${efi64_dir}" ; then
070038f8
VS
220 process_input_dir "${efi64_dir}" x86_64-efi
221 fi
222 if test -e "${ia64_dir}" ; then
223 process_input_dir "${ia64_dir}" ia64-efi
224 fi
225 if test -e "${mips_qemu_dir}" ; then
226 process_input_dir "${mips_qemu_dir}" mips-qemu_mips
227 fi
228 if test -e "${mipsel_qemu_dir}" ; then
229 process_input_dir "${mipsel_qemu_dir}" mipsel-qemu_mips
ac0289ba 230 fi
3f2bdd8f
VS
231 if test -e "${loongson_dir}" ; then
232 process_input_dir "${loongson_dir}" mipsel-loongson
233 fi
efda854e 234else
b84f26c5 235 . "${override_dir}"/modinfo.sh
6ad6223e 236 process_input_dir "${override_dir}" ${grub_modinfo_target_cpu}-${grub_modinfo_platform}
7210dca9 237 multiboot_dir=
efda854e 238 pc_dir=
ac0289ba
VS
239 efi32_dir=
240 efi64_dir=
070038f8 241 ia64_dir=
7e70395f
VS
242 coreboot_dir=
243 qemu_dir=
070038f8
VS
244 mipsel_qemu_dir=
245 mips_qemu_dir=
3f2bdd8f 246 loongson_dir=
6ad6223e 247 case "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" in
070038f8
VS
248 i386-multiboot) multiboot_dir="${override_dir}" ;;
249 i386-coreboot) coreboot_dir="${override_dir}" ;;
250 i386-qemu) qemu_dir="${override_dir}" ;;
251 i386-pc) pc_dir="${override_dir}" ;;
252 i386-efi) efi32_dir="${override_dir}" ;;
253 x86_64-efi) efi64_dir="${override_dir}" ;;
254 ia64-efi) ia64_dir="${override_dir}" ;;
255 mipsel-qemu_mips) mipsel_qemu_dir="${override_dir}" ;;
3f2bdd8f 256 mipsel-loongson) loongson_dir="${override_dir}" ;;
070038f8 257 mips-qemu_mips) mips_qemu_dir="${override_dir}" ;;
efda854e 258 esac
fc2208b0
RM
259fi
260
13ac4305
VS
261# obtain date-based UUID
262iso_uuid=$(date -u +%Y-%m-%d-%H-%M-%S-00)
263grub_mkisofs_arguments="${grub_mkisofs_arguments} --modification-date=$(echo ${iso_uuid} | sed -e s/-//g)"
264
52cc3ce0 265# build BIOS core.img
efda854e 266if test -e "${pc_dir}" ; then
a32d5c71 267 gettext_printf "Enabling %s support ...\n" "BIOS"
92cd0f6e
VS
268 load_cfg="`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"`"
269 core_img="`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"`" || exit 1
270
271 (for i in $(cat "${pc_dir}/partmap.lst") ${modules} ; do
272 echo "insmod $i"
273 done ;) > "${load_cfg}"
0ae56929 274
92cd0f6e
VS
275 "$grub_mkimage" -O i386-pc -d "${pc_dir}/" -o "${core_img}" -c "$load_cfg" --prefix=/boot/grub \
276 iso9660 biosdisk
277 cat "${pc_dir}/cdboot.img" "${core_img}" > "${iso9660_dir}/boot/grub/i386-pc/eltorito.img"
0ae56929 278
92cd0f6e
VS
279 embed_img="`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"`" || exit 1
280 cat "${pc_dir}/boot.img" "${core_img}" > "${embed_img}"
fc2208b0 281
0ae70393 282 rm -f "${core_img}"
fc2208b0 283
47779711 284 grub_mkisofs_arguments="${grub_mkisofs_arguments} -b boot/grub/i386-pc/eltorito.img -no-emul-boot -boot-info-table \
0ae56929 285 --embedded-boot ${embed_img}"
fc2208b0
RM
286fi
287
7e70395f 288# build multiboot core.img
efff4b1c 289make_image "${multiboot_dir}" i386-multiboot "${iso9660_dir}/boot/multiboot.img" "pata ahci at_keyboard"
7e70395f 290
070038f8 291if test -e "${efi64_dir}" || test -e "${efi32_dir}" || test -e "${ia64_dir}"; then
b65ea155 292 efi_dir=`mktemp -d "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1
260ddb94 293 mkdir -p "${efi_dir}/efi/boot"
13ac4305 294
070038f8
VS
295 # build bootia64.efi
296 make_image "${ia64_dir}" ia64-efi "${efi_dir}"/efi/boot/bootia64.efi ""
7e70395f
VS
297 # build bootx64.efi
298 make_image "${efi64_dir}" x86_64-efi "${efi_dir}"/efi/boot/bootx64.efi ""
299 # build bootia32.efi
300 make_image "${efi32_dir}" i386-efi "${efi_dir}"/efi/boot/bootia32.efi ""
fc858482
VS
301 if [ -e "${efi_dir}"/efi/boot/bootia32.efi ]; then
302 # For old macs. Suggested by Peter Jones.
303 cp "${efi_dir}"/efi/boot/bootia32.efi "${efi_dir}"/efi/boot/boot.efi
304 fi
13ac4305 305
260ddb94
VS
306 mformat -C -f 2880 -L 16 -i "${iso9660_dir}"/efi.img ::
307 mcopy -s -i "${iso9660_dir}"/efi.img ${efi_dir}/efi ::/
ea9be8ea 308 rm -rf ${efi_dir}
260ddb94 309 grub_mkisofs_arguments="${grub_mkisofs_arguments} --efi-boot efi.img"
ac0289ba
VS
310fi
311
070038f8
VS
312make_image "${mipsel_qemu_dir}" mipsel-qemu_mips-elf "${iso9660_dir}/boot/mipsel-qemu_mips.elf" "pata"
313if [ -e "${iso9660_dir}/boot/mipsel-qemu_mips.elf" ] && [ -d "${rom_directory}" ]; then
314 cp "${iso9660_dir}/boot/mipsel-qemu_mips.elf" "${rom_directory}/mipsel-qemu_mips.elf"
315fi
3f2bdd8f
VS
316
317make_image "${loongson_dir}" mipsel-loongson-elf "${iso9660_dir}/boot/mipsel-loongson.elf" "pata -C xz"
318if [ -e "${iso9660_dir}/boot/mipsel-loongson.elf" ] && [ -d "${rom_directory}" ]; then
319 cp "${iso9660_dir}/boot/mipsel-loongson.elf" "${rom_directory}/mipsel-loongson.elf"
320fi
321make_image "${loongson_dir}" mipsel-yeeloong-flash "${iso9660_dir}/boot/mipsel-yeeloong.bin" "pata -C xz"
322if [ -e "${iso9660_dir}/boot/mipsel-yeeloong.bin" ] && [ -d "${rom_directory}" ]; then
323 cp "${iso9660_dir}/boot/mipsel-yeeloong.bin" "${rom_directory}/mipsel-yeeloong.bin"
324fi
325
326make_image "${loongson_dir}" mipsel-fuloong2f-flash "${iso9660_dir}/boot/mipsel-fuloong2f.bin" "pata -C xz"
327if [ -e "${iso9660_dir}/boot/mipsel-fulong.bin" ] && [ -d "${rom_directory}" ]; then
328 cp "${iso9660_dir}/boot/mipsel-fulong.bin" "${rom_directory}/mipsel-fulong.bin"
329fi
330
070038f8
VS
331make_image "${mips_qemu_dir}" mips-qemu_mips-elf "${iso9660_dir}/boot/mips-qemu_mips.elf" "pata"
332if [ -e "${iso9660_dir}/boot/mips-qemu_mips.elf" ] && [ -d "${rom_directory}" ]; then
333 cp "${iso9660_dir}/boot/mips-qemu_mips.elf" "${rom_directory}/mips-qemu_mips.elf"
334fi
efff4b1c 335make_image "${qemu_dir}" i386-qemu "${iso9660_dir}/boot/qemu.img" "pata at_keyboard"
7e70395f
VS
336if [ -e "${iso9660_dir}/boot/qemu.img" ] && [ -d "${rom_directory}" ]; then
337 cp "${iso9660_dir}/boot/qemu.img" "${rom_directory}/qemu.img"
338fi
efff4b1c 339make_image "${coreboot_dir}" i386-coreboot "${iso9660_dir}/boot/coreboot.elf" "pata ahci at_keyboard"
7e70395f
VS
340if [ -e "${iso9660_dir}/boot/coreboot.elf" ] && [ -d "${rom_directory}" ]; then
341 cp "${iso9660_dir}/boot/coreboot.elf" "${rom_directory}/coreboot.elf"
342fi
343
fc2208b0 344# build iso image
92cd0f6e
VS
345"${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}
346rm -rf "${iso9660_dir}"
fc2208b0 347
92cd0f6e 348rm -f "${embed_img}"
0ae56929 349
fc2208b0 350exit 0