Many Linux servers these days are using LVM (Logical Volume Manager) in order to allow disk drives and partitions to be easily managed (shrinked / resized). It is interesting fact LVM is successor of HP-UX's volume manager. LVM can be considered as a thin software layer on top of the hard disks and partitions, which creates an abstraction of continuity and ease-of-use for managing hard drive replacement, re-partitioning, and backup.
LVM is commonly used for the following purposes:
- Managing large hard disk farms by allowing disks to be added and replaced without downtimes and services disruption (useful whenever hot-swapping is needed)
- On small systems (like a desktop at home), instead of having to estimate at installation time how big a partition might need to be in the future.
– LVM lets file systems to be easily resized later as needed.
- Performing consistent backups by taking snapshots of the logical volumes.
- Creating single logical volumens of multiple physical volumes or entire hard disks (somewhat similar to RAID-0), ability to do dynamic volume resizing (in LVM partitions are volumes).
So if you're sysadmin it is quite likely that some LVM volume starts being filled up (because of bad initial planning), so the customer asks you to resize a LVM (volume), here is how to do it:
1. Check whether LVM configured on server has free disk space that can be relocated
First lets list all LVM configured volumes on server:
Reading all physical volumes. This may take a while...
Found volume group "web_log" using metadata type lvm2
Found volume group "web_all" using metadata type lvm2
Found volume group "rootvg" using metadata type lvm2
vgscan – scan all disks for volume groups and rebuild caches
Then lets display the volume group information.
This is done with vgdisplay cmd
--- Volume group ---
VG Name rootvg
Metadata Areas 1
Metadata Sequence No 13
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 11
Open LV 11
Max PV 0
Cur PV 1
Act PV 1
VG Size 136.56 GB
PE Size 8.00 MB
Total PE 17480
Alloc PE / Size 7329 / 57.26 GB
Free PE / Size 10151 / 79.30 GB
VG UUID 27z2w0-Ku0H-y6M0-QFCR-3Rp6-c1HX-OTinzn
[root@lupus ~]# vgs
VG #PV #LV #SN Attr VSize VFree
VolGroup00 1 3 0 wz–n- 695.44G 0
[root@lupus ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sda3 VolGroup00 lvm2 a– 695.44G 0
Important line from above command output is (Free PE / Size 10151 / 79.30 GB). Indicating that server's LVM had 79.30 GB Free which can be used to extend any of the server LVM existing volumes.
Here are one of servers managed by me existing volumes:
# df -h
Filesystem Size Used Avail Use% Mounted on
5.0G 301M 4.4G 7% /
udev 18G 144K 18G 1% /dev
tmpfs 42G 0 42G 0% /dev/shm
/dev/cciss/c0d0p1 122M 28M 88M 24% /boot
512M 268M 219M 56% /home
2.5G 484M 1.9G 21% /opt
3.0G 895M 2.0G 32% /opt/Tivoli
3.0G 289M 2.6G 11% /opt/uc4
3.0G 69M 2.8G 3% /sysadm
1.3G 35M 1.2G 3% /tmp
4.0G 1.2G 2.6G 32% /usr
5.0G 500M 4.2G 11% /var
9.9G 4.0G 5.9G 41% /webservices
For instance lets say the task is to extend LVM (volume) partition:
9.9G 4.0G 5.9G 41% /webservices
Lets say we want to extend /dev/mapper/rootvg/rootvg-webserices with 20 Gygabytes:
# lvextend -L20G /dev/mapper/rootvg-webservices
Then we we would like to add some extra 10GB:
# lvextend -L10G /dev/mapper/rootvg-webservices
In order to add all available LVM free space to a volume use:
# lvextend -l +100%FREE /dev/mapper/rootvg-webservices
Whether you had to do it on Linux with kernel 2.4.x and ext2 / ext3 FS:
# umount /dev/mapper/rootvg-webservices
# resize2fs /dev/mapper/rootvg-webservices
# mount /dev/mapper/rootvg /webservices
To resize ext4 filesystem with LVM above umount / resize2fs and mount commands can be safely skipped.
On other file systems to raise the size of the filesystem there are different tools to use also on some umount and mount is not necessary example for dynamicly resizable filesystem is reiserfs (though I don't recommend this FS to anyone as the creator of ReiserFS killed his family – moreover my personal experience with ReiserFS in past was quite bitter – I lost personal data because of ReiserFS break ups).
Here is how to dynamicly resize FS after lvextend on Reiserfs filesystem:
# resize_reiserfs -f /dev/myvg/homevol
XFS also supports resize of filesystem with no need to re-mount on server with XFS LVM resize after lvextend run:
# xfs_growfs /webservices
More helpful Articles
Tags: check, disk space, Display, filesystem, Filesystem Size Used Avail Use Mounted, FS, hard disks, howto, information, kernel 2, linux?, Logical Volume Manager, LVM, mapper, metadata, Metadata Areas, mount dev, partition, partitions, resize, server, servers, top, type