7.module LVM

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 10

Module7:LVM (Logical Volume Management)

LVM (Logical Volume Management) is basically a tool that provides logical volume
management for the Linux kernel. It is being introduced simply to make physical
storage device management easier. It also includes allocating disks, striping,
mirroring, resizing logical volumes. Its main advantages are increased abstraction,
flexibility, and control. It simply allows for flexible disk space management. It is
especially required to resize the size of the file system online. In Linux, the size of
the LVM partition can be extended using “lvextend” command

Logical Volume Manager (LVM):

 Combining two or more physical volumes (partitions)from two or more HDDs


making a group called as “Volume Group” and dividing Volume group into
small parts called as “Logical Volumes”
 By using LVM ,If you require large amount of partition you can create
 By using LVM ,You can increase partition (Logical Volume) size without loss
of data ,by adding a new disk / physical volume to Volume Group .
 But LVM do not support fault tolerance
Steps for creating LVM :

 Step1 : Create two more partitions from HDD1 / HDD2


 Step2 : Create Physical Volumes (#pvcreate )
 Step3 : Create Volume Group (#vgcreate)
 Step4 : Create Logical Volume in a Volume Group (#lvcreate)
 Step5 : Format Logical Volume (#mkfs.ext3 )
 Step6 : Mount the Logical Volume (#mount)
Checking Partitions by using “fdisk” :

root@localhost ~]# fdisk -l

Disk /dev/sda: 21.4 GB, 21474836480 bytes


255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System


/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 1288 10241437+ 83 Linux
/dev/sda3 1289 1543 2048287+ 82 Linux swap / Solaris
/dev/sda4 1544 1666 987997+ 83 Linux

Disk /dev/sdb: 21.4 GB, 21474836480 bytes


255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System


/dev/sdb1 1 366 2939863+ 83 Linux
/dev/sdb2 367 610 1959930 83 Linux
[root@localhost ~]#

Creating Physical Volumes :

[root@localhost ~]# pvcreate /dev/sda4 /dev/sdb1


Physical volume "/dev/sda4" successfully created
Physical volume "/dev/sdb1" successfully created
[root@localhost ~]#
44
Checking Physical Volumes :

[root@localhost ~]# pvdisplay

--- NEW Physical volume ---


PV Name /dev/sda4
VG Name
PV Size 964.84 MB
Allocatable NO
PE Size (KByte) 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID uWHvL3-T0F2-bwQL-r3ll-fD2w-xQYZ-ivMnH0

--- NEW Physical volume ---


PV Name /dev/sdb1
VG Name
PV Size 2.80 GB
Allocatable NO
PE Size (KByte) 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID jibguB-4P2o-FHx8-HQRD-zZSq-fLUo-3AkpGX

[root@localhost ~]#

Creating Volume Group :

[root@localhost ~]# vgcreate mydata /dev/sda4 /dev/sdb1


Volume group "mydata" successfully created
[root@localhost ~]#

4
4
45
Verifying Volume Group :

[root@localhost ~]# vgdisplay


--- Volume group ---
VG Name mydata
System ID
Format lvm2
Metadata Areas
2
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 2
Act PV 2
VG Size 3.74 GB
PE Size 4.00 MB
Total PE 958
Alloc PE / Size 0/0
Free PE / Size 958 / 3.74 GB
VG UUID 4fEcVZ-G7sF-00W2-nm3Z-B16k-qHwe-RevZPi

[root@localhost ~]#

Creating Logical Volume :

[root@localhost ~]# lvcreate -L 500mb mydata -n itdept


Logical volume "itdept" created

Verifying Logical Voumes :

[root@localhost ~]# lvdisplay


--- Logical volume ---
LV Name /dev/mydata/itdept
VG Name mydata
LV UUID 6VPpkz-CcTv-YeAq-sQX6-2f0m-6r3q-duRAZI
LV Write Access read/write
LV Status available
# open 0
LV Size 500.00 MB
Current LE 125
Segments 1
Allocation inherit
Read ahead sectors
0
Block device 253:0

[root@localhost ~]#

4
46
Formatting Logical Volume :

[root@localhost ~]# mkfs.ext3 /dev/mydata/itdept


mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
128016 inodes, 512000 blocks
25600 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=67633152
63 block groups
8192 blocks per group, 8192 fragments per group
2032 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729, 204801, 221185, 401409

Writing inode tables: done


Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 29 mounts or


180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@localhost ~]#

Mounting Logical Volume:

[root@localhost ~]# mkdir /itdeptdata


[root@localhost ~]# mount /dev/mydata/itdept /itdeptdata
[root@localhost ~]#
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 9.5G 2.6G 6.5G 28% /
/dev/sda1 99M 9.9M 84M 11% /boot
tmpfs 506M 0 506M 0% /dev/shm
/dev/mapper/mydata-itdept
485M 11M 449M 3% /itdeptdata
[root@localhost ~]#

4
6
47
Extending “/dev/mydata/itdept” Logical Volume Size:

Steps for Extending Logical Volume Size :


 Step1 : Add a New HDD or if existed HDD has free space ,create a new partition
 Step2 : Create a physical volume (#pvcreate)
 Step3 : Extend(Add) physical volume into Volume Group (#vgextend)
 Step4 : Resize (increase) logical volume (#lvresize)
 Step5 : Arrange file system for logical volume (#resize2fs)
 Step6 : Verifying Logical Volume Size (#lvdisplay)

Extending Logical Volume Size :


Step1 : Creating a new
partition : [root@localhost ~]#
fdisk -l

Disk /dev/sda: 21.4 GB, 21474836480 bytes


255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System


/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 1288 10241437+ 83 Linux
/dev/sda3 1289 1543 2048287+ 82 Linux swap / Solaris
/dev/sda4 1544 1666 987997+ 83 Linux

Disk /dev/sdb: 21.4 GB, 21474836480 bytes


255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System


/dev/sdb1 1 366 2939863+ 83 Linux
[root@localhost ~]#

4
7
/dev/sdb2 367 610 1959930 83 Linux

[root@localhost ~]#
Step2 : Create a physical volume :

[root@localhost ~]# pvcreate


/dev/sdb2
Physical volume "/dev/sdb2" successfully created
[root@localhost ~]#

Step3 : Extend(Add) physical volume into Volume Group:

[root@localhost ~]# vgextend mydata /dev/sdb2


Volume group "mydata" successfully extended
[root@localhost ~]#

Step4 : Resize (increase) logical volume:

[root@localhost ~]# lvresize -L +450M /dev/mydata/itdept


Rounding up size to full physical extent 452.00 MB
Extending logical volume itdept to 952.00 MB
Logical volume itdept successfully resized
[root@localhost ~]#

Step5 : Arrange file system for logical volume:

[root@localhost ~]# resize2fs /dev/mydata/itdept


resize2fs 1.39 (29-May-2006)
Filesystem at /dev/mydata/itdept is mounted on /itdeptdata; on-line resizing required
Performing an on-line resize of /dev/mydata/itdept to 974848 (1k) blocks.
The filesystem on /dev/mydata/itdept is now 974848 blocks long.

Step6 : Verifying Logical Volume Size:

[root@localhost ~]# lvdisplay


--- Logical volume ---
LV Name /dev/mydata/itdept
VG Name mydata
LV UUID 6VPpkz-CcTv-YeAq-sQX6-2f0m-6r3q-duRAZI
LV Write Access read/write
LV Status available
# open 1
LV Size 952.00 MB
Current LE 238
Segments 1
Allocation inherit
Read ahead sectors
0

[root@localhost ~]#

4
8
Block device 253:0

[root@localhost ~]#

You might also like