Using fdisk During an Install


For this example, I'm dividing a 20GB IDE hard drive between Windows XP and OpenBSD. The first 7GB of the hard drive hold a standard install of Windows XP, on a FAT32 file system. I want to put an 8GB OpenBSD install immediately after that. Prepare your hardware as you normally would, and boot off your OpenBSD installation disk. The install process is identical up until the point you see the disk usage menu.

 Available disks are: sd0 sd1 wd0. Which one is the root disk? (or done) [done] wd0 Do you want to use *all* of wd0 for OpenBSD? [no] 

We don't want to use the whole hard drive for OpenBSD, so take the default. This brings up a whole new tool, OpenBSD's interactive fdisk(8).

Reading MBR Partitions

After a few instructions, the installer will fire up fdisk(8) and automatically print out your partitioning from the Master Boot Record. The top of fdisk's output contains some basic disk geometry information.

 Disk: wd0    geometry: 1 2438/ 2 255/3 63 [ 4 39166470 Sectors] 

This line describes what fdisk(8) believes is the disk geometry in the number of cylinders, heads, and sectors a disk has. According to fdisk(8), this disk has 1 2438 cylinders (numbered 0 through 2,437), 2 255 heads (numbered 0 through 254), and 3 63 sectors per cylinder. If you compare this information to what the physical label on the hard drive says, it almost certainly won't match. That's all right — it's just been translated. One interesting thing to note is that fdisk(8) reports that this hard drive has the same 4 total number of sectors as every other tool reports, however.

A little beneath that, you get a table describing the MBR partitions themselves.

      Starting     Ending      LBA Info: #: id  C  H  S -  C  H  S [    start:    size   ] ------------------------------------------------------------------------ * 1 0: 2 0B 3 0 4 1 5 1 - 6 891 7 254 8 63 [   63:   14329917 ] 9 Win95 FAT-32     1:   00 0  0  0 -   0   0 0 [       0:     0 ] unused     2:   00 0  0  0 -   0   0 0 [       0:     0 ] unused     3:   00 0  0  0 -   0   0 0 [       0:     0 ] unused 

This isn't nearly as confusing as it looks at first glance. The first column gives the 1 MBR partition number, between 0 and 3. We then see the 2 Partition ID. This is a unique hex number used to identify the type of file system on the partition. Partition ID 0x0B represents FAT32.

fdisk then prints the 2 cylinder, 3 head, and 5 sector where this partition begins. The first partition on this disk begins on cylinder 0, head 1, sector 1 — the beginning of the disk. [1]

The next three columns show the cylinder, head, and sector where this partition ends. Compare these numbers to the total number of cylinders, heads, and sectors in the drive. This disk has 2,438 cylinders, of which we are using 6 892. Within cylinder number 891, we are using up through head 7 254 (all of the heads) and 8 sector 63 (all of the sectors). This Windows partition completely fills the first 2,438 cylinders. We say that such a partition ends on a cylinder boundary. All of your partitions should begin and end on a cylinder boundary.

At the end of the line, we have the 8 partition type in clear English. We could get this information by looking up partition ID 0x0B in a table, but it's certainly convenient to print it here.

Finally, fdisk presents a command prompt.

 fdisk: 1> 

We want to create a new MBR partition, immediately following the existing FAT32 partition.

Creating MBR Partitions

Actually entering the values for a new MBR is easy enough, once you know which keys to press. And OpenBSD's online help (available by entering a question mark) is clear enough on telling you which keys to press. Figuring out which numbers you want to enter is the hard part! To create a new partition, we have to tell fdisk(8) where the partition starts, where it ends, and what sort of partition it is. Let's tackle the easy one first: the partition type.

OpenBSD Partition Type

All OpenBSD partitions have a partition ID of A6. You can install OpenBSD on partitions of other partition IDs, but you might have some problems with doing that and have to hack around some assumptions in the operating system. Don't do it.

Partition Beginning

We know that the previous partition ends at the end of cylinder number 891. Our new partition should begin at the beginning of cylinder 892. This would be head 0, sector 1, cylinder 892.

Partition Ending

