Aug 262014
 
Article Server Administration

There are several scenarios where a filesystem contained in a single file might come handy.

This post explains how to set up that kind of configuration on a Debian Linux system. The procedure explained here can also be applied to other Linux distros, such as Ubuntu.

Introduction

A computer is usually equipped with one or more physical disks, each of which is divided into several partitions. Under Linux, each partition contains a file system of a given type (excluding the partitions used as swap areas, or other special purposes).

On a production system, we might not have the possibility to modify the configuration of disks, partitions and file systems, due to limitations imposed by our hosting provider, or to other reasons. But, by using a file as a “virtual” filesystem, we have complete freedom to create last generation filesystems such as zfs or btrfs, with advanced features such as encryption, data compression, etc.

Besides, having a whole filesystem in a file enhances the portability, because moving the information to a new system becomes a matter of copying a single file.

Create the container file

1. Create a 1 GB file named “linux.ex2” de 1 GB:

2. Create the filesystem inside the container

In this example, the mke2fs command with adequate options is used to create the desired filesystem type

In the example above, the new filesystem has been created with 8 block groups of  16384 inodes, for a total of 131072 inodes. Besides, option “-j” resulted in the creation of a journaling filesystem.

Mount the filesystem

The same mount command used to mount filesystems created in physical disk partitions can be used with option ” -o loop=/dev/loop0″ to mount a filesystem created in a file container:

References

Wikipedia: The Loop Device

 Posted by at 11:41 am

 Leave a Reply

(required)

(required)