2023-02-12

OpenBSD Mastery.


Running an OpenBSD server is easy and requires minimal maintenance. This article presents lessons learned during my journey.

Extend your storage when you are running out of space

When your server is running out of space you could extend it by adding a new harddisk and moving the data eating up the space to the fresh space. In this case /var/vmail is the folder keeping all mails of the mail server. The steps listed here describe how to setup the new harddisk and use the new space for /var/vmail.

Identify the newly added harddisk

# sysctl hw.disknames
hw.disknames=cd0:,sd0:9db28a39ced0fdfa,sd1:,sd2:083cefab42727759,fd0:

sd1 has no DUID yet. So this is the newly added harddisk. The DUID will be assigned as soon as the first disklabel is created.

Create a GPT partition table without a boot partition

# fdisk -g sd1

Create a disklabel partition a using the whole disk space

# disklabel -E sd1
Label editor (enter '?' for help at any prompt)
sd1> p
OpenBSD area: 64-41943007; size: 41942943; free: 41942943
#                size           offset  fstype [fsize bsize   cpg]
 c:         41943040                0  unused
sd1> a a
offset: [64]
size: [41942943]
FS type: [4.2BSD]
sd1*> w
sd1> q

Typing disklabel sd1 or sysctl hw.disknames will show up a DUID for our disk sd1:

# sysctl hw.disknames
hw.disknames=cd0:,sd0:9db28a39ced0fdfa,sd1:cf7a1c6c81dca676,sd2:083cefab42727759,fd0:

# disklabel sd1
# /dev/rsd1c:
type: SCSI
disk: SCSI disk
label: Volume
duid: cf7a1c6c81dca676
flags:
bytes/sector: 512
sectors/track: 63
tracks/cylinder: 255
sectors/cylinder: 16065
cylinders: 2610
total sectors: 41943040
boundstart: 64
boundend: 41943007

16 partitions:
#                size           offset  fstype [fsize bsize   cpg]
  a:         41942912               64  4.2BSD   2048 16384 12960
  c:         41943040                0  unused

Create a UFS filesystem on disklabel partition a

# newfs -q /dev/rsd1a

Moving data to the replacement partition

Mount the new disklabel partition temporarely on /mnt

# mount cf7a1c6c81dca676.a /mnt

Dublicate your data in the the new space

# tar -cf - -C /var/vmail . && tar xpf - -C /mnt

Delete the data from the old directory

# cd /var/vmail
# rm -rf *

Mount the new partition to the destination

# umount /mnt
# mount cf7a1c6c81dca676.a /var/vmail

Add new partition to fstab via DUID

083cefab42727759.b none swap sw
083cefab42727759.a / ffs rw,wxallowed 1 1
083cefab42727759.d /home ffs rw,nodev,nosuid 1 2
083cefab42727759.e /tmp ffs rw,nodev,nosuid 1 2
083cefab42727759.f /var ffs rw,nodev,nosuid 1 2
cf7a1c6c81dca676.a /var/vmail ffs rw,nodev,nosuid 1 2