Files containing file systems

Sometimes it is desirable to put files into a file system, that can be mounted.

Examples are initial ram disc for the boot, preparation contents of a CD, backup of a memory device.

Here the steps:

Create a file in current directory of bs size filled with zeros (see dd)

dd if=/dev/zero of=<filename> bs=3000k count=1

Format it as file system

mke2fs -F -m0<filename>

Mount the file as device (Note: The kernel must support loop devices)

mount -t ext2 -o loop<filename> /mnt/<mountpoint>

Now everything can be copied there. If finished unmount it.

umount /mnt/<filename>

When it will be distributed then it is probably worth to zip it.

gzip -9<filename>

When be used on a later stage, unzip and mount it:

mount -t ext2 -o loop<filename> /mnt/<mountpoint>

Linurs Hosttech startpage