For this method, you will need to expand the size of the disk attached to your Deskpro server in your hypervisor, then restart your VM in order for the kernel to recognise the disk has been resized.
All commands listed below must be run as the root
user on the server. You can escalate to root from a sudoer user with the command sudo su -
Identifying the partition to expand
Once the VM has restarted, run the command fdisk -l
, and you should see that the total size of the disk has grown, but the size of the partitions haven't changed.
Disk /dev/sda: 50 GiB, 53687091200 bytes, 104857600 sectors
Disk model: Virtual disk
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: gpt
Disk identifier: 0F162CEE-5CE2-4CFB-8187-C1770A85FA78
Device Start End Sectors Size Type
/dev/sda1 2048 4095 2048 1M BIOS boot
/dev/sda2 4096 4198399 4194304 2G Linux filesystem
/dev/sda3 4198400 62912511 58714112 28G Linux filesystem
Disk /dev/mapper/ubuntu--vg-ubuntu--lv: 28 GiB, 30060576768 bytes, 58712064 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 copy
In the example above, the disk /dev/sda has a size of 50GB, but the 3 partitions on the disk only amount to 30GB in size. Additionally, the logical volume /dev/mapper/ubuntu--vg-ubuntu--lv has a size of 28GB, which matches the size of the largest partition. /dev/mapper/ubuntu--vg-ubuntu--lv is mounted on / when you run df
.
You can also run the command pvdisplay
to confirm the Physical Volume /dev/sda3 is within the volume group:
root@deskpro:~# pvdisplay
--- Physical volume ---
PV Name /dev/sda3
VG Name ubuntu-vg
PV Size <28.00 GiB / not usable 0
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 7167
Free PE 0
Allocated PE 7167
PV UUID nCxUhI-F1e4-BYBy-oMzz-QOaV-ksfK-VRcz1f copy
From this, we can confirm that /dev/sda3 is the partition we need to grow.
Repartitioning the disk
The first step in growing the disk is repartitioning the disk to expand /dev/sda3. This guide will use parted
to do this.
parted /dev/sda copy
This should start the GNU Parted prompt for the disk /dev/sda. The following commands need to be entered into the (parted)
prompt.
First, confirm the current partition table with the command print
(parted) print
Model: VMware Virtual disk (scsi)
Disk /dev/sda: 53.7GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 1049kB 2097kB 1049kB bios_grub
2 2097kB 2150MB 2147MB ext4
3 2150MB 32.2GB 30.1GB copy
In the above example, the partition numbers match the partitions from fdisk -l
, so we want to move the end of partition 3 to the end of the disk. The easiest way to do this is to run the command resizepart <partition> <end>
. In this context, the command will be resizepart 3 100%
:
(parted) resizepart 3 100%
(parted) print
Model: VMware Virtual disk (scsi)
Disk /dev/sda: 53.7GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 1049kB 2097kB 1049kB bios_grub
2 2097kB 2150MB 2147MB ext4
3 2150MB 53.7GB 51.5GB copy
As we can see above, the End of Partition 3 now reaches the end of the disk, and the size of the partition has increased.
The partition has now been resized. Run the command quit
to leave the (parted)
prompt.
We can now run fdisk -l
to confirm that the /dev/sda3 has grown, and the partitions on /dev/sda now match the total size of the disk.
Growing the Physical Volume
If you run the commands pvdisplay
and vgdisplay
, you will still see that the Physical Volume is at the old size of the partition, and there is no free space within the Volume Group:
root@deskpro:~# pvdisplay
--- Physical volume ---
PV Name /dev/sda3
VG Name ubuntu-vg
PV Size <28.00 GiB / not usable 0
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 7167
Free PE 0
Allocated PE 7167
PV UUID nCxUhI-F1e4-BYBy-oMzz-QOaV-ksfK-VRcz1f
root@deskpro:~# vgdisplay
--- Volume group ---
VG Name ubuntu-vg
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 2
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 1
Max PV 0
Cur PV 1
Act PV 1
VG Size <28.00 GiB
PE Size 4.00 MiB
Total PE 7167
Alloc PE / Size 7167 / <28.00 GiB
Free PE / Size 0 / 0
VG UUID YuHCnH-4xGx-jk7p-52mH-epkG-Qbvn-OVjYBw copy
We first need to resize the Physical Volume to take up the full partition size with pvresize
root@deskpro:~# pvresize /dev/sda3
Physical volume "/dev/sda3" changed
1 physical volume(s) resized or updated / 0 physical volume(s) not resized copy
Now, if we run pvdisplay
and vgdisplay
, we will see that the Physical Volume uses the full space on the partition, and the Volume Group now has some free space:
root@deskpro:~# pvdisplay
--- Physical volume ---
PV Name /dev/sda3
VG Name ubuntu-vg
PV Size <48.00 GiB / not usable 16.50 KiB
Allocatable yes
PE Size 4.00 MiB
Total PE 12287
Free PE 5120
Allocated PE 7167
PV UUID nCxUhI-F1e4-BYBy-oMzz-QOaV-ksfK-VRcz1f
root@deskpro:~# vgdisplay
--- Volume group ---
VG Name ubuntu-vg
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 3
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 1
Max PV 0
Cur PV 1
Act PV 1
VG Size <48.00 GiB
PE Size 4.00 MiB
Total PE 12287
Alloc PE / Size 7167 / <28.00 GiB
Free PE / Size 5120 / 20.00 GiB
VG UUID YuHCnH-4xGx-jk7p-52mH-epkG-Qbvn-OVjYBw copy
With the space now being available to the volume group, move on to Growing the Logical Volume
Please log in or register to submit a comment.