]>
Commit | Line | Data |
---|---|---|
1246efeb CW |
1 | #! /bin/sh |
2 | set -e | |
fc2208b0 RM |
3 | |
4 | # Make GRUB rescue image | |
8c411768 | 5 | # Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009,2010 Free Software Foundation, Inc. |
fc2208b0 RM |
6 | # |
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. | |
11 | # | |
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. | |
16 | # | |
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/>. | |
19 | ||
20 | # Initialize some variables. | |
21 | transform="@program_transform_name@" | |
22 | ||
23 | prefix=@prefix@ | |
24 | exec_prefix=@exec_prefix@ | |
25 | bindir=@bindir@ | |
26 | libdir=@libdir@ | |
27 | PACKAGE_NAME=@PACKAGE_NAME@ | |
28 | PACKAGE_TARNAME=@PACKAGE_TARNAME@ | |
29 | PACKAGE_VERSION=@PACKAGE_VERSION@ | |
8c411768 | 30 | pkglib_DATA="moddep.lst command.lst fs.lst partmap.lst parttool.lst handler.lst video.lst crypto.lst terminal.lst" |
fc2208b0 | 31 | |
0ea7c4f9 GS |
32 | self=`basename $0` |
33 | ||
c77069f5 VS |
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" | |
7e70395f | 40 | rom_directory= |
d1d368e4 | 41 | override_dir= |
c77069f5 | 42 | grub_mkimage="${bindir}/`echo grub-mkimage | sed ${transform}`" |
fc2208b0 | 43 | |
a6085973 TS |
44 | xorriso=xorriso |
45 | ||
fc2208b0 RM |
46 | # Usage: usage |
47 | # Print the usage. | |
48 | usage () { | |
49 | cat <<EOF | |
0ea7c4f9 | 50 | Usage: $self [OPTION] SOURCE... |
fc2208b0 RM |
51 | Make GRUB rescue image. |
52 | ||
53 | -h, --help print this message and exit | |
54 | -v, --version print the version information and exit | |
7a64e28d | 55 | -o, --output=FILE save output in FILE [required] |
7e70395f VS |
56 | --modules=MODULES pre-load specified modules MODULES |
57 | --rom-directory=DIR save rom images in DIR [optional] | |
a6085973 | 58 | --xorriso=FILE use FILE as xorriso [optional] |
7fb5c25f | 59 | --grub-mkimage=FILE use FILE as grub-mkimage |
fc2208b0 | 60 | |
ce08a9fb TS |
61 | $self generates a bootable rescue image with specified source files, source |
62 | directories, or mkisofs options listed by: xorriso -as mkisofs -help | |
4066f57f CW |
63 | |
64 | Option -- switches to native xorriso command mode. | |
fc2208b0 RM |
65 | |
66 | Report bugs to <bug-grub@gnu.org>. | |
ce08a9fb | 67 | Mail xorriso support requests to <bug-xorriso@gnu.org>. |
fc2208b0 RM |
68 | EOF |
69 | } | |
70 | ||
b02c7c8f BC |
71 | argument () { |
72 | opt=$1 | |
73 | shift | |
74 | ||
75 | if test $# -eq 0; then | |
76 | echo "$0: option requires an argument -- '$opt'" 1>&2 | |
77 | exit 1 | |
78 | fi | |
79 | echo $1 | |
80 | } | |
81 | ||
fc2208b0 | 82 | # Check the arguments. |
7a64e28d BC |
83 | while test $# -gt 0 |
84 | do | |
85 | option=$1 | |
86 | shift | |
87 | ||
fc2208b0 RM |
88 | case "$option" in |
89 | -h | --help) | |
90 | usage | |
91 | exit 0 ;; | |
92 | -v | --version) | |
0ea7c4f9 | 93 | echo "$self (${PACKAGE_NAME}) ${PACKAGE_VERSION}" |
fc2208b0 | 94 | exit 0 ;; |
7a64e28d BC |
95 | |
96 | --modules) | |
b02c7c8f | 97 | modules=`argument $option "$@"`; shift ;; |
fc2208b0 RM |
98 | --modules=*) |
99 | modules=`echo "$option" | sed 's/--modules=//'` ;; | |
7a64e28d BC |
100 | |
101 | -o | --output) | |
b02c7c8f | 102 | output_image=`argument $option "$@"`; shift ;; |
fc2208b0 RM |
103 | --output=*) |
104 | output_image=`echo "$option" | sed 's/--output=//'` ;; | |
7a64e28d | 105 | |
d6d0c209 BC |
106 | --rom-directory) |
107 | rom_directory=`argument $option "$@"`; shift ;; | |
7e70395f VS |
108 | --rom-directory=*) |
109 | rom_directory=`echo "$option" | sed 's/--rom-directory=//'` ;; | |
d6d0c209 | 110 | |
efda854e | 111 | # Intentionally undocumented |
7a64e28d | 112 | --override-directory) |
b02c7c8f | 113 | override_dir=`argument $option "$@"` |
7a64e28d BC |
114 | shift |
115 | PATH=${override_dir}:$PATH | |
116 | export PATH | |
117 | ;; | |
efda854e RM |
118 | --override-directory=*) |
119 | override_dir=`echo "${option}/" | sed 's/--override-directory=//'` | |
120 | PATH=${override_dir}:$PATH | |
121 | export PATH | |
122 | ;; | |
d6d0c209 BC |
123 | |
124 | --grub-mkimage) | |
125 | grub_mkimage=`argument $option "$@"`; shift ;; | |
7fb5c25f CW |
126 | --grub-mkimage=*) |
127 | grub_mkimage=`echo "$option" | sed 's/--grub-mkimage=//'` ;; | |
b2ffba9c BC |
128 | |
129 | --xorriso) | |
130 | xorriso=`argument $option "$@"`; shift ;; | |
a6085973 | 131 | --xorriso=*) |
182c872a | 132 | xorriso=`echo "${option}" | sed 's/--xorriso=//'` ;; |
b2ffba9c | 133 | |
fc2208b0 | 134 | *) |
b02c7c8f | 135 | source="${source} ${option} $@"; break ;; |
fc2208b0 RM |
136 | esac |
137 | done | |
138 | ||
74ff1dd5 FZ |
139 | if [ "x${output_image}" = x ] ; then |
140 | echo "output file must be given" >&2 | |
141 | usage | |
142 | exit 1 | |
143 | fi | |
144 | ||
7fb5c25f CW |
145 | set $grub_mkimage dummy |
146 | if test -f "$1"; then | |
147 | : | |
148 | else | |
149 | echo "$1: Not found." 1>&2 | |
150 | exit 1 | |
151 | fi | |
152 | ||
b65ea155 | 153 | iso9660_dir=`mktemp -d "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1 |
fc2208b0 RM |
154 | mkdir -p ${iso9660_dir}/boot/grub |
155 | ||
efda854e RM |
156 | process_input_dir () |
157 | { | |
158 | input_dir="$1" | |
159 | platform="$2" | |
7e70395f | 160 | mkdir -p ${iso9660_dir}/boot/grub/${platform} |
ed660bd8 | 161 | for file in "${input_dir}/"*.mod "${input_dir}/"efiemu32.o "${input_dir}/"efiemu64.o; do |
efda854e | 162 | if test -f "$file"; then |
7e70395f | 163 | cp -f "$file" ${iso9660_dir}/boot/grub/${platform}/ |
efda854e RM |
164 | fi |
165 | done | |
10a88797 FZ |
166 | for file in ${pkglib_DATA}; do |
167 | if test -f "${input_dir}/${file}"; then | |
7e70395f | 168 | cp -f "${input_dir}/${file}" ${iso9660_dir}/boot/grub/${platform}/ |
10a88797 FZ |
169 | fi |
170 | done | |
57bbe3be CPE |
171 | |
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/ | |
176 | fi | |
177 | done | |
efda854e RM |
178 | } |
179 | ||
7e70395f VS |
180 | make_image () |
181 | { | |
182 | source_directory="$1" | |
183 | platform=$2 | |
184 | if ! test -e "${source_directory}"; then | |
185 | return; | |
efda854e | 186 | fi |
fc2208b0 | 187 | |
7e70395f VS |
188 | echo "Enabling $2 support ..." |
189 | ||
b65ea155 GS |
190 | memdisk_img=`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1 |
191 | memdisk_dir=`mktemp -d "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1 | |
fc2208b0 | 192 | mkdir -p ${memdisk_dir}/boot/grub |
fc2208b0 | 193 | |
fc2208b0 | 194 | cat << EOF > ${memdisk_dir}/boot/grub/grub.cfg |
c982589f | 195 | search --fs-uuid --set=root ${iso_uuid} |
7e70395f VS |
196 | set prefix=(\${root})/boot/grub/${platform} |
197 | source \$prefix/grub.cfg | |
fc2208b0 | 198 | EOF |
b0c4f956 | 199 | (for i in $(cat ${source_directory}/partmap.lst) ${modules} ; do |
fc2208b0 RM |
200 | echo "insmod $i" |
201 | done ; \ | |
202 | echo "source /boot/grub/grub.cfg") \ | |
7e70395f | 203 | > ${iso9660_dir}/boot/grub/${platform}/grub.cfg |
fc2208b0 | 204 | |
3eaac1a1 | 205 | (cd "${memdisk_dir}"; tar -cf - boot) > "${memdisk_img}" |
fc2208b0 | 206 | rm -rf ${memdisk_dir} |
7fb5c25f | 207 | $grub_mkimage -O ${platform} -d "${source_directory}" -m "${memdisk_img}" -o "$3" --prefix='(memdisk)/boot/grub' \ |
ee62c427 | 208 | search iso9660 configfile normal memdisk tar $4 |
7e70395f VS |
209 | rm -rf ${memdisk_img} |
210 | } | |
211 | ||
efda854e | 212 | if [ "${override_dir}" = "" ] ; then |
7210dca9 | 213 | if test -e "${multiboot_dir}" ; then |
7e70395f VS |
214 | process_input_dir ${multiboot_dir} i386-multiboot |
215 | fi | |
216 | if test -e "${coreboot_dir}" ; then | |
217 | process_input_dir ${coreboot_dir} i386-coreboot | |
218 | fi | |
219 | if test -e "${qemu_dir}" ; then | |
220 | process_input_dir ${qemu_dir} i386-qemu | |
fc2208b0 | 221 | fi |
efda854e | 222 | if test -e "${pc_dir}" ; then |
7e70395f | 223 | process_input_dir ${pc_dir} i386-pc |
efda854e | 224 | fi |
ac0289ba | 225 | if test -e "${efi32_dir}" ; then |
7e70395f | 226 | process_input_dir ${efi32_dir} i386-efi |
ac0289ba VS |
227 | fi |
228 | if test -e "${efi64_dir}" ; then | |
7e70395f | 229 | process_input_dir ${efi64_dir} x86_64-efi |
ac0289ba | 230 | fi |
efda854e | 231 | else |
b84f26c5 | 232 | . "${override_dir}"/modinfo.sh |
6ad6223e | 233 | process_input_dir "${override_dir}" ${grub_modinfo_target_cpu}-${grub_modinfo_platform} |
7210dca9 | 234 | multiboot_dir= |
efda854e | 235 | pc_dir= |
ac0289ba VS |
236 | efi32_dir= |
237 | efi64_dir= | |
7e70395f VS |
238 | coreboot_dir= |
239 | qemu_dir= | |
6ad6223e | 240 | case "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" in |
918405fd | 241 | i386-multiboot) multiboot_dir=${override_dir} ;; |
7e70395f VS |
242 | i386-coreboot) coreboot_dir=${override_dir} ;; |
243 | i386-qemu) qemu_dir=${override_dir} ;; | |
244 | i386-pc) pc_dir=${override_dir} ;; | |
ac0289ba VS |
245 | i386-efi) efi32_dir=${override_dir} ;; |
246 | x86_64-efi) efi64_dir=${override_dir} ;; | |
efda854e | 247 | esac |
fc2208b0 RM |
248 | fi |
249 | ||
13ac4305 VS |
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)" | |
253 | ||
52cc3ce0 | 254 | # build BIOS core.img |
efda854e | 255 | if test -e "${pc_dir}" ; then |
52cc3ce0 | 256 | echo "Enabling BIOS support ..." |
b65ea155 | 257 | core_img=`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1 |
26966aeb | 258 | $grub_mkimage -O i386-pc -d ${pc_dir}/ -o ${core_img} --prefix=/boot/grub/i386-pc \ |
b15937b1 | 259 | iso9660 biosdisk |
fc2208b0 | 260 | cat ${pc_dir}/cdboot.img ${core_img} > ${iso9660_dir}/boot/grub/i386-pc/eltorito.img |
0ae56929 | 261 | |
b65ea155 | 262 | embed_img=`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1 |
e9309813 | 263 | cat ${pc_dir}/boot.img ${core_img} > ${embed_img} |
0ae56929 | 264 | |
fc2208b0 RM |
265 | rm -f ${core_img} |
266 | ||
b0c4f956 | 267 | (for i in $(cat ${pc_dir}/partmap.lst) ${modules} ; do |
fc2208b0 RM |
268 | echo "insmod $i" |
269 | done ; \ | |
270 | echo "source /boot/grub/grub.cfg") \ | |
271 | > ${iso9660_dir}/boot/grub/i386-pc/grub.cfg | |
272 | ||
47779711 | 273 | grub_mkisofs_arguments="${grub_mkisofs_arguments} -b boot/grub/i386-pc/eltorito.img -no-emul-boot -boot-info-table \ |
0ae56929 | 274 | --embedded-boot ${embed_img}" |
fc2208b0 RM |
275 | fi |
276 | ||
7e70395f | 277 | # build multiboot core.img |
efff4b1c | 278 | make_image "${multiboot_dir}" i386-multiboot "${iso9660_dir}/boot/multiboot.img" "pata ahci at_keyboard" |
7e70395f | 279 | |
260ddb94 | 280 | if test -e "${efi64_dir}" || test -e "${efi32_dir}"; then |
b65ea155 | 281 | efi_dir=`mktemp -d "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1 |
260ddb94 | 282 | mkdir -p "${efi_dir}/efi/boot" |
13ac4305 | 283 | |
7e70395f VS |
284 | # build bootx64.efi |
285 | make_image "${efi64_dir}" x86_64-efi "${efi_dir}"/efi/boot/bootx64.efi "" | |
286 | # build bootia32.efi | |
287 | make_image "${efi32_dir}" i386-efi "${efi_dir}"/efi/boot/bootia32.efi "" | |
fc858482 VS |
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 | |
291 | fi | |
13ac4305 | 292 | |
260ddb94 VS |
293 | mformat -C -f 2880 -L 16 -i "${iso9660_dir}"/efi.img :: |
294 | mcopy -s -i "${iso9660_dir}"/efi.img ${efi_dir}/efi ::/ | |
ea9be8ea | 295 | rm -rf ${efi_dir} |
260ddb94 | 296 | grub_mkisofs_arguments="${grub_mkisofs_arguments} --efi-boot efi.img" |
ac0289ba VS |
297 | fi |
298 | ||
efff4b1c | 299 | make_image "${qemu_dir}" i386-qemu "${iso9660_dir}/boot/qemu.img" "pata at_keyboard" |
7e70395f VS |
300 | if [ -e "${iso9660_dir}/boot/qemu.img" ] && [ -d "${rom_directory}" ]; then |
301 | cp "${iso9660_dir}/boot/qemu.img" "${rom_directory}/qemu.img" | |
302 | fi | |
efff4b1c | 303 | make_image "${coreboot_dir}" i386-coreboot "${iso9660_dir}/boot/coreboot.elf" "pata ahci at_keyboard" |
7e70395f VS |
304 | if [ -e "${iso9660_dir}/boot/coreboot.elf" ] && [ -d "${rom_directory}" ]; then |
305 | cp "${iso9660_dir}/boot/coreboot.elf" "${rom_directory}/coreboot.elf" | |
306 | fi | |
307 | ||
fc2208b0 | 308 | # build iso image |
a6085973 | 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} |
fc2208b0 RM |
310 | rm -rf ${iso9660_dir} |
311 | ||
0ae56929 RM |
312 | rm -f ${embed_img} |
313 | ||
fc2208b0 | 314 | exit 0 |