# grub-image - Create a GRUB boot filesystem image and tarball
# Gordon Matzigkeit <gord@fig.org>, 2000-07-25
#
# Copyright (C) 2000, 2002 Free Software Foundation, Inc.
#
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
# See if we were invoked from within the build directory, and if so,
# use the built files rather than the installed ones.
grub_shell="$thisdir/../grub/grub"
else
fi
# Exit on any error.
set -e
# Get GRUB's version from the Grub shell, since we use the
# installed files.
test "X$VERSION" != X
# Create the tarball.
trap '' 0
fi
# Create a new filesystem image of the specified size.
if test ! -f $image; then
# Add about 30% (20% overhead plus 10% breathing room), and convert
# to kilobytes. This factor was determined empirically.
trap "rm -f $image" 0
trap '' 0
fi
# Attempt to mount the image.
echo "# Mounting \`$image'"
gnu*)
;;
linux*)
# This requires running as root, and using the loop device.
i=0
break
fi
i=`expr $i + 1`
done
# Silly losetup doesn't report an error!
;;
*)
exit 1
;;
esac
trap "$umount" 0
# Extract our tarball into the image, then unmount it.
echo "# Copying files into \`$image':"
echo "# \`$image' usage:"
eval $umount
# Use the GRUB shell to properly set up GRUB on the image.
echo "# Installing GRUB in \`$image'"
cat <<EOF | $grub_shell --batch --device-map=/dev/null
device (fd0) $image
root (fd0)
install /boot/grub/stage1 (fd0) /boot/grub/stage2
quit
EOF
exit 0