Linux File System
I just wanted to share this “very basics” of Linux file system for all the beginners.
Understand what is a file system?
A file system is an organization of data and metadata on a storage device. With this technical jargon you can conclude that the Linux file system interface is implemented as a layered architecture, separating the user interface layer from the file system implementation from the drivers that manipulate the storage devices.
Another way to think about a file system is as a protocol. Like you have network protocols (such as Internet Protocol (IP) ) give meaning to the streams of data traversing the Internet, file systems give meaning to the data on a particular storage medium.
Now what is Mounting?
Associating a file system to a storage device in Linux is a process called mounting. The mount command is used to attach a file system to the current file system hierarchy (root). During a mount, you provide a file system type, a file system, and a mount point.
To illustrate the capabilities of the Linux file system layer (and the use of mount), create a file system in a file within the current file system. This is accomplished first by creating a file of a given size using dd (copy a file using /dev/zero as the source) — in other words, a file initialized with zeros, using dd command.
dd if=/dev/zero of=/DATA/zebra bs=1k count=500
Here I am creating a file filled with zeros under /DATA with the name of zebra of size 500k.
Now use the losetup command to associate a loop device with the file thus making it look like a block device instead of just a regular file within the file system.
losetup /dev/loop0 /DATA/zebra
Once it is done, now create a file system on the device with mke2fs. This command creates a new second ext2 file system of the defined size.
mke2fs -c /dev/loop0 500
(you can also use mkfs.ext4)
Now you know you need to create a location for mounting it.
Once done, now mount it using mount command.
mount /dev/loop0 /mnt/zebra
Finally check it using df -h command. You can see that your file is actually showing itself as a block device.
Hope you are able to understand that how powerful the Linux file system (and the loop device) can be. You can use this approach to create encrypted file systems with the loop device on a file. This is useful to protect your data by transiently mounting your file using the loop device when needed.
Below is a illustration of the same hack from my machine.