How To Extend Disk Space on Next-/Owncloud Appliance

Kudos @knebb
Note: There is a video available which is based on this article.
Check the steps (these steps are valid for a Owncloud image downloaded just recently, some numbers might change in later or earlier editions); Nextcloud should be similar.

Step 1: Extend the HDD of the virtual machine (VM) itself

  1. Power off the VM
  2. Take a snapshot for rollback in case something goes wrong
  3. Edit Settings and extend from 50GB to the desired size
  4. Power on the VM

Step 2: Edit partition table

  1. Login on the command line as root
  2. fdisk /dev/sda
  3. Print current partition table, note the “start” values of /dev/sda2 and /dev/sda5
Command (m for help): p
Disk /dev/sda: 150 GiB, 161061273600 bytes, 314572800 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x1ed9986f

Device     Boot   Start       End   Sectors  Size Id Type
/dev/sda1  *       2048    999423    997376  487M 83 Linux
/dev/sda2       1001470 104855551 103854082 49,5G  5 Extended
/dev/sda5       1001472 104855551 103854080 49,5G 8e Linux LVM
  1. Delete (yes!) partition 5 and 2 (in that order!)
Command (m for help): d
Partition number (1,2,5, default 5): 5

Partition 5 has been deleted.

Command (m for help): d
Partition number (1,2, default 2): 2

Partition 2 has been deleted.
  1. Re-Create the logical partition/dev/sda2 with the starting block as noted above (usually 1001470)
Command (m for help): n
Partition type
   p   primary (1 primary, 0 extended, 3 free)
   e   extended (container for logical partitions)
Select (default p): e
Partition number (2-4, default 2): 
First sector (999424-314572799, default 999424): 1001470
Last sector, +sectors or +size{K,M,G,T,P} (1001470-314572799, default 314572799): 

Created a new partition 2 of type 'Extended' and of size 149,5 GiB.
  1. Re-create the extended partition /dev/sda5 with a whatever starting point (just press enter both times!). Take care NOT to remove the ext4 signature!
Command (m for help): n
All space for primary partitions is in use.
Adding logical partition 5
First sector (1003518-314572799, default 1003520): 
Last sector, +sectors or +size{K,M,G,T,P} (1003520-314572799, default 314572799): 

Created a new partition 5 of type 'Linux' and of size 149,5 GiB.
Partition #5 contains a ext4 signature.

Do you want to remove the signature? [Y]es/[N]o: n
  1. Change into the Expert menu and set the beginning of your new /dev/sda5 to the previously noted value (usually 1001472):
Command (m for help): x

Expert command (m for help): b
Partition number (1,2,5, default 5): 
New beginning of data (1001471-314572799, default 1003520): 1001472
  1. Verify starting numbers of /dev/sda2 and /dev/sda5 are the same as noted above in step 2-2.
Expert command (m for help): p

Disk /dev/sda: 150 GiB, 161061273600 bytes, 314572800 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x1ed9986f

Device     Boot   Start       End   Sectors Id Type     Start-C/H/S End-C/H/S Attrs
/dev/sda1  *       2048    999423    997376 83 Linux        0/32/33  62/53/55    80
/dev/sda2       1001470 314572799 313571330  5 Extended    62/86/23  125/64/3      
/dev/sda5       1001472 314572799 313571328 83 Linux      62/118/57  125/64/3
  1. Leave the expert menu and write the partition table to disk, leave fdisk
Expert command (m for help): r

Command (m for help): w

The partition table has been altered.
Calling ioctl() to re-read partition table.
Re-reading the partition table failed.: Das Gerät oder die Ressource ist belegt

The kernel still uses the old table. The new table will be used at the next reboot or after you run partprobe(8) or kpartx(8).
  1. Reboot the VM; it should come up properly

Step 3: Resize LVM and filesystem

  1. Login again to the VM as in previous steps
  2. Resize physical volume: pvresize /dev/sda5
root@owncloud:~# pvresize /dev/sda5
  Physical volume "/dev/sda5" changed
  1 physical volume(s) resized / 0 physical volume(s) not resized
  1. Verify it has been resized, the line “Free PE” should NOT be zero!
root@owncloud:~# pvdisplay -v
    Wiping internal VG cache
    Wiping cache of LVM-capable devices
  --- Physical volume ---
  PV Name               /dev/sda5
  VG Name               vg_ucs
  PV Size               149,52 GiB / not usable 2,00 MiB
  Allocatable           yes 
  PE Size               4,00 MiB
  Total PE              38277
  Free PE               25600
  Allocated PE          12677
  PV UUID               eEOcDZ-x27e-ivIp-HAUf-Um67-t5MP-Pzbdp2
  1. Resize the logical volume and use the number of FreePE from Step 3-3 (here: 25600).
root@owncloud:~# lvresize /dev/vg_ucs/root -l +25600
  Size of logical volume vg_ucs/root changed from 47,52 GiB (12165 extents) to 147,52 GiB (37765 extents).
  Logical volume vg_ucs/root successfully resized.
  1. Resize the filesystem itself
root@owncloud:~# resize2fs /dev/vg_ucs/root 
resize2fs 1.43.4 (31-Jan-2017)
Dateisystem bei /dev/vg_ucs/root ist auf / eingehängt; Online-Größenänderung ist
erforderlich
old_desc_blocks = 10, new_desc_blocks = 19
Das Dateisystem auf /dev/vg_ucs/root is nun 38671360 (4k) Blöcke lang.
  1. Verify by df:
root@owncloud:~# df -h
Dateisystem             Größe Benutzt Verf. Verw% Eingehängt auf
udev                      10M       0   10M    0% /dev
tmpfs                    292M     17M  276M    6% /run
/dev/mapper/vg_ucs-root  143G    3,6G  133G    3% /
tmpfs                    730M       0  730M    0% /dev/shm
tmpfs                    5,0M       0  5,0M    0% /run/lock
tmpfs                    730M       0  730M    0% /sys/fs/cgroup
/dev/sda1                472M     61M  387M   14% /boot
overlay                  143G    3,6G  133G    3% /var/lib/docker/overlay/662d4e26b808c849850c03b569052b578f311fde1afce09df1bcc9bfd9d63227/merged
shm                       64M       0   64M    0% /var/lib/docker/containers/332300a8c307b732a76bf22720b5585a14b53aab5fc969783253add8c8543109/shm

All done now. You Owncloud appliance now has more disk space available.
Note: It would be much easier to do if Own-/ Nextcloud had mounted /var on a separate disk!

1 Like
Mastodon