|
|
1.1 root 1: #!/bin/sh
2: # script for creating a compatible DOS HD image for Hatari
3: # with a single FAT16 partition of given size
4:
5: # defaults for disk attributes
6: diskfile=hd.img # HD image filename
7: partname=DOS # partition name
8:
9: if [ $# -lt 1 ]; then
10: name=${0##*/}
11: echo
12: echo "usage: $name <size> [filename] [partition name] [directory]"
13: echo
14: echo "Create an ACSI/IDE harddisk image for Hatari with a single Atari"
15: echo "compatible DOS partition. Arguments are (defaults in parenthesis):"
16: echo "- size: harddisk image size in megabytes, 8-256"
17: echo "- filename: name for the harddisk image ($diskfile)"
18: echo "- partition name: name for that single partition ($partname)"
19: echo "- directory: directory for initial content copied to the image"
20: echo
21: echo "For example:"
22: echo "- 16MB '$diskfile' HD image:"
23: echo " $name 16"
24: echo "- 8MB image with 'TEST' partition having files from content/:"
25: echo " $name 8 8mb-disk.img TEST content/"
26: echo
27: exit 1
28: fi
29:
30: # sfdisk/mkdosfs reside in /sbin
31: PATH=/sbin:$PATH
32: export PATH
33:
34: # check tools
35: if [ -z $(which sfdisk) ] || [ -z $(which mkdosfs) ]; then
36: echo "ERROR: either sfdisk or mkdosfs missing!"
37: exit 1
38: fi
39:
40: # check disk size
41: if [ $1 -lt 5 ]; then
42: echo "ERROR: disk size needs to be at least 5 (MB) to work properly."
43: exit 1
44: fi
45: if [ $1 -gt 256 ]; then
46: echo "ERROR: EmuTOS supports only partitions up to 256 (MB)."
47: exit 1
48: fi
49: # disk geometry
50: cylinders=$((4*$1)) # 16*32*512 is 1/4MB
51: diskheads=16
52: tracksectors=32 # same as used by mkdosfs
53: sectorsize=512
54: partsize=$(($cylinders*$diskheads*$tracksectors*$sectorsize))
55:
56: # counts in sectors with correct disk geometry
57: sfdisk="sfdisk -uS -C $cylinders -H $diskheads -S $tracksectors"
58:
59: # check optional arguments
60: if [ \! -z $2 ]; then
61: diskfile=$2
62: fi
63: if [ \! -z $3 ]; then
64: partname=$3
65: fi
66: if [ \! -z $4 ]; then
67: if [ -z $(which mcopy) ]; then
68: echo "ERROR: mcopy (from Mtools) missing!"
69: exit 1
70: fi
71: contentdir=$4
72: fi
73:
74: # don't overwrite files by accident
75: if [ -f $diskfile ]; then
76: echo "ERROR: given harddisk image already exits. Give another name or remove it:"
77: echo " rm $diskfile"
78: exit 1
79: fi
80:
81: # temporary files
82: tmppart=$diskfile.part
83:
84: # script exit/error handling
85: exit_cleanup ()
86: {
87: echo
88: if [ $? -eq 0 ]; then
89: echo "$step) Cleaning up..."
90: else
91: echo
92: echo "ERROR, cleaning up..."
93: echo "rm -f $diskfile"
94: rm -f $diskfile
95: fi
96: echo "rm -f $tmppart"
97: rm -f $tmppart
98: echo "Done."
99: }
100: trap exit_cleanup EXIT
101:
102: echo
103: step=1
104: echo "$step) Creating $1MB sparse disk image..."
105: echo "dd if=/dev/zero of=$diskfile bs=1 count=0 seek=$((512+partsize))"
106: dd if=/dev/zero of=$diskfile bs=$((512+partsize)) count=1
107:
108: echo
109: step=$(($step+1))
110: echo "$step) Creating DOS Master Boot Record partition table..."
111: echo "Add DOS MBR signature needed by sfdisk:"
112: echo -e "\0125\0252" | dd of=$diskfile bs=1 seek=510 count=2
113:
114: echo "Add partition table to MBR with single FAT16 partition:"
115: clusters=$(($partsize/1024))
116: if [ $clusters -le 32765 ]; then
117: fatbits=16
118: parttype="0x4"
119: else
120: fatbits=16
121: parttype="0x6"
122: fi
123: echo "Using FAT$fatbits partition type $parttype"
124: echo "$sfdisk --no-reread $diskfile: ,,$parttype,*"
125: $sfdisk --no-reread $diskfile << EOF
126: ,,$parttype,*
127: EOF
128: if [ $? -ne 0 ]; then
129: exit 2
130: fi
131:
132: echo
133: step=$(($step+1))
134: echo "$step) Creating Atari TOS compatible DOS partition..."
135: sectors=$($sfdisk -l $diskfile|awk '/\*/{print $5}')
136: if [ -z "$sectors" ] || [ $sectors -eq 0 ]; then
137: echo "ERROR: couldn't get partition size information."
138: exit 2
139: fi
140: # mkdosfs keeps the sector count below 32765 when -A is used by increasing
141: # the logical sector size (this is for TOS compatibility, -A guarantees
142: # also 2 sectors / cluster and Atari serial number etc). Mtools barfs
143: # if partition size doesn't divide evenly with its track size. Determine
144: # suitable cluster count & corresponding track size and align (decrease)
145: # the file system sector count accordingly.
146: tracksize=32
147: clustertmp=$((sectors/2))
148: echo "Sectors: $sectors, sectors/track: $tracksize, clusters: $clustertmp"
149: while [ $clustertmp -gt 32765 ]; do
150: clustertmp=$((clustertmp/2))
151: tracksize=$(($tracksize*2))
152: echo "Doubling sector size as >32765 clusters -> $clustertmp clusters"
153: done
154: origsectors=$sectors
155: sectors=$(($sectors/$tracksize))
156: sectors=$(($sectors*$tracksize))
157: kilobytes=$(($sectors/2))
158: if [ $sectors -ne $origsectors ]; then
159: echo "Align sector count with clusters/sectors/track: $origsectors -> $sectors ($kilobytes kB)"
160: fi
161: echo "mkdosfs -A -F $fatbits -n $partname -C $tmppart $kilobytes"
162: mkdosfs -A -n $partname -C $tmppart $kilobytes
163:
164: if [ \! -z $contentdir ]; then
165: echo
166: step=$(($step+1))
167: # copy contents of given directory to the new partition
168: echo "$step) Copying the initial content to the partition..."
169: echo "MTOOLS_NO_VFAT=1 mcopy -i $tmppart -spmv $contentdir/* ::"
170: MTOOLS_NO_VFAT=1 mcopy -i $tmppart -spmv $contentdir/* ::
171: if [ $? -ne 0 ]; then
172: echo "ERROR: failed."
173: exit 2
174: fi
175: fi
176:
177: echo
178: step=$(($step+1))
179: # copy the partition into disk
180: echo "$step) Copying the partition to disk image..."
181: start=$($sfdisk -l $diskfile|awk '/\*/{print $3}')
182: if [ -z "$sectors" ] || [ $sectors -eq 0 ]; then
183: echo "ERROR: couldn't get partition start information."
184: exit 2
185: fi
186: echo "dd if=$tmppart of=$diskfile bs=512 seek=$start count=$sectors"
187: dd if=$tmppart of=$diskfile bs=512 seek=$start count=$sectors
188:
189: step=$(($step+1))
190: # cleanup is done by exit_cleanup() trap
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.