What Does LVM Mean?
Taking a description from The Geek Diary:
The Logical Volume Manager (LVM) introduces an extra layer between the physical disks and the file system allowing file systems to:
- Be resized and moved easily and online without requiring a system-wide outage.
- Use discontinuous space on disk.
- Have meaningful names to volumes, rather than the usual cryptic device names.
- Span multiple physical disks.
Extending a LVM Volume (e.g. /opt):
Run “vgs” to display information on the available volume groups. This will tell you if you have “free” space that you can allocate to one of the existing logical volumes. In our case, we have 30 GB free.
$> vgs VG #PV #LV #SN Attr VSize VFree rootvg 1 7 0 wz--n- <63.00g <30.00g
Run “lvs” to display the logical volumes on your system and their sizes. Find the one you want to extend.
$> lvs LV VG Attr LSize homelv rootvg -wi-ao---- 1.00g optlv rootvg -wi-ao---- 2.00g rootlv rootvg -wi-ao---- 8.00g swaplv rootvg -wi-ao---- 2.00g tmplv rootvg -wi-ao---- 2.00g usrlv rootvg -wi-ao---- 10.00g varlv rootvg -wi-ao---- 8.00g
Extend the logical volume using “lvextend”. In our case, I’m moving /opt from 2g to 5g.
$> lvextend -L 5g rootvg/optlv
Display the logical volumes again if you like. You won’t see a change yet, it will still say 2.00g.
Use df -hT to show what kind of file system you are using for the volume you resized. This can change the next command you have to do.
$> df -hT Filesystem Type ... /dev/mapper/rootvg-rootlv ext4 ... devtmpfs devtmpfs ... tmpfs tmpfs ... tmpfs tmpfs ... tmpfs tmpfs ... /dev/mapper/rootvg-usrlv ext4 ... /dev/sda1 ext4 ... /dev/mapper/rootvg-optlv ext4 ... /dev/mapper/rootvg-tmplv ext4 ... /dev/mapper/rootvg-varlv ext4 ... /dev/mapper/rootvg-homelv ext4 ... /dev/sdb1 ext4 ... tmpfs tmpfs ...
If it is ext4, you can use the following command to tell the system to recognize the extended volume. If it is not, you will have to find the appropriate command for the given file system.
$> resize2fs /dev/mapper/rootvg-optlv
Now you should see the extended volume size in “lvs” or “df -h”; and you’re done!
$> df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/rootvg-rootlv 7.8G 76M 7.3G 2% / devtmpfs 3.9G 0 3.9G 0% /dev tmpfs 3.9G 4.0K 3.9G 1% /dev/shm tmpfs 3.9G 130M 3.8G 4% /run tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup /dev/mapper/rootvg-usrlv 9.8G 2.6G 6.7G 29% /usr /dev/sda1 976M 119M 790M 14% /boot /dev/mapper/rootvg-optlv 4.9G 1.9G 2.9G 40% /opt /dev/mapper/rootvg-tmplv 2.0G 11M 1.8G 1% /tmp /dev/mapper/rootvg-varlv 7.8G 3.2G 4.2G 44% /var /dev/mapper/rootvg-homelv 976M 49M 861M 6% /home /dev/sdb1 16G 45M 15G 1% /mnt/resource tmpfs 797M 0 797M 0% /run/user/1000