Logical Volume Management

LOGICAL VOLUME MANAGEMENT

LVM is one of the most flexible partitioning method for storage servers. LVM differs with many features than a physical, extended and logical partitions. The most important features of LVM are resizing, snapshots, and reduces wastage of space.

LVM is created in three steps they are as follows,

PHYSICAL VOLUME (PV)
VOLUME GROUP (VG)
LOGICAL VOLUME (LV)

Consider you are having 3 partitions /dev/sda6, sda7, sda8 each of 10MB (applicable for hard drives also), after creating partitions convert the partitions to Physical Volume(PV) using pvcreate tool, then create the Volume Group(VG) namely VG1 by combining the PVs using vgcreate tool. Now the VG would be 30MB. After VG creation Logical Volumes(LV) can be created using lvcreate tool.

PHYSICAL VOLUME:

CREATING PVs:

Physical volume creation is the first step to create a LV. This could be done by pvcreate tool, this converts a physical or logical partition or a entire hard drive to a physical volume. Let us create the sda6,7,8 partitions to PVs.

[root@amanda test]# pvcreate /dev/sda6
Physical volume “/dev/sda6″ successfully created

[root@amanda test]# pvcreate /dev/sda7
Physical volume “/dev/sda7″ successfully created

[root@amanda test]# pvcreate /dev/sda8
Physical volume “/dev/sda8″ successfully created
Image

DISPLAYING PVs:

To display the informations about physical volumes use pvdisplay tool, this will display all the PVs in the server. To display a particular PV provide the PV name followed by the tool(pvdisplay).

[root@amanda ~]# pvdisplay

— Physical volume —
PV Name /dev/sda6
VG Name VG1
PV Size 15.66 MB / not usable 3.66 MB
Allocatable yes
PE Size (KByte) 4096
Total PE 3
Free PE 2
Allocated PE 1
PV UUID tqMGGD-WvHq-cbBC-5izA-KsQO-UY0Z-N9FQgG

— Physical volume —
PV Name /dev/sda7
VG Name VG1
PV Size 15.66 MB / not usable 3.66 MB
Allocatable yes
PE Size (KByte) 4096
Total PE 3
Free PE 3
Allocated PE 0
PV UUID zIEXlt-4AXs-fDNm-NByC-GNuK-OLR8-FIae76

— Physical volume —
PV Name /dev/sda8
VG Name VG1
PV Size 15.66 MB / not usable 3.66 MB
Allocatable yes
PE Size (KByte) 4096
Total PE 3
Free PE 3
Allocated PE 0
PV UUID YjK2JH-8eEA-U3gi-3CCO-4YvX-2GnU-fppl29
Image
VOLUME GROUP:

CREATING VGs:

Volume group is like a storage pool where you can combine number of PVs to create a entire size of VGs. VG can be created using vgcreate tool. Let us combine the three PVs already created to create a VG (Storage Pool).

[root@amanda test]# vgcreate VG1 /dev/sda6 /dev/sda7 /dev/sda8
Volume group “VG1″ successfully created

The command syntax describes
vgcreate is the tool name, VG1 is the name of the we are going to create VG and /dev/sda6,7,8 are the PVs already created

DISPLAYING VGs:

To display all the VG in the server use vgdisplay tool. To dsplay a specific VG provide the VG name followed by the tool (vgdisplay).

[root@amanda test]# vgdisplay
— Volume group —
VG Name VG1
System ID
Format lvm2
Metadata Areas 3
Metadata Sequence No 1
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 0
Open LV 0
Max PV 0
Cur PV 3
Act PV 3
VG Size 36.00 MB
PE Size 4.00 MB
Total PE 9
Alloc PE / Size 0 / 0
Free PE / Size 9 / 36.00 MB
VG UUID UqyVNt-WRTO-UZCw-W9lz-3BGD-STC3-sB8rmW

LOGICAL VOLUME

CREATING LVs:

LVs are created from VG by using lvcreate tool. Let us create a LV namely LV1 from the Volume Group VG1.

[root@amanda test]# lvcreate -L 3M -n LV1 VG1
Rounding up size to full physical extent 4.00 MB
Logical volume “LV1″ created

Here you can see the round up size as 4.00 MB, this is nothing but the PE Physical Extends. We could not create a LV below PV size this would be shown in the vgdisplay tool’s output as PE Size 4.00 MB. We can alter the PV size.

