Creating a file system on a file in Linux.

Creating a file system on a file in Linux


Home

This page explains how to create a file that is interpreted as a file system in Linux, so you can have an extra space in your Linux system without repartitioning the hard disk wich let's you create symbolic and hard  links and have user information and file permissions.

  1. Be sure you have the loop module in your kernel, it doesn't works without it.
    This step is not forced to be the first, it can be the last, but it's absolutely necessary if you don't have the loop module in your kernel.

    To recompile the kernel install the kernel sources and set the current directory to that where the sources are:
    make clean
    make xconfig:Find the loop modules and activate it to Yes. The question about the loop device is in the option "block devices".
    then:make zlilo or make zdisk  or make zimage.
    make modules
    make modules_install.

    You can recompile the kernel being sure you added the loop module to it, or if it is too complicated for you, you can add a line to the file /etc/conf.modules:alias loop loop .
     

  2. :Create the file that will have the filesystem:
    dd if=/dev/zero of="filename Ej:/mnt/dosc/linux/ext2filemount.e2" count="number of 512 bytes blocks"

  3. Create the filesystem into the file.
    mkfs -t ext2 filename : the same filename as before.

  4. Configuring the system to mount it.
    edit the file /etc/fstab and add a line to it as this:
    filename mountpoint  fstype(ext2)  loop 0 0
    where mountpoint is the directory where the file will be mounted Ej(/mnt/cext2) and fstype is the file system type you specified to mkfs Ej(ext2).

    Then restarting the computer if you have done all well and have the loop module in your kernel will mount the filesystem on the file as a directory on your system.