The first thing you should do is verify that you don't already have the space you need by seeing how much free space your volume group has.
All the following commands usually require sudo.
You can see the attributes of volume groups with vgdisplay
vgdisplay
You should see something like this:
--- Volume group ---
VG Name example-vg
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 6
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 2
Act PV 2
VG Size 15.52 GiB
PE Size 4.00 MiB
Total PE 3972
Alloc PE / Size 3963 / 15.48 GiB
Free PE / Size 9 / 36.00 MiB
VG UUID JZCVgU-QvdG-2dMN-ZLrO-YXHp-83bq-zItAUD
If you have free physical extents (PE) you can just add those ( if the free physical extents size covers your needs, skip to adding to logical volume Ctrl + F ADDING TO LOGICAL VOLUME
).
If you don't have enough free space in your volume group, you need to add it from your free allocated space, but first you need to partition it.
You can do that with fdisk
fdisk /dev/sda
First list the existing table ( You need to know where to start the partition from )
In fdisk ( Command (m for help):
)
p
Will display something like this:
Device Boot Start End Sectors Size Id Type
/dev/sda1 * 2048 999423 997376 487M 83 Linux
/dev/sda2 1001470 32000000 30998531 14.8G 5 Extended
/dev/sda3 32002048 48779263 16777216 8G 8e Linux LVM
/dev/sda5 1001472 32000000 30998529 14.8G 8e Linux LVM
Copy the highest End. Otherwise you might create a partition between partitions, which limits the partition's size to the space between the partitions. ( like 1 kb )
Proceed by pressing n ( create a new partition )
n
Choose the default number ( it doesn't matter much, but write it down or remember it)
Paste the highest end for the first sector and end as +size{K,M,G,T,P} ( or however you like )
That will create the new partition.
You should now reboot ( sudo reboot
)
After reboot create the physical volume pvcreate /dev/sda##THE NUMBER YOU CHOSE##
Reboot again if needed sudo reboot
If you don't remember the number you can just fdisk /dev/sda ... p
to list them.
Now extend your volume group vgextend example-vg /dev/sda##NUMBER##
ADDING TO LOGICAL VOLUME
sudo parted ##example-vg-path ( from vgdisplay) ##
print list ( find your /dev/mapper/example-vg--vg-root )
resizepart NUMBER
Enter your size
quit
sudo resize2fs /dev/mapper/example--vg-root
Run df -h
to check.
The ending got a bit clunky but oh well in a hurry :)
end as +size{K,M,G,T,P}
? could you provide an example actual value? – Tom Roggero Feb 05 '19 at 23:31