In this scenario I had Linux installed on a VM with disk size 10G with LVM configuration. I needed to extend the root residing on the LVM on this disk. I resized the disk from the hypervisor (10G->16G), now need to extend the space on the OS
The output below show that the current configuration. Note that the disk is now 15GiB, but the sda3
partition is still 9.5GiB
root@pvetest2:~# gdisk -l /dev/sda
GPT fdisk (gdisk) version 1.0.3
Partition table scan:
MBR: protective
BSD: not present
APM: not present
GPT: present
Found valid GPT with protective MBR; using GPT.
Disk /dev/sda: 33554432 sectors, 16.0 GiB
Model: QEMU HARDDISK
Sector size (logical/physical): 512/512 bytes
Disk identifier (GUID): 599595F0-2AD1-458F-A08A-7DF3C81181CA
Partition table holds up to 128 entries
Main partition table begins at sector 2 and ends at sector 33
First usable sector is 34, last usable sector is 20971486
Partitions will be aligned on 2-sector boundaries
Total free space is 0 sectors (0 bytes)
Number Start (sector) End (sector) Size Code Name
1 34 2047 1007.0 KiB EF02
2 2048 1050623 512.0 MiB EF00
3 1050624 20971486 9.5 GiB 8E00
root@pvetest2:~# gdisk -l /dev/sda
GPT fdisk (gdisk) version 1.0.3
Partition table scan:
MBR: protective
BSD: not present
APM: not present
GPT: present
Found valid GPT with protective MBR; using GPT.
Note that the disk size is 16GiB, but the last usable sector is still 20971486, which corresponds to 10GiB disk
We need to adjust that with the 'e'
expert level command on the gdisk tool:
Command (? for help): x
Expert command (? for help): e
Relocating backup data structures to the end of the disk
Expert command (? for help): m
Command (? for help): p
Disk /dev/sda: 33554432 sectors, 16.0 GiB
Model: QEMU HARDDISK
Sector size (logical/physical): 512/512 bytes
Disk identifier (GUID): 599595F0-2AD1-458F-A08A-7DF3C81181CA
Partition table holds up to 128 entries
Main partition table begins at sector 2 and ends at sector 33
First usable sector is 34, last usable sector is 33554398
Partitions will be aligned on 2-sector boundaries
Total free space is 12582912 sectors (6.0 GiB)
Number Start (sector) End (sector) Size Code Name
1 34 2047 1007.0 KiB EF02
2 2048 1050623 512.0 MiB EF00
3 1050624 20971486 9.5 GiB 8E00
Note that the last usable sector is now 33554398, which corresponds to 16GiB
Need to collect the old partition GUID (might not be neccessary, but won’t hurt)
Command (? for help): i
Partition number (1-3): 3
Partition GUID code: E6D6D379-F507-44C2-A23C-238F2A3DF928 (Linux LVM)
Partition unique GUID: 389714C3-986C-4BA6-B164-774B4A95A68E
First sector: 1050624 (at 513.0 MiB)
Last sector: 20971486 (at 10.0 GiB)
Partition size: 19920863 sectors (9.5 GiB)
Attribute flags: 0000000000000000
Partition name: ''
Take a note of the Partition unique GUID
Now need to delete the old partition and re-create a new one with the extended size
Command (? for help): d
Partition number (1-3): 3
Command (? for help): n
Partition number (3-128, default 3): 3
First sector (1050624-33554398, default = 1050624) or {+-}size{KMGTP}:
Last sector (1050624-33554398, default = 33554398) or {+-}size{KMGTP}:
Current type is 'Linux filesystem'
Hex code or GUID (L to show codes, Enter = 8300): 8E00
Changed type of partition to 'Linux LVM'
Assign the old partition GUID and save all the changes
Command (? for help): x
Expert command (? for help): c
Partition number (1-3): 3
Enter the partition's new unique GUID ('R' to randomize): 389714C3-986C-4BA6-B164-774B4A95A68E
New GUID is 389714C3-986C-4BA6-B164-774B4A95A68E
Expert command (? for help): w
Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!
Do you want to proceed? (Y/N): y
OK; writing new GUID partition table (GPT) to /dev/sda.
Warning: The kernel is still using the old partition table.
The new table will be used at the next reboot or after you
run partprobe(8) or kpartx(8)
The operation has completed successfully.
We need to run partprobe tool to rescan the partition (might need to be installed as part of parted package)
root@pvetest2:~# apt install parted
...
root@pvetest2:~# partprobe
Now need to extend the LVM physical volume
root@pvetest2:~# pvdisplay
--- Physical volume ---
PV Name /dev/sda3
VG Name pve
PV Size <9.50 GiB / not usable 2.98 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 2431
Free PE 1567
Allocated PE 864
PV UUID vR3OsT-HNP1-pHQD-ADVx-2uBc-uLip-qIF5lL
root@pvetest2:~# pvresize /dev/sda3
Physical volume "/dev/sda3" changed
1 physical volume(s) resized or updated / 0 physical volume(s) not resized
root@pvetest2:~# pvdisplay
--- Physical volume ---
PV Name /dev/sda3
VG Name pve
PV Size <15.50 GiB / not usable 1.98 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 3967
Free PE 3103
Allocated PE 864
PV UUID vR3OsT-HNP1-pHQD-ADVx-2uBc-uLip-qIF5lL
Now use the usual LVM lvextend command to extend the logical volume to your liking Here I extend the root volume to the maximum
root@pvetest2:~# lvextend -l 100%FREE pve/root
Size of logical volume pve/root changed from 2.25 GiB (576 extents) to 12.12 GiB (3103 extents).
Logical volume pve/root successfully resized.
Resize the filesystem
root@pvetest2:~# resize2fs /dev/pve/root
resize2fs 1.44.5 (15-Dec-2018)
Filesystem at /dev/pve/root is mounted on /; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 2
The filesystem on /dev/pve/root is now 3177472 (4k) blocks long.
Than concludes the process