#!/bin/sh # Copyright (C) 2008 Emmanuel Varoquaux # This file is part of XOS. # 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 3 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, see . GRUBDIR=/usr/lib/grub/i386-pc error() { echo "$0: $1" >&2 } die() { error "$1" exit 1 } usage() { echo "Usage: $0 [OPTION]... IMAGE KERNEL [ROOTDIR]" echo "Create a bootable floppy disk image of XOS using GRUB as boot loader." echo echo "Mandatory arguments to long options are mandatory for short options too." echo " -h, --help display this help and exit" exit 0 } args=`getopt -o h -l help -n "$0" -- "$@"` status=$? if [ $status != 0 ]; then case $status in 1) echo "Try \`$0 --help' for more information." >&2 exit 1 ;; *) exit 1 ;; esac fi eval set -- "$args" while true; do case "$1" in -h|--help) usage ;; --) shift break ;; *) exit 1 ;; esac done if [ ! $2 ]; then die "missing operand" fi IMAGE=$1 KERNEL=$2 ROOTDIR=$3 dd if=/dev/zero of=$IMAGE bs=18k count=80 || exit 1 export MTOOLSRC=`mktemp` || exit 1 echo "drive u: file=\"$IMAGE\" 1.44M filter" >>$MTOOLSRC mformat U: || exit 1 if [ "$ROOTDIR" -a "`find $ROOTDIR -mindepth 1 -maxdepth 1`" ]; then mcopy -sb $ROOTDIR/* U:/ || exit 1 fi mmd U:/boot || exit 1 mmd U:/boot/grub || exit 1 mcopy $GRUBDIR/stage1 U:/boot/grub/ || exit 1 mcopy $GRUBDIR/stage2 U:/boot/grub/ || exit 1 mcopy -b $KERNEL U:/boot/`basename $KERNEL` || exit 1 MENU=`mktemp` || exit 1 cat <>$MENU default 0 timeout 4 title XOS root (fd0) kernel /boot/`basename $KERNEL` EOF mcopy -b $MENU U:/boot/grub/menu.lst || exit 1 grub --batch </dev/null || exit 1 device (fd0) $IMAGE install (fd0)/boot/grub/stage1 (fd0) (fd0)/boot/grub/stage2 p (fd0)/boot/grub/menu.lst quit EOT rm $MTOOLSRC $MENU exit 0