Let's say you happen to have a Debian-based VM with a small single storage drive (hard disk in Proxmox VE) of about 5 GiB, and you need to make it bigger, up to 10 GiB for instance. To do so you'll have to resize the hard disk first, then you'll need to extend the root LVM filesystem inside of it over the new space. The procedure is not hard but, since it manipulates the root
filesystem while it's active, you must be careful when going through it.
You can expand any hard disk attached to a VM easily on Proxmox VE.
-
With the VM shutdown, get into the
Hardware
tab, select the hard disk and then press onResize disk
.In this case, the hard disk to resize has a 5 GiB size.
-
You'll get to a very simple form.
The
Disk
field identifies the hard disk you're about to resize, and theSize Increment
field is where you indicate by how much you want to increase the size of this particular hard disk.BEWARE!
The Proxmox VE web console only supports INCREASING a hard disk's size, not reducing it. -
Type the increment, in gigabytes, you want to apply to the hard disk and click on
Resize Disk
.In this case, the hard disk will be made 5 GiB bigger.
-
Proxmox VE will apply the resize immediately, so you'll see the new size shown in the hard disk description.
The hard disk now has a total of 10 GiB, from an initial capacity of 5 GiB.
The hard disk is bigger now, but the VM's filesystem is not using that extra space yet. You need to extend it over the newly available space. Assuming the VM is a Debian system installed over a LVM filesystem, here you'll see how to extend it's root filesystem while the VM is running.
BEWARE!
The following procedure, if not applied with care, could make your VM's filesystem (and the VM itself) unusable!
Before you can extend the root
LVM volume, you need to resize the partition in which it's found.
-
Check with
fdisk
if your system truly sees the full size of the disk.$ sudo fdisk -l Disk /dev/sda: 10 GiB, 10737418240 bytes, 20971520 sectors Disk model: QEMU HARDDISK 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: 0xf8a21db5 Device Boot Start End Sectors Size Id Type /dev/sda1 * 2048 999423 997376 487M 83 Linux /dev/sda2 1001470 10483711 9482242 4.5G 5 Extended /dev/sda5 1001472 10483711 9482240 4.5G 8e Linux LVM Disk /dev/mapper/debiandemo--vg-root: 3.56 GiB, 3825205248 bytes, 7471104 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 Disk /dev/mapper/debiandemo--vg-swap_1: 980 MiB, 1027604480 bytes, 2007040 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
Notice the
Disk /dev/sda
line, it says that thesda
harddisk has the expected 10 GiB. Also see how insidesda
there are three partitions:sda1
,sda2
andsda5
. Thesda5
partition is the one you want to spread over the extra storage space available, since its the one that contains theroot
LVM volume (and also the swap volume). But thissda5
partition is inside theExtended
sda2
one, so you need to expand first thesda2
partition to the end of thesda
drive. -
Now you're going to install another partition tool that will help you resize the
sda2
andsda5
partitions easily. The tool isparted
.$ sudo apt install -y parted
-
Launch
parted
over the/dev/sda
drive.$ sudo parted /dev/sda
Then you'll get in the
parted
shell.GNU Parted 3.4 Using /dev/sda Welcome to GNU Parted! Type 'help' to view a list of commands. (parted)
-
Execute
print
to check howparted
sees thesda
partitions.(parted) print Model: QEMU QEMU HARDDISK (scsi) Disk /dev/sda: 10.7GB Sector size (logical/physical): 512B/512B Partition Table: msdos Disk Flags: Number Start End Size Type File system Flags 1 1049kB 512MB 511MB primary ext2 boot 2 513MB 5368MB 4855MB extended 5 513MB 5368MB 4855MB logical lvm
Notice that the
Number
is what identifies each partition: thesda2
is shown just as number2
, andsda5
as5
. -
Resize the partition
2
with the followingresize
command.BEWARE!
Theparted
program applies the changes in the partition table immediately, unlikefdisk
that works first on a temporal table on memory.(parted) resizepart 2 -1s
It won't return any output. Check with
print
that the resizing has been done.(parted) print Model: QEMU QEMU HARDDISK (scsi) Disk /dev/sda: 10.7GB Sector size (logical/physical): 512B/512B Partition Table: msdos Disk Flags: Number Start End Size Type File system Flags 1 1049kB 512MB 511MB primary ext2 boot 2 513MB 10.7GB 10.2GB extended 5 513MB 5368MB 4855MB logical lvm
-
Now, apply the resizing to partition
5
.(parted) resizepart 5 -1s
Again, use
print
to verify the resizing.(parted) print Model: QEMU QEMU HARDDISK (scsi) Disk /dev/sda: 10.7GB Sector size (logical/physical): 512B/512B Partition Table: msdos Disk Flags: Number Start End Size Type File system Flags 1 1049kB 512MB 511MB primary ext2 boot 2 513MB 10.7GB 10.2GB extended 5 513MB 10.7GB 10.2GB logical lvm
-
Type
quit
or just use Ctrl+C to exitparted
.(parted) quit Information: You may need to update /etc/fstab.
Notice that, when exiting,
parted
will warn you about updating the/etc/fstab
file. In this case it won't be necessary.
With the real partitions updated, now you can extend the LVM filesystem in the newly available space.
-
First you must extend the physical volume that corresponds to the
sda5
partition. Check withpvs
its current state.$ sudo pvs PV VG Fmt Attr PSize PFree /dev/sda5 debiandemo-vg lvm2 a-- <4.52g 0
Notice that its
PSize
is only around 4.5 GiB. -
Use
pvresize
to expand thesda5
PV.$ sudo pvresize /dev/sda5 Physical volume "/dev/sda5" changed 1 physical volume(s) resized or updated / 0 physical volume(s) not resized
Then verify with
pvs
that the resizing has been done.$ sudo pvs PV VG Fmt Attr PSize PFree /dev/sda5 debiandemo-vg lvm2 a-- <9.52g 5.00g
Above you can see that
PSize
is now 9.52 GiB, from which 5 GiB are free (PFree
column). -
Now you can resize the
root
LV itself. First, check it's current status.$ sudo lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert root debiandemo-vg -wi-ao---- 3.56g swap_1 debiandemo-vg -wi-ao---- 980.00m
It's
LSize
is 3.56 GiB and, below it, you can see the swap volume (swap_1
) taking up a bit less than 1 GiB. -
Use the following
lvextend
command to extend theroot
volume over all the available free space in thesda5
PV.$ sudo lvextend -r -l +100%FREE debiandemo-vg/root Size of logical volume debiandemo-vg/root changed from 3.56 GiB (912 extents) to 8.56 GiB (2192 extents). Logical volume debiandemo-vg/root successfully resized. resize2fs 1.46.2 (28-Feb-2021) Filesystem at /dev/mapper/debiandemo--vg-root is mounted on /; on-line resizing required old_desc_blocks = 1, new_desc_blocks = 2 The filesystem on /dev/mapper/debiandemo--vg-root is now 2244608 (4k) blocks long.
The command not only has resized the LV, but also has resized the
ext4
filesystem inside (the-r
option called theresize2fs
command). Check again withlvs
the new status of theroot
LV.$ sudo lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert root debiandemo-vg -wi-ao---- 8.56g swap_1 debiandemo-vg -wi-ao---- 980.00m
Now it's
LSize
is 8.56 GiB, and the swap volume has been unaffected by the whole procedure. -
As a final test, reboot the VM to verify that the changes have not messed up with the system in a bad way. This is something you may detect in the VM's boot sequence, sequence which you can see only through a noVNC shell, never remotely through ssh.
$ sudo reboot
This procedure is, as it is, also valid to extend any non-root LVM volumes.
- How to resize LVM disk in Debian 8.6 without losing data
- Expanding LVM Partitions in VMware, on the fly
- How to extend a Linux PV partition online after virtual disk growth
- Extend a LVM partition after increasing its virtual disk on VirtualBox
- How do I extend a partition with a LVM and the contained physical volume and logical volume?
- CentOS / RHEL : How to extend Physical Volume in LVM by extending the Disk Partition used
- How to Increase the size of a Linux LVM by expanding the virtual machine disk
- LVM Resize – How to Increase an LVM Partition
<< Previous (G906. Appendix 06) | +Table Of Contents+ | Next (G908. Appendix 08) >>