Custom Disk Layout

If you have multiple hard disks in a system, or if you want a different partition layout than the default, you must manually edit your disk layout.

The installer partitions one disk at a time, and you can’t easily bounce between multiple disks. To successfully use multiple disks, decide on your partitioning scheme before you start the installation, and write down exactly which partitions you want on which disks as specifically as possible.

My system has two 50GB hard disks. I plan to divide the disks like this:

  • Disk 1 . 1GB /, 1.2GB swap, 5GB /tmp, 1GB /usr/X11R6, 2GB /usr/src, 2GB /usr/obj, and everything else /home

  • Disk 2 . 1GB /altroot, 1.2GB swap, 6GB /var, 10GB /usr/local, and everything else /var/postgresql

This layout includes all of the standard OpenBSD partitions, plus a few additions: I’ve increased some partition sizes above the installer-generated defaults, and I’ve added an extra swap partition on the second hard drive. OpenBSD doesn’t include a separate /var/postgresql partition, but I’ve added one because I want my database data on its own partition. (We’ll discuss the /altroot partition in Chapter 9.)

The installer runs as usual until you get to the disk portion.

Available disks are: sd0 sd1.
Which one is the root disk? (or 'done') [sd0]

By default, the installer puts the root partition on the first hard drive, sd0. I’ll use this disk for the root partition and use the entire disk for OpenBSD.

The installer then presents a list of automatically generated disklabel partitions. We don’t want to use these partitions; we want to create our own from scratch.

Use (A)uto layout, (E)dit auto layout, or create (C)ustom layout? [a] c

We want a custom layout, so enter c.

The installer should now drop us to the disklabel(8) command prompt, indicated here by the > symbol:

You will now create an OpenBSD disklabel inside the OpenBSD MBR
partition. The disklabel defines how OpenBSD splits up the MBR partition
into OpenBSD partitions in which filesystems and swap space are created.
You must provide each filesystem's mountpoint in this program.
The offsets used in the disklabel are ABSOLUTE, i.e. relative to the
start of the disk, NOT the start of the OpenBSD MBR partition.
Label editor (enter '?' for help at any prompt)
>

We can now use the interactive disklabel editor to create OpenBSD partitions within the MBR partition, as discussed in the following sections.

Viewing Disklabels

The p command prints the partition’s existing disklabel:

> p
OpenBSD area: 64-104856255; size: 104856191; free: 32
#                size           offset  fstype [fsize bsize  cpg]
  a:          2104448               64  4.2BSD   2048 16384    1
  b:          2506143          2104512    swap                  
  c:        104857600                0  unused
  d:         10490432          4610656  4.2BSD   2048 16384    1
…
>

This is exactly the same information discussed in Understanding Disklabels. This hard drive previously had an OpenBSD installation, and the disklabel has those old partitions.

To display partition sizes in megabytes, enter p m:

> p m
OpenBSD area: 64-104856255; size: 51199.3M; free: 0.0M
#                size           offset  fstype [fsize bsize  cpg]
  a:          1027.6M               64  4.2BSD   2048 16384    1
  b:          1223.7M          2104512    swap                  
  c:         51200.0M                0  unused
  d:          5122.3M          4610656  4.2BSD   2048 16384    1
…

You can also display partition sizes in gigabytes by entering p g:

> p g
OpenBSD area: 64-104856255; size: 50.0G; free: 0.0G
#                size           offset  fstype [fsize bsize  cpg]
  a:             1.0G               64  4.2BSD   2048 16384    1
  b:             1.2G          2104512    swap                   
  c:            50.0G                0  unused
  d:             5.0G          4610656  4.2BSD   2048 16384    1
…

Choose the unit of measurement best suited to your disk.

Deleting Partitions

Use the d command to delete partitions:

> d
partition to delete: [] a
>

That’s it. Tell disklabel to delete a partition on this disk, give it the partition letter, and it’s gone. But beware: disklabel won’t ask you to verify your choice, so be sure to choose the correct partition.

Erasing Existing Disklabels

You could manually delete all partitions, but it’s much easier to zero out the existing disklabel with the z command:

> z
> p
OpenBSD area: 64-104856255; size: 104856191; free: 104856191
#                size           offset  fstype [fsize bsize  cpg]
  c:        104857600                0  unused
>

Here, we tell disklabel to erase the partition table with z, and then print the partition table with p. The output should be an empty disklabel, because the c disklabel partition represents the entire MBR partition. We can now create our desired partitions.

