The information you need to do this can be found in the
fdisk man page, in the CONFIGURATION FILE section.
To understand this file better you can ask fdisk to create such a file from an existing MBR.
Code:
-p Print a slice table in fdisk configuration file format and exit;
see CONFIGURATION FILE, below
First the MBR in the default displayp
Code:
# fdisk ad0
******* Working on device /dev/ad0 *******
parameters extracted from in-core disklabel are:
cylinders=4961616 heads=1 sectors/track=63 (63 blks/cyl)
Figures below won't work with BIOS for partitions not in cyl 1
parameters to be used for BIOS calculations are:
cylinders=4961616 heads=1 sectors/track=63 (63 blks/cyl)
Media sector size is 512
Warning: BIOS sector numbering starts with sector 1
Information from DOS bootblock is:
The data for partition 1 is:
sysid 166 (0xa6),(OpenBSD)
start 63, size 78156162 (38162 Meg), flag 0
beg: cyl 0/ head 1/ sector 1;
end: cyl 1023/ head 254/ sector 63
The data for partition 2 is:
sysid 165 (0xa5),(FreeBSD/NetBSD/386BSD)
start 78156225, size 78140160 (38154 Meg), flag 0
beg: cyl 1023/ head 255/ sector 63;
end: cyl 1023/ head 254/ sector 63
The data for partition 3 is:
sysid 165 (0xa5),(FreeBSD/NetBSD/386BSD)
start 156296385, size 39086145 (19085 Meg), flag 80 (active)
beg: cyl 1023/ head 255/ sector 63;
end: cyl 1023/ head 254/ sector 63
The data for partition 4 is:
<UNUSED>
With the
-p option the output is:
Code:
# fdisk -p ad0
# /dev/ad0
g c4961616 h1 s63
p 1 0xa6 63 78156162
p 2 0xa5 78156225 78140160
p 3 0xa5 156296385 39086145
a 3
The
g describes the geometry of
4961616 cylinders, 1 head and 63 sectors. Actually FreeBSD sees this differently then OpenBSD, but anyway
The first
p line says the first slice has an ID of A6, which is OpenBSD, defines the slice to start at sector 63 with a size of 78156162 sectors.
Slice 2 with id A5 starts at 78156225 and it's size is 78140160.
Something similar for the 3rd slice.
The last line
a 3 means that the 3rd slice is active, or in other words that this slice should be used when the computer is booted.
Although this configuration file has been derived from an existing MBR it could be used to configure another hard disk.
Redirect the output to file first:
Code:
# fdisk -p ad0 >fdisk-mbr.conf
After editing you could initialize a second disk in the system with:
Code:
# fdisk -f fdisk-mbr.conf -iv ad2
Actually it is better to use the
-t option to preview or test what the result would be
Code:
# fdisk -f fdisk-mbr.conf -ivt ad2
******* Working on device /dev/ad2 *******
fdisk: WARNING line 2: number of cylinders (4961616) may be out-of-range
(must be within 1-1024 for normal BIOS operation, unless the entire disk
is dedicated to FreeBSD)
parameters extracted from in-core disklabel are:
cylinders=4961616 heads=1 sectors/track=63 (63 blks/cyl)
Figures below won't work with BIOS for partitions not in cyl 1
parameters to be used for BIOS calculations are:
cylinders=4961616 heads=1 sectors/track=63 (63 blks/cyl)
Information from DOS bootblock is:
1: sysid 166 (0xa6),(OpenBSD)
start 63, size 78156162 (38162 Meg), flag 0
beg: cyl 1/ head 0/ sector 1;
end: cyl 510/ head 0/ sector 63
2: sysid 165 (0xa5),(FreeBSD/NetBSD/386BSD)
start 78156225, size 78140160 (38154 Meg), flag 0
beg: cyl 511/ head 0/ sector 1;
end: cyl 766/ head 0/ sector 63
3: sysid 165 (0xa5),(FreeBSD/NetBSD/386BSD)
start 156296385, size 39086145 (19085 Meg), flag 80 (active)
beg: cyl 767/ head 0/ sector 1;
end: cyl 637/ head 0/ sector 63
4: <UNUSED>
In my next post I will give you an example to rewrite this disk to 1 big MBR partition.
Because FreeBSD has a long tradition of interpreting disk geometry wrongly,I first have to reboot this machine in OpenBSD to check the correct geometry.
<rant>
I really don't understand why a small BSD project like OpenBSD has no problems with disk geometry, while giant FreeBSD still hasn't figured out to correctly deal with disk geometry. For a FreeBSD install, I always have to rely on an OpenBSD install disk.
</rant>