Can we create a file system (i.e. formatting a drive/partition) with in a file system?
Looks little bit strange is int it? So follow me I will show you how to create a virtual partition and file system within a partition.

Step1 : Create a empty file with /dev/zero with size equal to 50Mb.
#dd if=/dev/zero of=/temp/vf0 count=102400

Note :

1. By default “dd” command(dataset definition) uses block of 512bytes so the size will be 102400*512=52 428 800=~50MB
2. /dev/zero is a device files which will be used create a file which conations “0” i.e. an empty

Clipped output:
[root@test6 ~]# dd if=/dev/zero of=/temp/vf0 count=102400
102400+0 records in
102400+0 records out
[root@test ~]# ls -lh /temp/vf0
-rw-r–r– 1 root root 50M Nov 7 12:08 /temp/vf0

Step2 : Create ext3 file system for this virtual partition.
#mkfs -t ext3 /temp/vf0

Here it will ask “do you want to format the file or not”?, just say yes.

Step3 : Now we have to create a mount point (nothing but a directory) and mount the created partition.
# mkdir /virtdrive
# mount -o loop=/dev/loop0 /temp/vf0 /virtdrive


/dev/loop is special hardware device used to mount ISO files and virtual file systems. In Linux there are total 8 loop devices numbering from 0 to 7. So you can mount only 8 ISO files/virtual file systems by default.

Step4 : Edit /etc/fstab file to mount permanently, so that it be auto mounted at boot time too. Specify following entry in fstab file.
/temp/vf0 /virtdrive ext3 rw,loop=/dev/loop0 0 0

Step5 : Specify the fstab changes to kernel.
#mount -a

Step6 : Conform Weather mounting happen perfectly or not.

Way1 :
#cat /etc/mtab

Way2 : Change the directory to mount point you have to see lost+found folder
[root@test ~]# cd /virtdrive/
[root@test virtdrive]# ls
[root@test virtdrive]#

Please comment your thoughts regarding this post:-)

Reblog this post [with Zemanta]