Creating Disklabel Partitions

This first disk needs the following partitions:

  • 1GB / (root)

  • 1.2GB swap

  • 5GB /tmp

  • 1GB /usr/X11R6

  • 2GB /usr/src

  • 2GB /usr/obj

  • Everything else /home

By default, disklabel creates partitions in order. You can manually create partitions in any order you want, but you’ll need to track sectors and cylinders in order to figure out where each partition should begin and end. I strongly recommend creating partitions in order and letting disklabel do the math.

Use the a command to create a partition beginning with /:

  > a
1 partition: [a]
2 offset: [64]
3 size: [104856191] 1g
4 Rounding size to cylinder (16065 sectors): 2104451
5 FS type: [4.2BSD]
6 mount point: [none] /
7 Rounding size to bsize (32 sectors): 2104448
  >

By default, at 1, disklabel offers the next free letter for your new partition. The first partition on the disk is a. Press ENTER to accept it.

The offset for a disklabel partition is the number of sectors from the beginning of the disk where the partition starts, not from the beginning of the MBR partition, which is the actual beginning of the disk. The first 63 sectors of a disk, numbers 0 through 62, contain the MBR. We could use sector 63, but OpenBSD starts on sector 64 to better align with memory cells in solid-state disks. At 2, you can see that disklabel offers 64 as the default offset.

The size at 3 is the number of sectors the partition uses. By default, disklabel offers all the remaining space on the disk, but I want a 1GB root partition. I could do the math to figure out how many sectors are in a gigabyte, but I’m lazy, so I use an abbreviation instead. The disklabel command recognizes the following abbreviations for sizes:

  • b for bytes

  • c for cylinders

  • k for kilobytes

  • m for megabytes

  • g for gigabytes

All partitions must end on a cylinder boundary, so disklabel figures out the closest boundary and, at 4, sizes my root partition to match. My root partition will be pretty close to 1GB.

The FS type at 5 shows the filesystem used on this partition. For an OpenBSD disk, every data partition needs type 4.2BSD. Your swap partition will be of type swap.

The mount point at 6 is where you want this partition mounted. By default, disklabel doesn’t assign a mount point because it can’t guess what you want. Enter the partition’s mount point.

Partitions must end on a cylinder boundary, but should end with a whole block for the filesystem. The disklabel command 7 adjusts the partition size again, based on the standard block size of the filesystem.

Our next partition is swap space.

  > a
1 partition: [b]
2 offset: [2104512]
3 size: [102751743] 1.2g
4 Rounding size to cylinder (16065 sectors): 2506143
5 FS type: [swap]
  >

The disklabel command assumes at 1 that you’re using the next partition letter, b. It automatically calculates the offset at 2, which is the next free sector after the previous partition. I use decimal fractions at 3 to set the size (I could alternatively enter 1200m). The size at 4 is rounded to the nearest cylinder boundary. Finally, disklabel knows that partition b is traditionally swap space, so it offers 5 that as the default. Swap space doesn’t need a mount point, and it doesn’t have a block size.

We can create the remaining partitions in the same way. Creating the last partition, /home, is even easier:

  > a
  partition: [h]
  offset: [25575456]
1 size: [79280799]
  FS type: [4.2BSD]
  mount point: [none] /home
  Rounding size to bsize (32 sectors): 79280768
  >

As you can see at 1, we don’t need to track how much empty disk space remains, because disklabel does that for us. Press ENTER to swallow it all. Now is your chance to leave empty space on your disk.

Now that you’ve created all your partitions, print the disklabel (with the p command, as described earlier in the chapter) to double-check your work.

Writing the New Disklabel

When you’re satisfied with your partition scheme, enter q to write your disklabel to disk:

> q
Write new label?: [y] y
/dev/rsd0a: 1027.6MB in 2104448 sectors of 512 bytes
…

disklabel gives you one last chance to change your mind. Once you write a new disklabel, recovering any data on the disk becomes extremely difficult, so be sure you backed up any vital data on this disk before starting the installation. (This is a good time to make sure that you didn’t microwave your backup.)

Adding More Disks

After you partition your first disk, the installer offers you a chance to partition any other hard drives:

Available disks are: sd1.
Which one do you wish to initialize? (or 'done') [done] sd1

The default is to not partition any other disks. If you choose another disk, you’ll need to create MBR partitions and then disklabel partitions.

Once all of your hard drives have been formatted, you’ll return to installing the file sets.

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

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