]> git.proxmox.com Git - grub2.git/blame - util/i386/pc/grub-mkrescue.in
2009-05-02 Vladimir Serbinenko <phcoder@gmail.com>
[grub2.git] / util / i386 / pc / grub-mkrescue.in
CommitLineData
59d31694 1#! /bin/sh -e
7ee367e4 2
3# Make GRUB rescue image
e0ca0677 4# Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2006,2007,2008 Free Software Foundation, Inc.
7ee367e4 5#
5a79f472 6# GRUB is free software: you can redistribute it and/or modify
7# it under the terms of the GNU General Public License as published by
8# the Free Software Foundation, either version 3 of the License, or
7ee367e4 9# (at your option) any later version.
10#
5a79f472 11# GRUB is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU General Public License for more details.
7ee367e4 15#
16# You should have received a copy of the GNU General Public License
5a79f472 17# along with GRUB. If not, see <http://www.gnu.org/licenses/>.
7ee367e4 18
19# Initialize some variables.
20transform="@program_transform_name@"
21
22prefix=@prefix@
23exec_prefix=@exec_prefix@
24bindir=@bindir@
25libdir=@libdir@
26PACKAGE_NAME=@PACKAGE_NAME@
27PACKAGE_TARNAME=@PACKAGE_TARNAME@
28PACKAGE_VERSION=@PACKAGE_VERSION@
29target_cpu=@target_cpu@
30platform=@platform@
31pkglibdir=${libdir}/`echo ${PACKAGE_TARNAME}/${target_cpu}-${platform} | sed ${transform}`
32
33grub_mkimage=${bindir}/`echo grub-mkimage | sed ${transform}`
34
35# Usage: usage
36# Print the usage.
37usage () {
38 cat <<EOF
39Usage: grub-mkrescue [OPTION] output_image
40Make GRUB rescue image.
41
42 -h, --help print this message and exit
43 -v, --version print the version information and exit
44 --modules=MODULES pre-load specified modules MODULES
06ab5303 45 --overlay=DIR overlay directory DIR in the memdisk image
64d2d53c 46 (may be specified multiple times)
59d31694 47 --pkglibdir=DIR use images from directory DIR instead of ${pkglibdir}
7ee367e4 48 --grub-mkimage=FILE use FILE as grub-mkimage
59d31694 49 --image-type=TYPE select floppy or cdrom (default)
e54a72f5 50 --emulation=TYPE select El Torito boot emulation type floppy
51 or none (default) (cdrom only)
7ee367e4 52
53grub-mkimage generates a bootable rescue image of the specified type.
54
68807e5f 55Report bugs to <bug-grub@gnu.org>.
7ee367e4 56EOF
57}
58
59image_type=cdrom
59d31694 60input_dir=${pkglibdir}
e54a72f5 61emulation=none
7ee367e4 62
63# Check the arguments.
64for option in "$@"; do
65 case "$option" in
66 -h | --help)
67 usage
68 exit 0 ;;
69 -v | --version)
9a745147 70 echo "grub-mkrescue (GNU GRUB ${PACKAGE_VERSION})"
7ee367e4 71 exit 0 ;;
72 --modules=*)
73 modules=`echo "$option" | sed 's/--modules=//'` ;;
06ab5303 74 --overlay=*)
64d2d53c 75 overlay=${overlay}${overlay:+ }`echo "$option" | sed 's/--overlay=//'` ;;
59d31694 76 --pkglibdir=*)
77 input_dir=`echo "$option" | sed 's/--pkglibdir=//'` ;;
7ee367e4 78 --grub-mkimage=*)
79 grub_mkimage=`echo "$option" | sed 's/--grub-mkimage=//'` ;;
80 --image-type=*)
81 image_type=`echo "$option" | sed 's/--image-type=//'`
82 case "$image_type" in
83 floppy|cdrom) ;;
84 *)
85 echo "Unknown image type \`$image_type'" 1>&2
86 exit 1 ;;
87 esac ;;
e54a72f5 88 --emulation=*)
89 emulation=`echo "$option" | sed 's/--emulation=//'`
90 case "$emulation" in
91 floppy|none) ;;
92 *)
93 echo "Unknown emulation type \`$emulation'" 1>&2
94 exit 1 ;;
95 esac ;;
7ee367e4 96 -*)
97 echo "Unrecognized option \`$option'" 1>&2
98 usage
99 exit 1
100 ;;
101 *)
102 if test "x$output_image" != x; then
103 echo "Unrecognized option \`$option'" 1>&2
104 usage
105 exit 1
106 fi
107 output_image="${option}" ;;
108 esac
109done
110
59d31694 111if test "x$output_image" = x; then
112 usage
113 exit 1
114fi
115
e0ca0677 116aux_dir=`mktemp -d`
117mkdir -p ${aux_dir}/boot/grub
7ee367e4 118
06ab5303 119cp ${input_dir}/*.mod \
120 ${input_dir}/command.lst ${input_dir}/moddep.lst ${input_dir}/fs.lst \
d9dc87b0 121 ${input_dir}/handler.lst ${input_dir}/parttool.lst \
e0ca0677 122 ${aux_dir}/boot/grub/
06ab5303 123
58cd3d85 124modules="biosdisk `cat ${input_dir}/partmap.lst` ${modules}"
125for i in ${modules} ; do
126 echo "insmod $i"
127done > ${aux_dir}/boot/grub/grub.cfg
128
64d2d53c 129for d in ${overlay}; do
130 echo "Overlaying $d"
131 cp -dpR "${d}"/* "${aux_dir}"/
132done
06ab5303 133
e54a72f5 134if [ "x${image_type}" = xfloppy -o "x${emulation}" = xfloppy ] ; then
e0ca0677 135 # build memdisk
136 memdisk_img=`mktemp`
137 tar -C ${aux_dir} -cf ${memdisk_img} boot
138 rm -rf ${aux_dir}
139
140 # build core.img
141 core_img=`mktemp`
f821ce59 142 ${grub_mkimage} -d ${input_dir}/ -m ${memdisk_img} -o ${core_img} memdisk tar
e0ca0677 143 rm -f ${memdisk_img}
144
145 # build floppy image
e54a72f5 146 if [ "x${image_type}" = xcdrom ] ; then
147 floppy_dir=`mktemp -d`
148 floppy_img=${floppy_dir}/grub_floppy.img
149 else
150 floppy_img=${output_image}
151 fi
152 cat ${input_dir}/boot.img ${core_img} /dev/zero | dd bs=1024 count=1440 > ${floppy_img}
e0ca0677 153 rm -f ${core_img}
e54a72f5 154
155 if [ "x${image_type}" = xcdrom ] ; then
156 # build iso image
157 genisoimage -b grub_floppy.img \
158 -o ${output_image} -r -J ${floppy_dir}
159 rm -rf ${floppy_dir}
160 fi
e0ca0677 161else
162 # build core.img
163 core_img=`mktemp`
58cd3d85 164 ${grub_mkimage} -d ${input_dir}/ -o ${core_img} biosdisk iso9660
e0ca0677 165
166 # build grub_eltorito image
167 cat ${input_dir}/cdboot.img ${core_img} > ${aux_dir}/boot/grub/grub_eltorito
168 rm -f ${core_img}
169
170 # build iso image
171 genisoimage -b boot/grub/grub_eltorito \
172 -no-emul-boot -boot-load-size 4 -boot-info-table \
e54a72f5 173 -o ${output_image} -r -J ${aux_dir}
e0ca0677 174 rm -rf ${aux_dir}
7ee367e4 175fi
176
7ee367e4 177exit 0