Our new partition should end on a cylinder boundary. This means that it will end on some cylinder, head 254, sector 63. But which cylinder?

Here, you have to resort to some basic math. No, stop screaming; it isn't that bad: Just get out your calculator. This hard drive has 2,591 cylinders and can hold about 20GB, or 20,000MB. Each cylinder holds roughly the same amount of data. 20,000MB divided by 2591 cylinders equals a little over 7.719MB/cylinder. Dividing the desired partition size in megabytes by the actual MB/cylinder ratio shows that we need 1,036 cylinders for OpenBSD. The first partition goes through partition 891. 891 + 1036 = 1,927, so our OpenBSD partition will end on cylinder 1,927.

Editing a MBR Partition

Armed with this information, we can create a new OpenBSD partition. Enter "edit" and the number of the partition you want to edit.

 fdisk: 1>e 1 Partition id ('0' to disable) [0 - FF]: [0] (? for help) A6 1 Do you wish to edit in CHS mode? [n] y 2 

First enter the 1 partition type, A6 for OpenBSD. If you're curious, you can enter a question mark and see a list of the myriad of partition types OpenBSD's fdisk(8) recognizes. fdisk(8) will then ask you if you want to edit the MBR partition table in CHS (cylinder/head/sector) mode. If you don't want to use CHS, you'll have to figure out which sector your first cylinder starts on and your last cylinder ends on. You don't want to do that. Enter "y" 2.

You'll then be prompted for the starting and ending cylinder information.

 BIOS Starting cylinder [0 - 2437]: [0] 892 BIOS Starting head [0 - 254]: [0] 0 BIOS Starting sector [1 - 63]: [0] 1 BIOS Ending cylinder [0 - 2437]: [0] 1927 BIOS Ending head [0 - 254]: [0] 254 BIOS Ending sector [1 - 63]: [0] 63 fdisk:*1> 

Note that the fdisk prompt has changed and now displays an asterisk. This means that you have changed the MBR partition and that your changes have not yet been saved to the disk. You could type "exit" now, and fdisk would quit without saving your changes. That wouldn't help us install OpenBSD, but you could do that if you made an error and didn't know how to recover.

Once you have created an OpenBSD partition, go back and view the MBR partition table with the "print" command.

 fdisk:*1> print Disk: wd0   geometry: 2438/255/63 [39166470 Sectors] Offset: 0   Signature: 0xAA55      Starting   Ending    LBA Info:  #: id  C  H S -  C  H S [   start:   size  ] ------------------------------------------------------------------------ *0: 0B  0  1 1 - 891 254 63 [    63:  14329917 ] Win95 FAT-32  1: A6 892  0 1 - 1927 254 63 [ 14329980:  16643340 ] OpenBSD  2: 00  0  0 0 -  0  0 0 [     0:      0 ] unused  3: 00  0  0 0 -  0  0 0 [     0:      0 ] unused fdisk:*1> 

The new OpenBSD partition shows up! Double-check your work, and make sure this is what you want the system partitioning to look like.

Set Active Partition

One of your partitions needs to be marked "active," meaning that when the system boots the BIOS will hand control of the system over to the operating system on that partition. (We'll use boot loaders to get around this later, but for now you need to use it.) Set your OpenBSD partition to be active during the install, so you can boot into OpenBSD after the install and make sure you actually have a working system before proceeding. Use the fdisk command "flag" and a partition number to mark a partition as active.

 fdisk: 1> flag 1 Partition 1 marked active. fdisk: *1> 

If your OpenBSD partition is not partition 1, enter the proper partition number.

Completing fdisk

Once you are satisfied with your fdisk configuration, enter "quit" to leave fdisk(8) and write your changes to the MBR.

 > quit Writing current MBR to disk. ... 

fdisk will print out your MBR partition information one last time, and then the install program proceeds to the disklabel section.

[1]Cylinder 0, head 0, sector 1 is the Master Boot Record itself.




Absolute Openbsd(c) Unix for the Practical Paranoid
Absolute OpenBSD: Unix for the Practical Paranoid
ISBN: 1886411999
EAN: 2147483647
Year: 2005
Pages: 298

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net