Have you ever come across a situation where you have installed linux with partition of fixed size and later you realized that one of the partition size needs to be increased. The only way is to delete the existing partition , create new partition of the required size, install the operating system again and reinstall the application . Is not a tedious process ? Yes it is . LVM is there to rescue you from the tedious task of reinstalling the OS.
Now lets discuss what exactly this LVM is, what it does and how to create that.
LVM is a Logical Volume Manager in Linux. LVM v2 is the latest version of LVM but is almost completely backward compatible with the volume created LVM v1 . Before upgrading from LVM v1 to LVM v2 snapshot volume must be deleted on LVM v1 if one is created.
Kernel 2.6 defaulty support LVM v2 but 2.4 kernel needs patching to support LVM v2 which defaultly supports LVM v1.
Before we go ahead and create logical volume using LVM lets understand the following terms.
Volume Group:
The Volume Group is the highest level abstraction used withn the LVM. It gathers together a collection of Logical Volumes and Physical Volumes into one administrative unit
Physical Volume:
A Physical Volume is typically a hard disk.
Logical Volume:
It actually contain the file system(ext3) as in disk partion in non-LVM system.
Physical Extent:
Each phyical volume is divided into chunk of data, known as physical extents, these extents have the same size as logical extents in the volume group.
Logical Extent:
Each logical volume is split into chunks of data, known as logical extents and the size is same for all logical volumes in the volume group.
Following are the steps to be followed to create logical volumes .In the following example lets assume its a scsi devices and is the first device on the system
1. Create partition using fdisk with partion id 8e
fdisk /dev/sda
2. Create phyical volume on partition created in steps 1
pvcreate /dev/sda{5,7}
3. Create volume group.
vgcreate vgo /dev/sda{5,7}
vg0 is the volume group name which includes three physical volume sda5, sda6 and sda7.
4. Create logical volume
lvcreate -L +150M -n development Vg0
logical volume "development" of size 150MB
Once the logical volume is created , the final steps , create filesystem , mount it and start using to store files.
5. mkfs.ext3 /dev/Vg0/developement ( putting filesystem on the logical volume)
6 .mount /dev/Vg0/development /data ( to mount the filesyste).
7. Update the /etc/fstab file to automatically mount the above partition
/dev/Vg0/development /data ext3 defaults 0 0
Finally we have a logical volume ready to use. But one of the main advantage of lvm is partition resizing without deleting and formating the partion . The command is
lvextend -L +50MB /dev/Vg0/development
To reduce the size of the logical volume
lvreduce -L -3G -n /dev/Vg0/development
No comments:
Post a Comment