2
# grub-image - Create a GRUB boot filesystem image and tarball
3
# Gordon Matzigkeit <gord@fig.org>, 2000-07-25
5
# Copyright (C) 2000, 2002 Free Software Foundation, Inc.
7
# This file is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 2 of the License, or
10
# (at your option) any later version.
12
# This program is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
# General Public License for more details.
17
# You should have received a copy of the GNU General Public License
18
# along with this program; if not, write to the Free Software
19
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22
exec_prefix=@exec_prefix@
28
host_vendor=@host_vendor@
29
context=${host_cpu}-${host_vendor}
30
pkglibdir=${libdir}/${PACKAGE}/${context}
34
progname=`echo "$0" | sed 's%^.*/%%'`
35
thisdir=`echo "$0" | sed 's%/[^/]*$%%'`
36
test "X$thisdir" = "X$0" && thisdir=.
38
# See if we were invoked from within the build directory, and if so,
39
# use the built files rather than the installed ones.
40
if test -f $thisdir/../stage2/stage2; then
41
grub_shell="$thisdir/../grub/grub"
42
stage1dir="$thisdir/../stage1"
43
stage2dir="$thisdir/../stage2"
45
grub_shell=${sbindir}/grub
46
stage1dir="$pkglibdir"
47
stage2dir="$pkglibdir"
53
# Get GRUB's version from the Grub shell, since we use the
55
VERSION=`$grub_shell --version | sed -e 's/^.* \([0-9.]*\).*$/\1/'`
58
bootdir=${PACKAGE}-${VERSION}-${context}
62
if test ! -f $bootdir.tar.gz; then
63
echo "# Creating \`$bootdir.tar.gz'"
64
mkdir -p $bootdir/boot/grub
65
cp -p $stage1dir/stage1 $stage2dir/*_stage1_5 $stage2dir/stage2 \
67
test ! -f menu.lst || cp -p menu.lst $bootdir/boot/grub
68
trap "rm -f $bootdir.tar.gz" 0
69
GZIP=-9 tar -zcf $bootdir.tar.gz $bootdir
74
# Create a new filesystem image of the specified size.
75
if test ! -f $image; then
76
tarsize=`zcat $bootdir.tar.gz | wc -c`
78
# Add about 30% (20% overhead plus 10% breathing room), and convert
79
# to kilobytes. This factor was determined empirically.
80
SIZE=`expr $tarsize \* 130 / 100 / 1024`k
81
echo "# Creating $SIZE disk image \`$image'"
83
dd if=/dev/zero of=$image bs=$SIZE count=1 >/dev/null
89
# Attempt to mount the image.
90
echo "# Mounting \`$image'"
91
test -d $bootdir || mkdir $bootdir
94
settrans -a $bootdir /hurd/ext2fs $image
95
umount="settrans -a $bootdir"
99
# This requires running as root, and using the loop device.
101
while test -e /dev/loop$i; do
102
if /sbin/losetup /dev/loop$i $image; then
108
# Silly losetup doesn't report an error!
109
mount /dev/loop$i $bootdir
110
umount="umount $bootdir && /sbin/losetup -d /dev/loop$i && trap '' 0"
114
echo "$progname: Mounting \`$image' under \`$host_os' is not supported" 1>&2
120
# Extract our tarball into the image, then unmount it.
121
echo "# Copying files into \`$image':"
122
tar -zxvf $bootdir.tar.gz
124
echo "# \`$image' usage:"
129
# Use the GRUB shell to properly set up GRUB on the image.
130
echo "# Installing GRUB in \`$image'"
131
cat <<EOF | $grub_shell --batch --device-map=/dev/null
134
install /boot/grub/stage1 (fd0) /boot/grub/stage2