$_ BSDHowTo.ch
How To... Why not..? Scripts Patches RSS logo

How to increase the size of an iSCSI LUN

Last update: 2022-11-02

Introduction

Lately my private Nextcloud instance got short on disk space. The data is stored in an iSCSI LUN on a Synology Disk Station. Nextcloud runs on an OpenBSD server. In this how to I describe the steps I’ve taken to increase the size of the LUN.

Preparation

Make sure you have a backup of the iSCSI LUN and/or the data on it. If something goes wrong you might loose the whole LUN and all the data on it. As my LUN holds the data of my private Nextcloud instance I put Nextcloud into maintenance mode as a first step:

$ doas sed -i '/maintenance/s/false/true/' /var/www/nextcloud/config/config.php

After that I create a backup of the LUN using dump(8).

Bring the LUN offline

I highly recommend you to detach the LUN completely from the system it is mounted on. I’m not sure if iscsid(8) and the OpenBSD kernel could handle size increases of attached LUNs. The first step is to umount(8) the LUN:

$ doas umount /dev/sd1a

To cut the connection completely you must stop iscsid(8). Make sure you don’t have any other LUNs mounted before you do this.

$ doas pkill iscsid

Increase the size of the LUN

The first step is obvious: You must increase the size of the LUN on the storage system. How this is done depends on the storage system you are using. After that you must increase the size of the partition, the disk label and the file system.

After the increasing of the LUN size you must reconnect it to the initiator system. If you use hotplugd(8) to automatically mount the LUN once it attaches you should stop it first:

$ doas rcctl stop hotplugd

Now you can start iscsid(8). It will attached the re-sized LUN to your system:

$ doas rcctl start iscsid

The step is to increase the size of the OpenBSD partition on the re-sized LUN. The easiest way is to start fdisk(8) in interactive edit mode:

$ doas fdisk -e sd1
Enter 'help' for information
sd1: 1>

Enter p to print the current partition table:

Disk: sd1       geometry: 6527/255/63 [104857600 Sectors]
Offset: 0       Signature: 0xAA55
            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: A6      0   1   2 -   6527  21  22 [          64:    31457216 ] OpenBSD

Edit partition entry #3 with the following command:

sd1: 1> e 3
            Starting         Ending         LBA Info:
 #: id      C   H   S -      C   H   S [       start:        size ]
-------------------------------------------------------------------------------
*3: A6      0   1   2 -   6527  21  22 [          64:    31457216 ] OpenBSD
Partition id ('0' to disable) [01 - FF]: [A6] (? for help)
Do you wish to edit in CHS mode? [n]
Partition offset [0 - 104857599]: [64]
Partition size [1 - 104857536]: [31457216] 104857536
sd1:*1> q
$

Now you must adjust the disk label of the LUN. Start disklabel(8) in the interactive editor mode:

$ doas disklabel -E sd1
Label editor (enter '?' for help at any prompt)
sd1>

Enter p to print the current disk label:

OpenBSD area: 64-104857600; size: 104857536; free: 0
#                size           offset  fstype [fsize bsize   cpg]
  a:        104857536               64  4.2BSD   2048 16384 38128 # /var/www/nextcloud/data
  c:        104857600                0  unused
sd1>

In case the second number in OpenBSD area is smaller than the size of the entry c: you can increase the available area by using the b command like this:

sd1> b
Starting sector: [64]
Size ('*' for entire disk): [104857536] *

Now you can change the size of the partition a to the maximum:

sd1> c a
Partition a is currently 31457216 sectors in size, and can have a maximum
size of 104857536 sectors.
size: [31457216] 104857536 
sd1*> q
$

Last but not least you must extend the size of the file system on the partition. Use growfs(8) for this:

$ doas growfs /dev/sd1a

Bring the LUN online

Now that everything is increased it is time to bring the LUN online on the system. As growfs(8) marks your file system on the LUN dirty you first must run a fsck(8) on it:

$ doas fsck /dev/sd1a

You can mount the LUN again:

$ doas mount /var/www/nextcloud/data

Don’t forget to restart hotplugd(8) in case you have stopped it earlier:

$ doas rcctl start hotplugd

And revert any steps you have taken to prevent applications from accessing the LUN while it is gone. In my case this is to disable the maintenance mode of Nextcloud:

$ doas sed -i 'maintenance/s/true/false/' /var/www/nextcloud/config/config.php