In this article we are going to learn how to configure loop device. But first we will checkout what loop device really 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 .

Now to configure follow these steps:

  • First we create a file
root@dhcppc2 ~]# touch a .txt
  •  Now we give this file a size .
[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, 17.1456 seconds, 61.2 MB/s
  • After giving this file size we have to convert this file into partition (loop device)
[root@dhcppc2 ~]# losetup /dev/loop0 a.txt
  • To check whether its been created or not you can type
[root@dhcppc2 ~]# losetup -a

/dev/loop0: [0801]:618408 (a.txt)
  • Now we will mount this loop device but before mounting create a folder where you want to mount and format it before mounting. Then mount
[root@dhcppc2 ~]# mkdir B

[root@dhcppc2 ~]# mkfs.ext3 /dev/loop0
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 20 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

[root@dhcppc2 ~]# mount /dev/loop0 B
  • for checking whether its been mounted or not type
[root@dhcppc2 ~]# df -h

Filesystem            Size  Used Avail Use% Mounted on
/dev/sda1              15G  3.5G   10G  26% /
tmpfs                 506M     0  506M   0% /dev/shm
/dev/loop0            985M   18M  918M   2% /root/B



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 )

Google+ photo

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

Connecting to %s