In this post we will learn how to configure lvm (logical volume management ) over RAID and RAID over loop devices in linux .

lvm over raid and raid over loop devices

  • First create two files .
[root@dhcppc6 ~]# touch deepit.txt
[root@dhcppc6 ~]# touch 3usageeks.txt
  • Now give this file a size through dd ( disk dumping )
  • I’m giving 1000MB to both file
[root@dhcppc6 ~]# dd if=/dev/zero of=deepit.txt bs=1M count=1000
1000+0 records in
1000+0 records out
1048576000 bytes (1.0 GB) copied, 9.68692 seconds, 108 MB/s
[root@dhcppc6 ~]# dd if=/dev/zero of=3usageeks.txt bs=1M count=1000
1000+0 records in
1000+0 records out
1048576000 bytes (1.0 GB) copied, 22.7716 seconds, 46.0 MB/s
  • Let’s convert these files into loop devices .
[root@dhcppc6 ~]# losetup /dev/loop1 deepit.txt
[root@dhcppc6 ~]# losetup /dev/loop2 3usageeks.txt
  • Check by below commands whether loop devices is been created or not
[root@dhcppc6 ~]# losetup -a
/dev/loop1: [0801]:62488635 (deepit.txt)
/dev/loop2: [0801]:62488638 (3usageeks.txt)
  • Now i’m going to create RAID0 over these two loop devices .
[root@dhcppc6 ~]# mdadm --create /dev/md0 --level=0 --raid-devices=2 /dev/loop1 /dev/loop2
mdadm: array /dev/md0 started.
  • Check whether its been created or not
  • Like md0 is been active on loop1 and loop2
[root@dhcppc6 ~]# cat /proc/mdstat
Personalities : [raid0]
md0 : active raid0 loop2[1] loop1[0]
      2047872 blocks 64k chunks
  • Now we will convert this raid into physical volume
[root@dhcppc6 ~]# pvcreate /dev/md0
  Physical volume "/dev/md0" successfully created
  • Create vg ( volume group ) over  pv( physical volumes )
[root@dhcppc6 ~]# vgcreate vg55 /dev/md0
  Volume group "vg55" successfully created
  • Type vgs to check volume group
[root@dhcppc6 ~]# vgs
  VG   #PV #LV #SN Attr   VSize VFree
  vg55   1   0   0 wz--n- 1.95G 1.95G
  • Then create lvm ( logical volume management ) over volume group
[root@dhcppc6 ~]# lvcreate -L +500M -n lv1 vg55
  Logical volume "lv1" created
[root@dhcppc6 ~]# lvcreate -L +700M -n lv2 vg55
  Logical volume "lv2" created
  • To check lvm type lvs
[root@dhcppc6 ~]# lvs
  LV   VG   Attr   LSize   Origin Snap%  Move Log Copy%  Convert
  lv1  vg55 -wi-a- 500.00M
  lv2  vg55 -wi-a- 700.00M

There are two ways to mount 

  1. Mount it on folder 
  2. Swap over lvm 

One lvm i will mount on folder and other one on swap

  • First format lv1 .
[root@dhcppc6 ~]# mkfs.ext3 /dev/vg55/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
Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 36 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
  • Create folder where you will mount
  • then mount lv1 to that folder
[root@dhcppc6 ~]# mkdir 3usageeks
[root@dhcppc6 ~]# mount /dev/vg55/lv1 3usageeks
  • Check by df -h command
[root@dhcppc6 ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda1             379G  6.7G  353G   2% /
tmpfs                 972M     0  972M   0% /dev/shm
/dev/mapper/vg55-lv1  485M   11M  449M   3% /root/3usageeks
  • Now we will mount lv2 on swap
  • Format lv2 .
[root@dhcppc6 ~]# mkswap /dev/vg55/lv2
Setting up swapspace version 1, size = 733999 kB
  • Activate swap on lv2
  • Check by cat  /proc/swaps
[root@dhcppc6 ~]# swapon /dev/vg55/lv2
[root@dhcppc6 ~]# cat /proc/swaps
Filename                                Type            Size    Used    Priority
/dev/sda2                               partition       51199144        0       -1
/dev/mapper/vg55-lv2                    partition       716792  0       -2

BUT THAT WAS TEMPORARY MOUNTING ( mounting will be lost when system reboots )

FOR PERMANENT MOUNTING  got to /etc/fstab

[root@dhcppc6 ~]# vim /etc/fstab
  • Press I ( insert mode )
  • MAke entry as shown below
  • I have shown you entries for both .
/dev/vg55/lv1           /root/3usageeks         ext3    defaults        0 0
/dev/vg55/lv2            swap                   swap    defaults        0 0
  • Press ESC and :wq ( to save and quit)





Leave a Reply

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

You are commenting using your 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