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
Partitioning is optional. Format to ext3 filesystem
mkfs.ext3 -L virtFileSystem /dev/loop0
Mount
Make a mount point
mkdir virtFS
Mount loop-back device
sudo mount -t ext3 /dev/loop0 virtFS
Log
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
awk (1) cryptsetup (1) dd (2) device (1) drive (1) encryption (2) ext (1) filesystem (1) firefox (1) grep (1) loop-back (1) losetup (1) mkfs (1) mount (1) protocol-handler (1) security (2) sed (1) ssh (3) stat (1) truncate (1) urandom (1)