I've spent the last couple of days trying to work out how to create a HD image containing a filesystem(ext2fs, ufs, fat32 not bothered at this stage) with Grub installed.
I found a script 'mkbimage' which seems to be for linux. Using what I had figured out at that stage I managed to hack it around and can now create a floppy disk image and boot it in bochs IA32 emulator. The problem is I cant work out how to create a HD image. Appended to this post is the script. As i've been hacking it further it currently does not create a filesystem on the image. Previously though I had it to the stage where it would create the fs, mount it and copy in the 'stuff'. The problem then was grub refused to use the image complaing of a corrupt partition table. Also I was unsure how the fact that their where no BSD sub partitions would effect things - but as I could mount the partition from FreeBsd I figured Grub would be able to mount it too. I am new to unix and now feeling a little frustrated. I would greatly appreciate ANY help. Thanks in advance Ryan my - mkimage - My Appologies for the duplication in the script but I dont know how else to get these things out to the console. As I mentioned above this version does not even create a fs now ..... zzz #!/bin/sh # MaKe a Bootable IMAGE --- 1.44, 2.88 and El Torito no-emulation mode # C) 2001 Thierry Laronde <[EMAIL PROTECTED]> # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2, 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, you can either send email to this # program's maintainer or write to: The Free Software Foundation, # Inc.; 59 Temple Place, Suite 330; Boston, MA 02111-1307, USA. # $Id: mkbimage,v 1.2 2001/10/14 15:19:55 tlaronde Exp $ # Global variables tarfile= dir= fs= #file system type decompress= image_type= #----------------------------DON'T CHANGE: INTERNALS block_size=512 cylinders= heads= sectors= cyl_size= type_option= geo_option= image= bk_120=$((2 * 15 * 80)) bk_144=$((2 * 18 * 80)) bk_288=$((2 * 36 * 80)) bk_160=$((2 * 20 * 80)) bk_168=$((2 * 21 * 80)) bk_174=$((2 * 21 * 83)) lo_options= device_map= fdisk_config= disklabel_config= sectorspcylinder= sectorspunit= # Name by which this script was invoked. program=`echo "$0" | sed -e 's/[^\/]*\///g'` mkbimage_version='$Id: mkbimage,v 1.2 2001/10/14 15:19:55 tlaronde Exp $' usage=" Usage: $program [-h] [-V] [-t TYPE] [-d DIRECTORY] [-s FS_TYPE] -f TAR_FILE Make a Bootable IMAGE using GRUB as a bootloader Options: Actions: -d DIRECTORY [default CWD] Directory where the boot.image and the partition subdirectories are/will be created -f TAR_FILE Name of the tar file containing the filesystem to install. Can be a pure tar file [.tar] or a compressed tar file [.tar.gz|.tar.bz2] -s FS_TYPE Type of the file system to create on the virtual disk [default is ext2]. XXX: At the moment the script has been designed for ext2. -t TYPE Type of the image to create. Choices are '1.20', '1.44', '1.68', '1.74' '2.88' or 'hd' [default is hd] Informations: -h display this Help and exit -V display Version information and exit Copyright (c) 2001 Thierry Laronde <[EMAIL PROTECTED]>. GPLed." version="$mkbimage_version Written by Thierry Laronde. Copyright (c) 2001 Thierry Laronde <[EMAIL PROTECTED]>. This is free software under the GPL version 2 or later; see the source for copying conditions. There is NO warranty, not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." # Functions error () { case $1 in bug) echo "This is a bug!"; echo "$usage";; option) echo "Unknow option"; echo "$usage";; missing_argument) echo "You must give an argument to the option!"; echo "$usage";; missing_option) echo "You must indicate at least one option!"; echo "$usage";; must_be_root) echo "You must be root!";; unknown_format) echo "The tar file must be .tar|.tar.gz|.tar.bz2 !";; wont_fit) echo "The files won't fit on the selected type of media!";; wrong_directory) echo "Directory inexistant or not given!"; echo "$usage";; wrong_file) echo "File inexistant or empty!"; echo "$usage";; wrong_type) echo "The type specified is not a valid one!"; echo "$usage";; esac exit 1 } #********************************************************************** # MAIN PROGRAM * #********************************************************************** #---------------------- Getting the options [ $# -eq 0 ] && error missing_option; while [ $# -gt 0 ]; do case "$1" in -d) shift; dir="$1"; [ ! -d "$1" ] && error wrong_directory;; -f) shift; tarfile="$1"; [ -z "$tarfile" ] && error missing_argument;; -s) shift; fs="$1";; -t) shift; image_type="$1";; -h) echo "$usage"; exit 0;; -V) echo "$version"; exit 0;; *) error option ;; esac shift done #---------------------- Must be root [ ! `id -u` -eq 0 ] && error must_be_root; [ ! "$tarfile" ] && error missing_argument; [ ! -s "$tarfile" ] && error wrong_file; if [ ! "$image_type" ]; then image_type=hd; elif [ "$image_type" != "1.20" -a "$image_type" != "1.44" \ -a "$image_type" != "1.68" \ -a "$image_type" != "2.88" -a "$image_type" != "1.74" \ -a "$image_type" != "hd" -a "$image_type" != "1.60" ] ; then error wrong_type ; fi #---------------------- Initializations [ ! "$dir" ] && dir=`pwd` [ ! "$fs" ] && fs=ext2 # What type of tar file has been given ? suffix=`echo "$tarfile" | sed -n 's/^.*\.\([targbz2]\{2,3\}\)$/\1/p'` case "$suffix" in tar) decompress="cat";; gz) decompress="gunzip -c";; bz2) decompress="bunzip2 -c";; *) error unknown_format;; esac image=$dir/$image_type.image device_map=$dir/device.map fdisk_config=$dir/fdiskconfig disklabel_config=$dir/disklabelconfig # First, find the size of the tar file in block_size. file_size=`$decompress $tarfile | wc -c | tr -d ' '` file_size=$(($file_size / $block_size + 1)) case "$image_type" in hd) heads=16; sectors=63; cyl_size=$((16 * 63)); # One cylinder for MBR and one to round up cylinders=$(($file_size / $cyl_size + 2)); sectorspcylinder=$(($sectors * $heads)); sectorspunit=$(($sectors * $cylinders * $heads));; 1.20) [ $file_size -ge $bk_120 ] && error wont_fit; heads=2; sectors=15; cyl_size=$((2 * 15)); cylinders=80;; 1.44) [ $file_size -ge $bk_144 ] && error wont_fit; heads=2; sectors=18; cyl_size=$((2 * 18)); cylinders=80;; 1.60) [ $file_size -ge $bk_160 ] && error wont_fit; heads=2; sectors=20; cyl_size=$((2 * 20)); cylinders=80; geo_option="-F";; 1.68) [ $file_size -ge $bk_168 ] && error wont_fit; heads=2; sectors=21; cyl_size=$((2 * 21)); cylinders=80;; 1.74) [ $file_size -ge $bk_174 ] && error wont_fit; heads=2; sectors=21; cyl_size=$((2 * 21)); cylinders=83;; 2.88) [ $file_size -ge $bk_288 ] && error wont_fit; heads=2; sectors=36; cyl_size=$((2 * 36)); cylinders=80;; *) error bug;; esac type_option="-t $image_type" [ "$image_type" = "1.60" ] && type_option= # We start by creating a virtual disk which size is the number of # cylinders of $cyl_size mandatory to put the files stocked in the $tarfile # We then create the empty virtual disk dd if=/dev/zero of=$image bs=$block_size count=$(($cyl_size * $cylinders)) # We then format the virtual disk # NOTE: the El Torito specification wants only one partition. So we # create the first, and the remaining 3 entries are empty. echo vnconfig -s labels -c vn0 $image vnconfig -s labels -c vn0 $image echo disklabel -r -w vn0 auto disklabel -r -w vn0 auto if [ "$image_type" = "hd" ]; then cat<<EOT >$disklabel_config # /dev/vn0c: type: unknown disk: amnesiac label: flags: bytes/sector: 512 sectors/track: $sectors tracks/cylinder: $heads sectors/cylinder: $sectorspcylinder cylinders: $cylinders sectors/unit: $sectorspunit rpm: 3600 interleave: 1 trackskew: 0 cylinderskew: 0 headswitch: 0 # milliseconds track-to-track seek: 0 # milliseconds drivedata: 0 8 partitions: # size offset fstype [fsize bsize bps/cpg] c: $sectorspunit 0 unused 0 0 # (Cyl. 0 - 9*) EOT cat<<EOT # /dev/vn0c: type: unknown disk: amnesiac label: flags: bytes/sector: 512 sectors/track: $sectors tracks/cylinder: $heads sectors/cylinder: $sectorspcylinder cylinders: $cylinders sectors/unit: $sectorspunit rpm: 3600 interleave: 1 trackskew: 0 cylinderskew: 0 headswitch: 0 # milliseconds track-to-track seek: 0 # milliseconds drivedata: 0 8 partitions: # size offset fstype [fsize bsize bps/cpg] c: $sectorspunit 0 unused 0 0 # (Cyl. 0 - 9*) EOT echo disklabel -R vn0 $disklabel_config disklabel -R vn0 $disklabel_config cat<<EOT g c$cylinders h$heads s$sectors EOT cat<<EOT >$fdisk_config g c$cylinders h$heads s$sectors EOT fdisk -f $fdisk_config /dev/vn0 fdisk /dev/vn0 fi echo newfs /dev/vn0c newfs /dev/vn0c mkdir ${image}1 2>/dev/null mount /dev/vn0 ${image}1 $decompress $tarfile | tar -C ${image}1 -xf - # Find stage2 name stage2= while [ ! "$stage2" ]; do stage2=`find ${image}1 -type f -name stage2 2>/dev/null` done sync umount ${image}1 #------------------------- GRUB stuff if [ "$image_type" = "hd" ]; then device='(hd0)' root='(hd0,0,a)' else device='(fd0)' root='(fd0)' fi cat<<EOT >$device_map $device /dev/vn0c EOT grub --device-map=$device_map --batch<<EOT geometry $device $cylinders $heads $sectors root $root setup $device quit EOT vnconfig -u vn0 echo "-------------------WHAT'S NEXT--------------------" echo echo cat <<EOF Enjoy! EOF exit 0 __________________________________________________ Do You Yahoo!? Everything you'll ever need on one web page from News and Sport to Email and Music Charts http://uk.my.yahoo.com _______________________________________________ Bug-grub mailing list [EMAIL PROTECTED] http://mail.gnu.org/mailman/listinfo/bug-grub