Logical Volume Manager
What is LVM ?
LVM (Logical Volume Manager) for the Linux Kernel is a method of allocating hard drive space into logical volumes, this also allows for the easy creation, resizing, or removal of new or existing partitions.
There are 4 main terms with LVM .....
- physical volumes - These are your physical disks, or disk partitions, such as /dev/hda or /dev/hdb1.
- volume groups - A volume group is comprised of real physical volume or volumes.
- logical volumes - The volume group contains your logical volumes, such as /opt /var etc.
- Filesystem - On each logical volume you will have a filesystem.
Note : You can have more then one physically volume used when creating a volume group. i.e 2 Physical Volumes at 20 GB each (2 x 20GB). This would allow you to create a 40GB Volume Group.
How do I change the size of my Logical Volumes ?
The below was carried out of RedHat Enterprise 5. Other Linux distrubutions may vary.
In this example we will resize both /var and /usr to 40GB each. There current sizes are,
- /var = 60GB
- /usr = 20GB
The following commands will provide you with an overview of your Physical / Logical Volumes,
- fdisk -l - Displays your physical volumes
- lvdisplay - Displays your Logical Volume Groups
- df -kh - Displays you Logical Volumes
Ok, so first of all we will need to boot the device into single user mode. We can do this by altering the /etc/inittab file by using the following command. Then reboot your system into single user mode.
sed -i 's/id:3:initdefault/id:1:initdefault/g' /etc/inittab
Once in single-user mode run the following commands, (first of all we will reduce /var)
Note : within the syntax all the size totals (40GB) is the total size that the filesystem / Logical volume will be.
e2fsck -f /dev/vg0/var
resize2fs /dev/vg0/var 40G
lvreduce -L 40G /dev/vg0/var
Now you can extended /usr,
lvextend -L 40G /dev/vg0/usr
resize2fs /dev/vg0/usr 40G
Then use the df -kh command to check that the changes have been successful.
Once you have confirmed the required changes have been made reboot your system into multiuser mode,
sed -i 's/id:1:initdefault/id:3:initdefault/g' /etc/inittab