Wednesday, October 7, 2009

Virtual File Systems: For Fun, Security, and Profit

Assumptions:  Your OS is Linux.
Do you need to bring up an FTP or NFS server on an existing system but want to keep things separated? Do you wanted to have a portable file system you can take with you? Do you want to "hide" things but are not worried about encryption? With Linux it is possible and easy. Here’s how.

Creating a virtual file system.

Assumptions: You have a large file system with plenty of free space. For this example, we’ll assume this file system is mounted on /home and there is well over 20GB of free space available.

Make a file in your home directory called portable.ext3 (you can call it whatever you want).
# touch /home/bob/portable.ext3

Now, let’s make this file a 16GB “empty” file. What you say? That’s right. We are going to take the file portable.ext3 and make is 16GB is size but completely empty. How?
# dd if=/dev/zero of=/home/bob/portable.ext3 bs=16G count=1
So we are creating a file with a 16GB block size at a count of 1. So… 1 block, 16GB in size.

We now have an “empty” 16GB file. Let’s format it.

Wait a minute. It is a file. You can’t format it.

Yes we can.
# mkfs.ext3 /home/bob/portable.ext3
You may get a warning, but it can be ignored.

So now we have a 16GB file that has been formatted as an ext3 filesystem.

What is left to do? Mount it.
Create an empty directory so you can mount the filesystem.
# mkdir -p /home/bob/mntdir (you can call the directory whatever you want).

Now let’s mount it.
# mount –o loop,rw /home/bob/portable.ext3 /home/bob/mntdir

Ta-Da. Do a “df -h” and you should see your “new” 16GB filesystem.

What can you do with it? You can share it out using NFS. Have it as your FTP root. Or (assuming you are going to unmount it first) copy it to a large enough flash drive and take it to a different linux system. If you are not going to move it between systems, and it will only live on one box, you may want to edit your /etc/fstab so that it will be mounted the next time the system reboots.

No comments:

Post a Comment