DISPLAYING LVs:

To display all the LV in the server use lvdisplay tool. To dsplay a specific LV provide the LV name followed by the tool (lvdisplay).

[root@amanda ~]# lvdisplay
— Logical volume —
LV Name /dev/VG1/LV1
VG Name VG1
LV UUID ZD78J6-MKcv-pK6B-4oVC-987W-KmRV-kprbyA
LV Write Access read/write
LV Status available
# open 0
LV Size 4.00 MB
Current LE 1
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
FORMATING AND MOUNTING LV:

Formating and Mounting LV is as same as the procedures done with primary and logical partitions. Please refer http://linuxczar.com/partitions-linux/.
RESIZING LV

EXTENDING LV:

Extending a LV does’nt need unmount, it can been extended with its mount state,

[root@amanda ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 3.0G 1.6G 1.3G 55% /
tmpfs 62M 0 62M 0% /dev/shm
/dev/sda5 471M 11M 437M 3% /temp
/dev/mapper/VG1-LV1 3.9M 1.1M 2.7M 29% /test

Here you can see the mounted LV of 4MB size in /test directory, Now let us extend the LV with lvextend tool.

[root@amanda test]# lvextend -L +4M /dev/VG1/LV1
Extending logical volume LV1 to 8.00 MB
Logical volume LV1 successfully resized

Check the extended size with lvdisplay and df -h tools.

[root@amanda test]# lvdisplay
— Logical volume —
LV Name /dev/VG1/LV1
VG Name VG1
LV UUID ZD78J6-MKcv-pK6B-4oVC-987W-KmRV-kprbyA
LV Write Access read/write
LV Status available
# open 1
LV Size 8.00 MB
Current LE 2
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0

Now you can see the extended length of the LV in LV size option, but the mount point will not take effect and it will use the old size of the LV before extending. In order to make the mount point to use the extended size, need to use the resize2fs tool as follows.

[root@amanda ~]# resize2fs /dev/VG1/LV1
resize2fs 1.39 (29-May-2006)
Filesystem at /dev/VG1/LV1 is mounted on /test; on-line resizing required
Performing an on-line resize of /dev/VG1/LV1 to 8192 (1k) blocks.
The filesystem on /dev/VG1/LV1 is now 8192 blocks long.

Now the mount point would use the entire size of the LV

[root@amanda ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 3.0G 1.6G 1.3G 55% /
tmpfs 62M 0 62M 0% /dev/shm
/dev/sda5 471M 11M 437M 3% /temp
/dev/mapper/VG1-LV1 7.9M 1.1M 6.7M 14% /test

REDUCING:

Reducing a LV size includes three steps, first unmount the LV (reducing a LV must need unmount), then run e2fsck to check the file system, then intimate the LV to which size it is going to be reduced, finally reduce the LV using lvreduce tool.

[root@amanda ~]# umount /dev/VG1/LV1

[root@amanda ~]# e2fsck /dev/VG1/LV1
e2fsck 1.39 (29-May-2006)
/dev/VG1/LV1: clean, 11/1024 files, 1192/8192 blocks

[root@amanda ~]# e2fsck /dev/VG1/LV1 -f
e2fsck 1.39 (29-May-2006)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/VG1/LV1: 11/1024 files (9.1% non-contiguous), 1192/8192 blocks

[root@amanda ~]# resize2fs /dev/VG1/LV1 4M
resize2fs 1.39 (29-May-2006)
Resizing the filesystem on /dev/VG1/LV1 to 4096 (1k) blocks.
The filesystem on /dev/VG1/LV1 is now 4096 blocks long.

[root@amanda ~]# lvreduce -L 4M /dev/VG1/LV1
WARNING: Reducing active logical volume to 4.00 MB
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce LV1? [y/n]: y
Reducing logical volume LV1 to 4.00 MB
Logical volume LV1 successfully resized

remount the LV and check the size.

[root@amanda ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 3.0G 1.6G 1.3G 55% /
tmpfs 62M 0 62M 0% /dev/shm
/dev/sda5 471M 11M 437M 3% /temp
/dev/mapper/VG1-LV1 3.9M 1.1M 2.8M 28% /test

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>