Extending var partition on OpenBSD

We use OpenBSD default installation for our LDAP server. It stores all of it’s records in var partition, which was significantly smalled then our home partition that we didn’t use at all.
I decided to increase the disk size on our ProxMox virtualisation manager, but the VM that has OpenBSD needed some configuring to use that newly added space.

So I ssh-ed into the VM and typed “reboot” and then went to the proxmox web interface and selected the VM console to try to catch it during the boot process.
Since I needed to use uppercase letters, I couldn’t use tor onion service that I usualy use to connect to the web interface. Apperently this is an issue with some “privacy.fingerprintingProtection” option in the “about:config” of the tor browser, but I couldn’t get it disabled properly.
Instead I used ssh -L 1234:[ip addr of proxmox server]:8006, then I used firefox to connect to https://localhost:1234 and used it from there.

I stopped the VM fully over ssh with “halt -p” command and turned it on over the proxmox web interface when I was ready.

I interupted the boot process by quickly pressing the “b” key when it said:

boot>

and continued typing the full boot command I needed:

boot> boot -s

The -s means single user mode, it doesn’t mount any partitions except root and is useful when dealing with these partiotions that are used by various services on the system.

Apperently you can also increase the boot wait time here to 30 seconds by adding"set timeout 30" to the /etc/boot.cfg file (you need to create it first).

Once the system boots and you get the console, you can type:
“disklabel -E sd0”

This will open up interface for editing the partitions on the sd0 disk.
You can press “p” to show all the existing partitions.

I read somewhere that you needed to reinitilize the disk first by pressing “b” and just continue with the default values by pressing the enter key once and then “*” sign and enter again. This apperently starts using the whole disk with the new added space, but it might not be necessary.

Now since var partition is not the last partition on the disk by deafult (home is the last) then we will need to create a new partition at the end and move var there.
To do that press “a” in the disklabel main interface and go with the default values of all the space left on the disk and the BSD filesystem all the partitions use.

By pressing “p” you can see the result again and should see the new partition added. Should be named “sd0l” if you have the default number of partitions.

Remember in OpenBSD partitions are not named by appending numbers at the end of the disk name, but by adding letters to it instead. The “c” partition is a special one, it means the whole disk, so that if you want to write something to the whole disk you need to write sd0c instead of just sd0 on linux. This helps with typos during dangerous partitioning changes, where you can forget the last letter of your partition and overwrite the whole disk.

To save your changes type “w”. The “q” to exit.

Now all we need to do is copy the var partition to the new one with “dd”. By default var partition is at “e”, but you can check in /etc/fstab.

dd if=/dev/sd0e of=/dev/sd0l bs=4M

After you copied all contents of var to the new partition, you can grow the filesystem on it, by typing:

growfs /dev/sd0l

That is it, just need to change /etc/fstab now so that it uses the new var partition.
Vi doesn’t work for some reason from this terminal, so I used sed, so that I dont do it over ssh and risk some new changes to var while I transfer to the new partition.

For sed I simply used the last character of the disk uid I saw in fstab. Luckly cat still works, so by running “cat /etc/fstab” I saw what it says in the file.
For me it was a character 9, so I typed first:

sed ‘s/9.e/9.l/g’

To see if everything is correct, then I added “-i” argument to write the changes to the file.

sed -i ‘s/9.e/9.l/g’

You can probably just use the dot characted to find the right e in the file, but I didn’t want to mess with regex. It would probably look like this:

sed -i ‘s/[.]e/[.]l/g’

That is all, now type “reboot” and all is done.