MBR Partitions and fdisk(8)

Some hardware platforms have specific ideas about disk partitioning that differ from what OpenBSD expects. For example, the i386 and amd64 platforms expect to find MBR partitions on hard drives, and OpenBSD accommodates this quirk by putting its own disklabel partitions inside MBR partitions. We briefly touched on creating partitions during the installation process, but if you add hard drives to an existing system, you’ll need to edit the MBR partition table by hand using fdisk(8).

My particular test system has two hard drives: wd0 and wd1. I think that wd1 is completely blank but before I can use this drive, I need to verify that it is empty, and then create MBR partitions. While fdisk has all sorts of commands to edit disks, I find the simplest way is to use the interactive disk editor. Run fdisk -e and give it the device node for the new disk.

# fdisk -e wd1
Enter 'help' for information
fdisk: 1>

The editor is minimal, but lets you view, add, remove, and edit MBR partitions. If you forget the commands at any time, entering help will print out all the commands fdisk supports.

Viewing MBR Partitions

To see the MBR partitions on the current disk, enter print or p. Here’s an example:

fdisk: 1> print
Disk: wd1       geometry: 2088/255/63 [33554304 Sectors]
Offset: 0       Signature: 0x0
            Starting         Ending         LBA Info:
 #: id      C   H   S -      C   H   S [       start:        size ]
------------------------------------------------------------------------------
 0: 00      0   0   0 -      0   0   0 [           0:           0 ] unused
 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

The first line shows the disk geometry (as discussed in Chapter 2). Every value in this disk’s MBR table is set to 0, meaning that it has no configured partitions.

Adding and Removing Partitions

Say we want to create an MBR partition on this disk. I habitually use partition 0, but the OpenBSD installer usually uses partition 3. The specific number you pick doesn’t matter unless you want multiple MBR partitions on the disk.

To edit a partition, enter edit or e followed by the partition number. For example, to edit partition 0, enter the following:

  fdisk: 1> e 0
            Starting         Ending         LBA Info:
   #: id      C   H   S -      C   H   S [       start:        size ]
------------------------------------------------------------------------------
   0: 00      0   0   0 -      0   0   0 [           0:           0 ] unused
1 Partition id ('0' to disable)  [0 - FF]: [0] (? for help) a6
   Do you wish to edit in CHS mode? [n]
2 offset: [0]
3 size: [0] *

Warning

Conveniently, fdisk prints the current information on this MBR partition. Make sure it’s the partition you think it is before you muck it up.

First, at 1, set a partition ID. This is a label indicating what kind of filesystem will be on the disk. OpenBSD uses partition ID a6, so enter that.

The offset at 2 is the number of sectors from the beginning of the disk to the start of the partition. We want to use this entire disk for OpenBSD, so set it to 0.

Finally, the size at 3 is the number of sectors the MBR partition fills. There is no need to copy the number of sectors in the disk here; OpenBSD fdisk uses * to mean “all free space.”

Now print the MBR table again to check your work.

fdisk:*1> p
Disk: wd1       geometry: 2088/255/63 [33554304 Sectors]
Offset: 0       Signature: 0x0
            Starting         Ending         LBA Info:
 #: id      C   H   S -      C   H   S [       start:        size ]
------------------------------------------------------------------------------
 0: A6      0   0   1 -   2088 167  63 [           0:    33554304 ] OpenBSD
 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

Notice that the entry for partition 0 is type A6 and extends from cylinder 0, head 0, sector 1, to cylinder 2088, head 167, sector 63. It fills 33,554,304 sectors—the same as the number of sectors in the disk. This MBR partition fills the entire disk.

If you had recycled this disk from another operating system, it would probably have a partition already on it. To remove a partition, edit the partition and set its partition ID to 0.

Making a Partition Bootable

In order to boot from a hard drive, you’ll need to mark a partition as active. Use the flag command and a partition number to do this.

fdisk: 1> flag 0
Partition 0 marked active.

Include this hard drive in your BIOS boot order, and the computer should try to boot from it. Simply marking a partition as active doesn’t mean that the computer can boot from it; however, you will still need a kernel, boot loader, and all the other things that go into bootstrapping a computer.

To mark a partition as no longer active, delete and re-create it. (There is no unflag command.)

Exiting fdisk

Once you’re satisfied with your work, enter quit or q, and fdisk should write the new MBR table to disk and exit. If you changed your mind, and don’t want to make any changes, enter abort or exit, and fdisk should exit without saving changes to the MBR partition table.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.22.216.254