HOW TO CREATE RAID OVER LOOP DEVICE

In this article we are going to learn how to configure raid over loop devices . First we should know what loop device and raid actually is.

Loop device is basically a file which we convert into partition . Like we make raid on hard disk partition, sometimes we don’t have that much hard disk space and we want file to act as an entire file system so thus where loop device is used.

Raid also known as redundant array of inexpensive disks, is basically a data storage virtualization  technology that combines multiple physical disk drive components into a single logical units for the purposes of data redundancy.

raid over loop devices

 

Now follow these steps to configure it:

  • First we create two files 
[root@dhcppc2 ~]# touch a.txt
[root@dhcppc2 ~]# touch b.txt
  • Now we give size to this file and convert into loop devices.
[root@dhcppc2 ~]# dd if=/dev/zero of=a.txt bs=1M count=1000
1000+0 records in
1000+0 records out
1048576000 bytes (1.0 GB) copied, 18.6737 seconds, 56.2 MB/s

[root@dhcppc2 ~]# dd if=/dev/zero of=b.txt bs=1M count=1000
1000+0 records in
1000+0 records out
1048576000 bytes (1.0 GB) copied, 12.5773 seconds, 83.4 MB/s

[root@dhcppc2 ~]# losetup /dev/loop0 a.txt
[root@dhcppc2 ~]# losetup /dev/loop1 b.txt
  • You can check whether its been created or not.
[root@dhcppc2 ~]# losetup -a

/dev/loop0: [0801]:618408 (a.txt)
/dev/loop1: [0801]:618415 (b.txt)
  • Lets create raid over these loop devices
[root@dhcppc2 ~]# mdadm --create /dev/md0 --level=0 --raid-devices=2 /dev/loop0 /dev/loop1

mdadm: array /dev/md0 started.
  • Make a folder and mount this raid into that folder
[root@dhcppc2 ~]# mkdir A
[root@dhcppc2 ~]# mkfs.ext3 /dev/md0

mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
256000 inodes, 511968 blocks
25598 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=524288000
16 block groups
32768 blocks per group, 32768 fragments per group
16000 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912
Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 27 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

[root@dhcppc2 ~]# mount /dev/md0 A

[root@dhcppc2 ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda1              15G  5.5G  8.1G  41% /
tmpfs                 506M     0  506M   0% /dev/shm
/dev/md0              2.0G   35M  1.8G   2% /root/A
  •  Now create two files in folder A and give that file a size
[root@dhcppc2 ~]# cd A
[root@dhcppc2 A]# touch c.txt
[root@dhcppc2 A]# touch d.txt
[root@dhcppc2 A]# dd if=/dev/zero of=c.txt bs=1M count=500
500+0 records in
500+0 records out
524288000 bytes (524 MB) copied, 6.63543 seconds, 79.0 MB/s

[root@dhcppc2 A]# dd if=/dev/zero of=d.txt bs=1M count=500
500+0 records in
500+0 records out
524288000 bytes (524 MB) copied, 48.2354 seconds, 10.9 MB/s
  • Make these file also loop device and create raid taking these two loop device
[root@dhcppc2 A]# losetup /dev/loop2 c.txt

[root@dhcppc2 A]# losetup /dev/loop3 d.txt

[root@dhcppc2 A]# losetup -a

/dev/loop0: [0801]:618408 (a.txt)
/dev/loop1: [0801]:618415 (b.txt)
/dev/loop2: [0900]:12 (c.txt)
/dev/loop3: [0900]:13 (d.txt)
mdadm --create /dev/md1 --level=1 --raid-devices=2 /dev/loop2 /dev/loop3
mdadm: array /dev/md1 started.

You can check your both raid is active by

# cat   /proc/mdstat

Mount this raid in another folder.

So this how you could create raid over loop devices.

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