Tutorial: Disk Drive: Loop back device

Tools: losetup, gdisk, mkfs.ext4
File as a filesystem / Filesystem in a file
create a file

dd if=/dev/zero of=virt_fs.img bs=1024 count=10240

bytes=1024 (1KB)
count=10240
total = 1024*10240 = 10485760 Bytes (10MB)
or

dd if=/dev/zero of=virt_fs.img bs=1M count=10

or

truncate -s 10M virt_fs.img

Setup loop-back device
find first available loop-back device

sudo losetup -f

create loop back device (using first available loop-back device and file)

sudo losetup /dev/loop0 virt_fs.img

Check status of loop-back devices

sudo losetup -a

Format the device
(Partitioning is optional)

mkfs.ext3 -L virtFileSystem /dev/loop0

Mount device
make mount point

mkdir virtFS

mount loop-back device

sudo mount -t ext3 /dev/loop0 virtFS

CLI o/p
testUser@testBench:~$ dd if=/dev/zero of=virt.fs.img bs=1M count=10
10+0 records in
10+0 records out
10485760 bytes (10 MB) copied, 0.0197492 s, 531 MB/s
testUser@testBench:~$ sudo losetup -f
[sudo] password for testUser:
/dev/loop0
testUser@testBench:~$ sudo losetup /dev/loop0 virt.fs.img
testUser@testBench:~$ sudo losetup -a
/dev/loop0: [0806]:1608731 (/home/testUser/virt.fs.img)
testUser@testBench:~$ mkdir Virt.FS
testUser@testBench:~$ sudo mkfs.ext3 -L VirtFS /dev/loop0
mke2fs 1.42.9 (4-Feb-2014)
Discarding device blocks: done
Filesystem label=VirtFS
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
2560 inodes, 10240 blocks
512 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=10485760
2 block groups
8192 blocks per group, 8192 fragments per group
1280 inodes per group
Superblock backups stored on blocks:
8193
Allocating group tables: 0/2 done
Writing inode tables: 0/2 done
Creating journal (1024 blocks): done
Writing superblocks and filesystem accounting information: 0/2 done
testUser@testBench:~$ sudo mount -t ext3 /dev/loop0 Virt.FS
testUser@testBench:~$ df -h /home/testUser/Virt.FS
Filesystem Size Used Avail Use% Mounted on
/dev/loop0 8.7M 97K 8.1M 2% /home/testUser/Virt.FS
testUser@testBench:~$ exit

Leave a comment

Your email address will not be published. Required fields are marked *