summaryrefslogtreecommitdiff
blob: 9c225c740bf4f3a1eeed5f527b0977cc52000f2c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/bin/sh
#
# Script for making a memtest86 boot floppy using GRUB as bootloader
#

# (c) 2003 Peter Loje Hansen <pl@2m.dk>
#  - original version
# (c) 2004 Yann Dirson <dirson@debian.org>
#  - added parameters
#  - ability to work on a floppy image instead of a real floppy
#  - adapted patches from Martin Koeppe <martin@koeppe-net.de>, to use
#    mtools and install full grub

# TODO:
# - add a flag to generate a default boot entry for (hd0)

set -e

MEMTEST=/boot/memtest86plus/memtest.bin
FLOPPYIMAGE=/dev/fd0
GRUBBIN=/sbin/grub
GRUBLIB=/lib/grub
MFORMAT=/usr/bin/mformat

arch=$(uname -m)

case "$arch" in
	i386|i486|i686)		GRUBARCH=i386-pc;;
	x86_64)				GRUBARCH=x86_64-pc;;
	*)					error "Unsupported architecture: $arch";;
esac

error()
{
    echo >&2 "$0: $*"
    exit 1
}

needsarg()
{
    [ $1 -ge 2 ] || error "syntax error"
}

[ -d $GRUBLIB ] || error "Can't find $GRUBLIB - did you install a recent grub package (0.95+cvs20040624 or later) ?"
[ -x $MFORMAT ] || error "Can't find mformat - did you install the mtools package ?"

while [ $# -gt 0 ]
do
    case "$1" in
    --help) echo "$0 [--memtest $MEMTEST] [--floppyimage $FLOPPYIMAGE]"; exit 0 ;;
    --memtest) needsarg $#; MEMTEST="$2"; shift ;;
    --floppyimage) needsarg $#; FLOPPYIMAGE="$2"; shift ;;
    *) error "syntax error" ;;
    esac
    shift
done

MOUNTPOINT=$(mktemp -d)

if [ -b "$FLOPPYIMAGE" ]
then
    FINALDEV="$FLOPPYIMAGE"
    FLOPPYIMAGE="$(mktemp)"
else
    FINALDEV=""
fi

echo "* Creating msdos file system"
echo
if [ ! -s "$FLOPPYIMAGE" ]; then
    # unless a non-empty image exists, create a blank one first
    dd bs=1024 count=1440 if=/dev/zero of="$FLOPPYIMAGE"
fi
# FIXME: "-f 1440" should probably be dropped
mformat -i $FLOPPYIMAGE -f 1440 :: 

mmd -i $FLOPPYIMAGE ::/boot 
mmd -i $FLOPPYIMAGE ::/boot/grub 

echo
echo "* Installing GRUB files"
mcopy -v -i "$FLOPPYIMAGE" - ::/boot/grub/menu.lst <<EOF
color green/black light-green/black
default 0
timeout 10
title  memtest
kernel (fd0)/boot/memtest.bin
EOF
mcopy -v -i "$FLOPPYIMAGE" $GRUBLIB/$GRUBARCH/* ::/boot/grub 

echo
echo "* Installing $MEMTEST"
mcopy -v -i "$FLOPPYIMAGE" "$MEMTEST" ::/boot/memtest.bin 

echo
echo -n "* Installing GRUB"
$GRUBBIN --batch --device-map=/dev/null <<EOF
device (fd0) $FLOPPYIMAGE
root (fd0)
setup (fd0)
quit
EOF

if [ -n "$FINALDEV" ]; then
    echo
    echo "Insert a writable floppy for $FINALDEV and press enter"
    read FOO

    dd bs=1024 if="$FLOPPYIMAGE" of="$FINALDEV"
    rm "$FLOPPYIMAGE"
fi