HOW TO CONFIGURE LOOP DEVICE IN LINUX .

In this article i will show you how to configure loop device in linux .

Loop device is a  file that is accessible as a block device . The file may then be mounted  as if it were a disk device.

HOW TO CONFIGURE LOOP DEVICE :

  • First i’m gonna create three files . You can create any file like it can be also pdf etc .
[root@dhcppc6 ~]# touch deepit.txt
[root@dhcppc6 ~]# touch rahul.txt
[root@dhcppc6 ~]# touch hemendra.txt
  • Then i’m going to give this file a size through dd (disk dumping) .
  • I have given every file 1000MB size  .
[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, 19.9902 seconds, 52.5 MB/s

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

[root@dhcppc6 ~]# dd if=/dev/zero of=hemendra.txt bs=1M count=1000
1000+0 records in
1000+0 records out
1048576000 bytes (1.0 GB) copied, 18.0577 seconds, 58.1 MB/s
  • Then we will make this file loop device .
  • To Make file loop device type  =   losetup    loopname   filename
[root@dhcppc6 ~]# losetup /dev/loop2 deepit.txt
[root@dhcppc6 ~]# losetup /dev/loop3 rahul.txt
[root@dhcppc6 ~]# losetup /dev/loop4 hemendra.txt
  • Check by below command
[root@dhcppc6 ~]# losetup -a
/dev/loop2: [0801]:62488638 (deepit.txt)
/dev/loop3: [0801]:62488639 (rahul.txt)
/dev/loop4: [0801]:62488640 (hemendra.txt)
  • Then we have to mount these loops . But before mounting we have to format it first .
[root@dhcppc6 ~]# mkfs.ext3 /dev/loop2
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
128000 inodes, 256000 blocks
12800 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=264241152
8 block groups
32768 blocks per group, 32768 fragments per group
16000 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376
Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 34 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

[root@dhcppc6 ~]# mkfs.ext3 /dev/loop3
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
128000 inodes, 256000 blocks
12800 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=264241152
8 block groups
32768 blocks per group, 32768 fragments per group
16000 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376
Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 38 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

[root@dhcppc6 ~]# mkfs.ext3 /dev/loop4
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
128000 inodes, 256000 blocks
12800 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=264241152
8 block groups
32768 blocks per group, 32768 fragments per group
16000 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376
Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 34 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
  • Now we can mount these loop devices .
  • Create folder where you want to mount
  • TO mount type  =    mount   loopname     foldername 
[root@dhcppc6 ~]# mount /dev/loop2 3usageeks
[root@dhcppc6 ~]# mount /dev/loop3 3usageeks1
[root@dhcppc6 ~]# mount /dev/loop4 3usageeks2
  • Check by df  -h command
[root@dhcppc6 ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda1             379G  8.6G  351G   3% /
tmpfs                 972M     0  972M   0% /dev/shm
/dev/loop2            985M   18M  918M   2% /root/3usageeks
/dev/loop3            985M   18M  918M   2% /root/3usageeks1
/dev/loop4            985M   18M  918M   2% /root/3usageeks2

But that was temporary mounting , your mounting will be lost once system reboots .

For permanent mounting go to fstab through vim

[root@dhcppc6 ~]# vim /etc/fstab
  • Press ”  I  ”  and make entry as shown below
/dev/loop2              /root/3usageeks         ext3    defaults        0  0
/dev/loop3              /root/3usageeks1        ext3    defaults        0 0
/dev/loop4              /root/3usageeks2        ext3    defaults        0 0
  • 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