Sunday, August 22, 2010

How to create logical volume or LVM on linux machine?

Guys,

Logical volume management provides a higher-level view of the disk storage on a computer system than the traditional view of disks and partitions. This gives the system administrator much more flexibility in allocating storage to applications and users.

Storage volumes created under the control of the logical volume manager can be resized and moved around almost at will, although this may need some upgrading of file system tools.

I have referred the following steps.

Before proceeding to create the LVM we need to first partition the drive. You may choose whole drive or some portion of the drive. So, check the current partition table.

1.
====
[root@server ~]#fdisk -l /dev/sdb
====

2. Start to partition the disk or drive (ie /dev/sdb):

====
[root@server ~]# fdisk /dev/sdb

Command (m for help): t // change partition type
Selected partition 1 // number, so system will create /dev/sdb1 drive.
Hex code (type L to list codes): L // show list of type
Hex code (type L to list codes): 8e // 8e for Linux LVM, 83 for Linux, 85 for Linux extended.

Just carefully proceed here. If you do you any mistake you can start again until you press "w' command.
====

Now please make it sure that you have used "w" command to write the partition table. It'll take a few minutes to complete and it's depending upon the size of the disk.

3. Create Physical Volume :

====
[root@server ~]fdisk -l /dev/sdb //check whether sdb1 has created or not.
[root@server ~]#pvcreate /dev/sdb1 // create Physical Volume

Physical volume "/dev/sdb1" successfully created

Note : If you would like to specify partition size
[root@server ~]# pvcreate --setphysicalvolumesize 100G /dev/sdb1
Physical volume "/dev/sdb1" successfully created

Else it'll take whole size as per the partition size. You can use pvresize which allows you to change the size of a physical vol­ume and this belongs to a volume group in case the underlying device changes size. Here is the CMD.

[root@server ~]# pvresize --setphysicalvolumesize 100G /dev/sdb1
====

4. Create volume group :

====
[root@server ~]# vgcreate VZ /dev/sdb1 // create Volume group 'VZ'
Volume group "VZ" successfully created

Note : If you want to add another disk or drive(partitioned with same type) you can use following command :

[root@server ~]# vgcreate VZ /dev/sdb1 /dev/sdd2
Volume group "VZ" successfully created

[root@server ~]# vgrename VZ MyVZ // change current name 'VZ' to new name MyVZ' //to rename
[root@server ~]# vgs //display the volume
[root@server ~]# vgextend VZ /dev/sdd2 // add sdd1 in VZ
[root@server ~]# vgreduce VZ /dev/sdd2 // remove sdd1 from VZ
====

5. Create logical vulome :-

=====
[root@server ~]# lvcreate -L 10G -n mydata VZ
=====

6. Create backup or snapshot of the above LVM :

====
[root@server ~]# lvcreate -s -L 5G -n SNAP /dev/VZ/mydata
Logical volume "SNAP" created
====

7. Extend and Reduce the LVM :

===
[root@server ~]# lvextend -L 20G /dev/VZ/mydata //will exyend 20GB

Then exucte folloiwng comamnd :

[root@server ~]# resize2fs /dev/VZ/mydata //to make it effective
===

====
[root@server ~]# lvreduce -L 10G /dev/VZ/mydata //reduce 20 GB
[root@server ~]# lvremove /dev/VZ/mydata //to remove the LVM
====

Ref : http://www.centos.org/docs/5/html/Cluster_Logical_Volume_Manager/LV_create.html

That's it. Try :)

No comments:

Post a Comment