Get Firefox!

Home Free Software Faq Blog GNU/Linux Faq Free Media Faq's NRI Faq Immigration Faq Plea for Action Notes My P2P Search Portal About me..

Sat, 30 Aug 2008

Creating Virtual Drives in Linux without VMware

Have you ever found the need to keep all the thousands of files which you use in a single file.
On Linux there is a way to do that.So essentailly you can have a virtual drive in a file which has an entire filesystem.
And to Linux it does not appear any different then an ext3 on a actual physical hard drive or a partition.
The implications of this are very huge, so for example you want to share some data with any one which has hundreds of files etc or you want to just backup your entire filesystem.
Here is how to achieve this

dd if=/dev/zero of=mydatafile bs=1 count=1 seek=1M

Will create a file of one megabyte in size, but with only one byte
actually stored on disk.

The convert that file into a ext3 partition by issuing the following command

mkfs.ext3 mydatafile

It will give a warning,say yes and let it proceed.
 
mke2fs 1.40-WIP (14-Nov-2006)
sparse-file is not a block special device.
Proceed anyway? (y,n) y

Then you can just mount the file as a filesystem/partition anywhere with the following command

mount -t ext3 -o loop mnt/mnt_point mydatafile

Now you can just do anything in the /mnt/mnt_point and then you can even move it to another machine 1 single file and you have all your data there.



Another example is dd if=/dev/zero of=mydatafile bs=1024 count=1024 to create a file of 1MB though it is not a true sparse file, the better definition of this file would be a virtual drive of fixed size of 1MB.

posted at: 16:18 | category: /linux | permanent link to this entry