WHAT IS LVM AND HOW TO CONFIGURE LVM IN LINUX .

LVM stands for logical volume management . It is created over vg ( volume group ) . And volume group is created by combining many harddisks . Google drive is one of the example of lvm . Means what google did is , he kept big amount of space volumes as volume group and gave user 15GB as lvm ( logical volume management ) .

So every google drive users have 15 GB of space . You will better understand by looking at the diagram . In this you can see volume group is made upon three harddisks and then we take small amount of space in a form of Lvm  .

lvm in linux

HOW TO CONFIGURE LVM IN LINUX

  • First we will create partitions in linux .
  • Command n ( to create partitions )
  • Command p  ( to print )
  • Command w  ( to save)
[root@dhcppc6 ~]# fdisk /dev/sda
The number of cylinders for this disk is set to 65399.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
   (e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): n
Command action
   l   logical (5 or over)
   p   primary partition (1-4)
l
First cylinder (57368-65399, default 57368):
Using default value 57368
Last cylinder or +size or +sizeM or +sizeK (57368-65399, default 65399): +1000M

Command (m for help): n
Command action
   l   logical (5 or over)
   p   primary partition (1-4)
l
First cylinder (57491-65399, default 57491):
Using default value 57491
Last cylinder or +size or +sizeM or +sizeK (57491-65399, default 65399): +1000M

Command (m for help): n
Command action
   l   logical (5 or over)
   p   primary partition (1-4)
l
First cylinder (57614-65399, default 57614):
Using default value 57614
Last cylinder or +size or +sizeM or +sizeK (57614-65399, default 65399): +1000M

Command (m for help): p
Disk /dev/sda: 537.9 GB, 537932857344 bytes
255 heads, 63 sectors/track, 65399 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1       50993   409601241   83  Linux
/dev/sda2           50994       57367    51199155   82  Linux swap / Solaris
/dev/sda4           57368       65399    64517040    5  Extended
/dev/sda5           57368       57490      987966   83  Linux
/dev/sda6           57491       57613      987966   83  Linux
/dev/sda7           57614       57736      987966   83  Linux

Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.
  • Mandatory – run partprobe command to save all changes made .
[root@dhcppc6 ~]# partprobe /dev/sda
  • Take all partitions and make pv( physical volume ) over these partitions .
  • Type pvcreate and partitions name  that you want to make physical volume .
[root@dhcppc6 ~]# pvcreate /dev/sda5 /dev/sda6 /dev/sda7
  Wiping software RAID md superblock on /dev/sda5
  Physical volume "/dev/sda5" successfully created
  Wiping software RAID md superblock on /dev/sda6
  Physical volume "/dev/sda6" successfully created
  Wiping software RAID md superblock on /dev/sda7
  Physical volume "/dev/sda7" successfully created
  • To check physical volume type pvs command .
  • Here you will find partitions that are included in physical volumes
[root@dhcppc6 ~]# pvs
  PV         VG   Fmt  Attr PSize   PFree
  /dev/sda5  vg00 lvm2 a-   964.00M 464.00M
  /dev/sda6  vg00 lvm2 a-   964.00M 464.00M
  /dev/sda7  vg00 lvm2 a-   964.00M 964.00M
  • Create vg ( volume groups ) including physical volumes
  • Type vgcreate  name of vg, like vg00 is name that i have given .
  • Then physical volumes name .
[root@dhcppc6 ~]# vgcreate vg00 /dev/sda5 /dev/sda6 /dev/sda7
  Volume group "vg00" successfully created
  • To check vg (volume group ) exist in your system or not type vgs command .
  • You can see vg00 has been created .
[root@dhcppc6 ~]# vgs
  VG   #PV #LV #SN Attr   VSize VFree
  vg00   3   2   0 wz--n- 2.82G 1.85G
  • Now its time to create logical volumes .(lvm)
  • In this type lvcreate -L then give size of logical volumes
  • Then -n   name of logical volume like i have created lv1  after that vgname (vg00)
[root@dhcppc6 ~]# lvcreate -L +500M -n lv1 vg00
  Logical volume "lv1" created
[root@dhcppc6 ~]# lvcreate -L +500M -n lv2 vg00
  Logical volume "lv2" created
  • To check lvm type lvs command .
  • You can find lv1 and lv2 , what we created just now.
[root@dhcppc6 ~]# lvs
  LV   VG   Attr   LSize   Origin Snap%  Move Log Copy%  Convert
  lv1  vg00 -wi-a- 500.00M
  lv2  vg00 -wi-a- 500.00M

Now there are two ways to mount lvm

  • Mount on any folder
  • Mount on swap

I’m going to mount lv1 on folder and lv2 on swap

  1. HOW TO MOUNT LVM ON FOLDER
  • First format the lv1 (/dev/vg00/lv1)
[root@dhcppc6 ~]# mkfs.ext3 /dev/vg00/lv1
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
  • Then i’m going to mount it on folder
  • To mount  type  =    mount    /dev/vgname/lvname   foldername
  • 3usageeks is my folder
  • To check type df  -h command
[root@dhcppc6 ~]# mount /dev/vg00/lv1 3usageeks/
[root@dhcppc6 ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda1             379G  8.5G  351G   3% /
tmpfs                 947M     0  947M   0% /dev/shm
/dev/mapper/vg00-lv1  485M   11M  449M   3% /root/3usageeks
  1. NOW HOW TO MOUNT LVM ON SWAP
  • Format lvm (lv2)
[root@dhcppc6 ~]# mkswap /dev/vg00/lv2
Setting up swapspace version 1, size = 524283 kB
  • Activate the swap by =  swapon  /dev/vgname/lvname 
  • To check type  cat  /proc/swaps command
[root@dhcppc6 ~]# swapon /dev/vg00/lv2
[root@dhcppc6 ~]# cat /proc/swaps
Filename                                Type            Size    Used    Priority
/dev/sda2                               partition       51199144        0       -1
/dev/mapper/vg00-lv2                    partition       511992  0       -2

But that was temporary mounting , means it will be lost when system reboots .

  • For permanent mounting  open fstab file
[root@dhcppc6 ~]# vim /etc/fstab
  • Make entry as shown below .
  • Both type of entry i have shown below .
/dev/vg00/lv1           3usageeks               ext3    defaults         0 0
/dev/vg00/lv2           swap                    swap    defaults          0 0
  • Press ESC then type :wq ( to save and quit )
~
~
:wq

 

One thought on “WHAT IS LVM AND HOW TO CONFIGURE LVM IN LINUX .

  1. Kavin says:

    What’s up i am kavin, its my first time to commenting
    anyplace, when i read this piece of writing i thought i could also make comment due to this sensible article.

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s