OpenBSDAddDiskSpace

How to add disk space under Open BSD

This is a server on which a brand new 1TB disk has been recently added.

This is simple, but better safe than sorry:

$ dmesg | grep -i ^wd
wd0 at pciide0 channel 0 drive 0: <SAMSUNG HD322GJ>
wd0: 16-sector PIO, LBA48, 305245MB, 625142448 sectors
wd0(pciide0:0:0): using PIO mode 4, Ultra-DMA mode 6
wd1 at pciide0 channel 1 drive 0: <WDC WD10EALX-009BA0>
wd1: 16-sector PIO, LBA48, 953869MB, 1953525168 sectors
wd1(pciide0:1:0): using PIO mode 4, Ultra-DMA mode 6

In the example shown above, wd0 is the original system disk of the server (around 300GB) and wd1 is the new disk, around 953GB. This is the disk we are going to configure.

(This can also be applied to the other BSD, such as: Free BSD, Net BSD, etc... since they all use the same system)

The main difference between Open BSD and a Linux distribution is that Linux only has one "level" of partitioning, while Open BSD offers two: partitions and "slices".

I will just define slices as sub-partitions, for the sake of simplicity.

One big difference is that Open BSD is that slices are (for Winchester "wd" hard disks) numbered with letters and that disks themselves are identified by numbers, starting with 0. The wd1 disk, introduced above, is therefore the second disk installed in the server, while the first is wd0. The very first slice (or sub-partition) will be: wd1a, while a Linux system would name it as: hda1 (disk a, partition 1).

The other difference is that, on a system disk, Open BSD demands that slice a should be the root filesystem (/), slice b should be the swap / virtual memory filesystem, and slice c, for historical reasons, always represent the entire disk. A disk should therefore always have at least a partition and a slice, the c slice, that cannot be deleted or modified.

If this seems a bit complicated, I hope it will seem clearer at the end of this small how to!

This being explained, we are now going to create, in that specific order: an Open BSD partition on the new disk, then a slice in that partition, format the filesystem and, finally mount the newly created disk space on our system.

To create and Open BSD parition, one should use the fdisk program and its interactive mode. It is possible to use fdisk non-interactively, but this is beyond the scope of this short document.

To do this, type the following as root:

# fdisk -e wd1
fdisk: 1>

The -e option indicates that fdisk should function in the interactive "editor" more. At the prompt, type ? to display the list of commands or help to display the man page:

fdisk: 1> ?
        help            Command help list        manual          Show entire OpenBSD man page for fdisk
        reinit          Re-initialize loaded MBR (to defaults)
        setpid          Set the identifier of a given table entry
        disk            Edit current drive stats
        edit            Edit given table entry
        flag            Flag given table entry as bootable
        update          Update machine code in loaded MBR
        select          Select extended partition table entry MBR
        swap            Swap two partition entries
        print           Print loaded MBR partition table
        write           Write loaded MBR to disk
        exit            Exit edit of current MBR, without saving changes
        quit            Quit edit of current MBR, saving current changes
        abort           Abort program without saving current changes

Let's now display the list of partitions on wd1 with the print command:

fdisk: 1> print
Disk: wd1       geometry: 121601/255/63 [1953525168 Sectors]
Offset: 0       Signature: 0xAA55
            Starting         Ending         LBA Info:
 #: id      C   H   S -      C   H   S [       start:        size ]
-------------------------------------------------------------------------------
*0: EE      0   0   2 - 121601  80  63 [           1:  1953525167 ] EFI GPT
 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

We can see in the example above 4 partitions, which is the standard for this disk type. They are the primary partitions.

