-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_floppy.sh
79 lines (58 loc) · 1.92 KB
/
create_floppy.sh
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
#!/bin/bash
# By David Lindsay <address@hidden>
# I wouldn't have discovered the --device-map/dev/null and "device
#(hd0) /dev/loopX" tricks had I not found http://sig9.com/bochs-grub,
#so I must thank "Vivek" for that vital knowledge!
# Some required info:
# Image name (include a path if you want)
imgname=floppy.img
# Loopback device
loopdevice=/dev/loop1
# Filesystem
fs=ext2
# OR
# fs=msdos
# Image mountpoint (NEEDS TO EXIST):
mntpath=/mnt/floppy2
# Location of stage1 and stage2
stage1=stage1
stage2=stage2
# ---
# 1. Create a floppy disk image:
! dd if=/dev/zero of=$imgname bs=1024 count=1440
# OR
# ! qemu-img create $imgname 1440
# 2. Setup a loopback device
losetup $loopdevice $imgname
# 3. Create a filesystem:
mkfs -V -t $fs $loopdevice
# 4. Mount it somewhere:
mount -o loop $loopdevice $mntpath
# 5. Copy stage1 and stage2 to it:
cp $stage1 $mntpath
cp $stage2 $mntpath
# 7. Unmount the image:
umount $mntpath
# 8. Use the GRUB shell to work its magic on stage1 and stage2 so they boot
echo -e "device (fd0) $loopdevice\nroot (fd0)\ninstall /$(basename \
$stage1) d (fd0) /$(basename $stage2)\nquit" | grub \
--device-map=/dev/null --batch
# 9. Remount the image
mount -o loop $loopdevice $mntpath
# 10. Remove stage1 and stage2, which don't appear to be needed
# anymore and will only consume unneccessary space on the disk - I've
# personally had success removing both files under both FAT and ext2.
# rm $mntpath/$(basename $stage1)
# rm $mntpath/$(basename $stage2)
# 11. Copy any extra files you want to the disk at this point.
# Note: I have this step here because until step 10 you had around
# 100K of data on the image that would have been deleted anyway.
mkdir -p $mntpath/boot/grub
cp menu.lst $mntpath/boot/grub/grub.conf
cp menu.lst $mntpath/boot/grub/menu.lst
cp kernel.bin $mntpath
cp README $mntpath
# 12. Unmount the image. Again. :P
umount $mntpath
# 13. Finally delete the loopback device.
losetup $loopdevice -d