HOW TO CONFIGURE LVM OVER RAID AND SWAP OVER LVM IN LINUX

In this post we will learn how to configure Lvm over raid and swap over lvm in linux

swap over lvm over raid in linux

  • First create two partitions of equal size .
  • Command t ( to change partition type )
  • Hex code  – fd  ( linux raid )
  • Command  w  ( to save )
[root@localhost ~]# fdisk /dev/sda
Command (m for help): n
Command action
   l   logical (5 or over)
   p   primary partition (1-4)
l
First cylinder (57368-68514, default 57368):
Using default value 57368
Last cylinder or +size or +sizeM or +sizeK (57368-68514, default 68514): +1000M

Command (m for help): n
Command action
   l   logical (5 or over)
   p   primary partition (1-4)
l
First cylinder (57491-68514, default 57491):
Using default value 57491
Last cylinder or +size or +sizeM or +sizeK (57491-68514, default 68514): +1000M
Command (m for help): t
Partition number (1-6): 6
Hex code (type L to list codes): fd
Changed system type of partition 6 to fd (Linux raid autodetect)
Command (m for help): t
Partition number (1-6): 5
Hex code (type L to list codes): fd
Changed system type of partition 5 to fd (Linux raid autodetect)
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@localhost ~]# partprobe /dev/sda
  • Now create raid 1  .
  • –level =1 ( raid 1)  .
  • Then add two partitions sda5 & sda6
[root@localhost ~]# mdadm --create /dev/md1 --level=1 --raid-devices=2 /dev/sda5 /dev/sda6
mdadm: array /dev/md1 started.
  • We will convert raid into pv ( physical volume )
[root@localhost ~]# pvcreate /dev/md1
  Physical volume "/dev/md1" successfully created
  • Over pv ( physical volume ) create vg ( volume group )
[root@localhost ~]# vgcreate vg11 /dev/md1
  /dev/hdc: open failed: No medium found
  Volume group "vg11" successfully created
  • Now create LVM over volume group .
[root@localhost ~]# lvcreate -L +300M -n lv1 vg11
  Logical volume "lv1" created
[root@localhost ~]# lvcreate -L +300M -n lv2 vg11
  Logical volume "lv2" created

There are two ways to mount. 

  1. Mount lvm on folder 
  2. Swap over lvm 

I’m going to show both ways that’s why i have created two lvm

lv1 will be mounted on folder 

lv2 will be mounted on swap .

First we will learn how to mount lvm  on folder

  • Format the lv1
[root@localhost ~]# mkfs.ext3 /dev/vg11/lv1
  • Then mount lv1 on folder you like .
  • To mount type    –    mount   lvmname    foldername 
  • 3usageeks is my folder name .
  • You can check by df  -h command .
[root@localhost ~]# mount /dev/vg11/lv1 3usageeks
[root@localhost ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda1             379G  7.4G  352G   3% /
tmpfs                 972M     0  972M   0% /dev/shm
/dev/mapper/vg11-lv1  291M   11M  266M   4% /root/3usageeks

 

NOW  HOW TO CONFIGURE SWAP OVER LVM OVER RAID

  • First format the lvm 2
  • Then activate the lvm 2
[root@localhost ~]# mkswap /dev/vg11/lv2
Setting up swapspace version 1, size = 314568 kB
[root@localhost ~]# swapon /dev/vg11/lv2
  • Check by   cat  /proc/swaps   command
[root@localhost ~]# cat /proc/swaps
Filename                                Type            Size    Used    Priority
/dev/sda2                               partition       51199144        0       -1
/dev/mapper/vg11-lv2                    partition       307192  0       -2

 

BUT THAT WAS TEMPORARY MOUNTING

Means mounting will be lost when system reboots

  • For permanent mounting go to /etc/fstab file  through vim
[root@localhost ~]# vim /etc/fstab
  • Now both types of entry i have shown below . Press I ( to go to insert mode )
/dev/vg11/lv1           3usageeks               ext3    defaults        0 0
/dev/vg11/lv2           swap                    swap    defaults        0 0

mounting in linux

  • Press ESC and type :wq ( to save and quit )
~
~
~
~
~
:wq

 

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