Since wd1 is going to be used only for our Open BSD system, we are simply going to modify the type of the first partition (#0) in order to make it usable by the system. To do this, still using fdisk, we are going to use the command edit, as follows:

fdisk: 1> edit 0
            Starting         Ending         LBA Info:
 #: id      C   H   S -      C   H   S [       start:        size ]
-------------------------------------------------------------------------------
*0: EE      0   0   2 - 121601  80  63 [           1:  1953525167 ] EFI GPT
Partition id ('0' to disable) [0 - FF]: [EE] (? for help) ?
Choose from the following Partition id values:
00 unused         20 Willowsoft     66 NetWare 386    A9 NetBSD
01 DOS FAT-12     24 NEC DOS        67 Novell         AB MacOS X boot
02 XENIX /        27 Win Recovery   68 Novell         AF MacOS X HFS+
03 XENIX /usr     38 Theos          69 Novell         B7 BSDI filesy*
04 DOS FAT-16     39 Plan 9         70 DiskSecure     B8 BSDI swap
05 Extended DOS   40 VENIX 286      75 PCIX           BF Solaris
06 DOS > 32MB     41 Lin/Minux DR   80 Minix (old)    C0 CTOS
07 NTFS           42 LinuxSwap DR   81 Minix (new)    C1 DRDOSs FAT12
08 AIX fs         43 Linux DR       82 Linux swap     C4 DRDOSs < 32M
09 AIX/Coherent   4D QNX 4.2 Pri    83 Linux files*   C6 DRDOSs >=32M
0A OS/2 Bootmgr   4E QNX 4.2 Sec    84 OS/2 hidden    C7 HPFS Disbled
0B Win95 FAT-32   4F QNX 4.2 Ter    85 Linux ext.     DB CPM/C.DOS/C*
0C Win95 FAT32L   50 DM             86 NT FAT VS      DE Dell Maint
0E DOS FAT-16     51 DM             87 NTFS VS        E1 SpeedStor
0F Extended LBA   52 CP/M or SysV   8E Linux LVM      E3 SpeedStor
10 OPUS           53 DM             93 Amoeba FS      E4 SpeedStor
11 OS/2 hidden    54 Ontrack        94 Amoeba BBT     EB BeOS/i386
12 Compaq Diag.   55 EZ-Drive       99 Mylex          EE EFI GPT
14 OS/2 hidden    56 Golden Bow     9F BSDI           EF EFI Sys
16 OS/2 hidden    5C Priam          A0 NotebookSave   F1 SpeedStor
17 OS/2 hidden    61 SpeedStor      A5 FreeBSD        F2 DOS 3.3+ Sec
18 AST swap       63 ISC, HURD, *   A6 OpenBSD        F4 SpeedStor
19 Willowtech     64 NetWare 2.xx   A7 NEXTSTEP       FF Xenix BBT
1C ThinkPad Rec   65 NetWare 3.xx   A8 MacOS X
Partition id ('0' to disable) [0 - FF]: [EE] (? for help) A6
Do you wish to edit in CHS mode? [n]
Partition offset: [1]
Partition size: [1953525167]

You can see above that the configuration of the disk itself is not going to be modified, since we take the default values for each question. The only change is to assign the value A6 (= Open BSD) to the #0 partition of disk wd1.

We then check the result of this operation by displaying again the disk configuration:

fdisk:*1> print
Disk: wd1       geometry: 121601/255/63 [1953525168 Sectors]
Offset: 0       Signature: 0xAA55
            Starting         Ending         LBA Info:
 #: id      C   H   S -      C   H   S [       start:        size ]
-------------------------------------------------------------------------------
*0: A6      0   0   2 - 121601  80  63 [           1:  1953525167 ] 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

You can see above that partition 0 is now configured as an Open BSD partition.

This configuration should now be written to the disk itself with:

fdisk:*1> quit
Writing MBR at offset 0.

The fdisk command confirms that the configuration is now written in the MBR (Master Boot Record), which makes it permanent. Since the partition is now configured correctly, let's proceed with the slice...

To configure the slice(s) of a partition, we need to use the disklabel command. This command is slightly less easy to use than fdisk since it only accepts letters, and not full commands.

In the same way we used fdisk, we are going to use disklabel in interactive mode with the -E option and display all the possible commands by typing ? at the prompt:

# disklabel -E wd1
Label editor (enter '?' for help at any prompt)
> ?
Available commands:
 ? | h    - show help                 n [part] - set mount point
 A        - auto partition all space  p [unit] - print partitions
 a [part] - add partition             q        - quit & save changes
 b        - set OpenBSD boundaries    R [part] - resize auto allocated partition
 c [part] - change partition size     r        - display free space
 D        - reset label to default    s [path] - save label to file
 d [part] - delete partition          U        - undo all changes
 e        - edit drive parameters     u        - undo last change
 g [d|u]  - [d]isk or [u]ser geometry w        - write label to disk
 i        - modify disklabel UID      X        - toggle expert mode
 l [unit] - print disk label header   x        - exit & lose changes
 M        - disklabel(8) man page     z        - delete all partitions
 m [part] - modify partition
  
Suffixes can be used to indicate units other than sectors:
 'b' (bytes), 'k' (kilobytes), 'm' (megabytes), 'g' (gigabytes) 't' (terabytes)
 'c' (cylinders), '%' (% of total disk), '&' (% of free space).
Values in non-sector units are truncated to the nearest cylinder boundary.

Let's start by listing all the slices in partition wit the p (print) command:

> p
OpenBSD area: 1-1953525168; size: 1953525167; free: 1953525167
#                size           offset  fstype [fsize bsize  cpg]
  c:       1953525168                0  unused

We can see above that there is, indeed a c slice: as noted above, this corresponds to the entire partition.

Since this is not a system disk, we are now going to create an a slice, with a size of around 250GB, using the command a (add), followed by the letter identifying the slice:

> a a
offset: [1]
size: [1953525167] 255G
Rounding size to cylinder (16065 sectors): 534787784
FS type: [4.2BSD]
Rounding size to bsize (64 sectors): 534787775

Please note that he default values were, again, accepted every time (by pressing Enter) except for the size (255G). The disklabel command accepts values followed by letters (K, M, G) to indicate the total size of a slice.

Let's now display the result of our command with the p (print) command:

> p
OpenBSD area: 1-1953525168; size: 1953525167; free: 1418737392
#                size           offset  fstype [fsize bsize  cpg]
  a:        534787775                1  4.2BSD   4096 32768    1
  c:       1953525168                0  unused

Two slices can be ssen above: the newly created a, and, of course the c slice.

Let's now write this configuration on the disk with the command w (write) and quit disklabel with x:

> w
> x

Our new slice is now almost ready to be used...

To create the filesystem, use the command newfs and supply the disk and partition, as well as the type of filesystem to be used.

Ergo:

# newfs -t ffs wd1a
/dev/rwd1a: 261126.8MB in 534787768 sectors of 512 bytes
321 cylinder groups of 814.44MB, 26062 blocks, 52224 inodes each
super-block backups (for fsck -b #) at:
 64, 1668032, 3336000, 5003968, 6671936, 8339904, 10007872, 11675840, 13343808, 15011776, 
16679744, 18347712, 20015680, 21683648, 23351616, 25019584, 26687552, 28355520, 30023488, 
31691456, ... etc ...

Please note in the example above that the filesystem type is FFS (Fast File System), which is the BSD standard, as well as the target disk, which is wd1a. After a few minutes of work, the filesystem is ready.

Let's create first the directory where the filesystem will be mounted:

# mkdir /backup
# ls -alhF /
total 83580
drwxr-xr-x  16 root  wheel   512B Nov 28 22:59 ./
drwxr-xr-x  16 root  wheel   512B Nov 28 22:59 ../
-rw-r--r--   1 root  wheel   578B Mar  2  2011 .cshrc
-rw-r--r--   1 root  wheel   468B Mar  2  2011 .profile
drwxr-xr-x   2 root  wheel   512B Aug  1 17:45 altroot/
drwxr-xr-x   2 root  wheel   512B Nov 28 22:58 backup/
drwxr-xr-x   2 root  wheel   1.0K Aug  1 17:48 bin/
-rw-r--r--   1 root  wheel  46.2K Aug 30  2011 boot
-rw-r--r--   1 root  wheel   8.6M Nov 25 17:16 bsd
... etc ...

We can now mount this filesystem in the directory:

# mount -v -t ffs /dev/wd1a /backup
/dev/wd1a on /backup type ffs (rw, local, ctime=Wed Nov 28 22:59:21 2012)

And check that it appears correctly in the list of filesystems:

# df -h
Filesystem     Size    Used   Avail Capacity  Mounted on
/dev/wd0a      7.9G   65.9M    7.4G     1%    /
/dev/wd0i     15.7G    1.0G   14.0G     7%    /home
/dev/wd0f      7.9G    8.0M    7.5G     0%    /tmp
/dev/wd0d      7.9G    1.2G    6.2G    17%    /usr
/dev/wd0h     15.7G    1.8G   13.1G    12%    /usr/local
/dev/wd0j      7.9G    531M    7.0G     7%    /usr/ports
/dev/wd0g      7.9G    821M    6.7G    11%    /usr/src
/dev/wd0e      7.9G    783M    6.7G    10%    /var
/dev/wd0k     29.5G   10.4G   17.7G    37%    /usr/local/news
/dev/wd0l      171G    4.0K    162G     0%    /data
/dev/wd1a      253G    4.0K    240G     0%    /backup

We now need to modify the /etc/fstab configuration file to make the configuration permanent:

# cat /etc/fstab                                                                                                                                                                              
/dev/wd0a / ffs rw,softdep 1 1
/dev/wd0i /home ffs rw,softdep,nodev,nosuid 1 2
/dev/wd0f /tmp ffs rw,softdep,nodev,nosuid 1 2
/dev/wd0d /usr ffs rw,softdep,nodev 1 2
/dev/wd0h /usr/local ffs rw,softdep,nodev 1 2
/dev/wd0j /usr/ports ffs rw,softdep,nodev,nosuid 1 2
/dev/wd0g /usr/src ffs rw,softdep,nodev,nosuid 1 2
/dev/wd0e /var ffs rw,softdep,nodev,nosuid 1 2
/dev/wd0k /usr/local/news ffs rw,softdep,nodev 1 2
/dev/wd0l /data ffs rw,softdep,nodev,nosuid 1 2
/dev/wd1a /backup ffs rw,softdep,nodev,nosuid 1 2

In the example above we have also activated the softdep option of FFS, which provides filesystem journaling and better performances.

Once the /etc/fstab configuration file has been modified, all that is needed is to unmount and re-mount the filesystem (/backup, in the example above) for the configuration to be completed and made permanent.

See Also:

The Open BSD documentation is absolutely top notch, so please always refer to it before doing anything: