Get Started Linux File Systems

Linux File Systems

Linux File System Mycodinglab

Linux File System Mycodinglab

Linux file systems exist to allow you to store, retrieve and manipulate data on a medium. File systems maintain an internal data structure (meta-data) that keeps all of your data organized and accessible. The structure of this meta-data imparts the characteristics of the file system. A Linux file system is accessed by a driver through the organized meta-data structure. When Linux boots it reads in /etc/fstab all the file systems that need to be mounted and checks if they are in a usable state.

When a power failure occurs Linux won’t be able to unmount the file system properly and some data in the cache won’t be synchronized on the media. As such, the meta-data may be corrupted.

Once you reboot the system, it will detect this and do a fsck to the full meta-data structure for a consistency check. This can take a very long time. Few minutes to few hours in proportion of the media size. Journaling a file system is adding a new data structure called a journal. This journal is on-disk and before each modification to the meta-data is made by the driver it is first written into the journal. Before each meta-data modification the journal maintains a log of the next operation.

Now, when a power failure occurs there is only the need to check the journal. A journaling file system recovery is very fast. It just needs to go through the logs and fix the latest operation. Journaling file system recovery can take only few seconds.

On a cluster systems, journaling allows to quickly recover a shared partition of a node that went down.

Different types of Linux File Systems

  • ext2: Old very stable Linux filesystem. Efficient for files larger than ~2-3K.
  • ext3: Journaling extension for ext2. Possible to move a filesystem back and forth between ext2 and ext3.
  • Reiserfs: Journaling file system. 8-15 time faster than ext2 when manipulating small files.
  • XFS: A powerfull journaling filesystem with possible quota and ACL
  • Msdos: MS-Windows FAT filesystem type. (mainly used for floppy)
  • Vfat: MS-Windows FAT filesystem type. (mainly used for large hdd partitions)
  • NTFS (ReadOnly but loop files): MS-Windows journaling filesystem
  • SMBFS: A filesystem to mount windows or samba sharing from Linux
  • NFS: Network File System

File System Tree

A Linux file system has one top directory called root (/) where all sub directories of the entire system is stored. The sub directories can be another partition, a remote directory, or a remote partition accessible through the network with NFS protocol.

  • /bin Common programs, shared by the system, the system administrator and the users.
  • /boot The startup files and the kernel, vmlinuz. In some recent distributions also grub data. Grub is the GRand Unified Boot loader and is an attempt to get rid of the many different boot-loaders we know today.
  • /dev Contains references to all the CPU peripheral hardware, which are represented as files with special properties.
  • /etc Most important system configuration files are in /etc, this directory contains data similar to those in the Control Panel in Windows
  • /home Home directories of the common users.
  • /initrd (on some distributions) Information for booting. Do not remove!
  • /lib Library files, includes files for all kinds of programs needed by the system and the users.
  • /lost+found Every partition has a lost+found in its upper directory. Files that were saved during failures are here.
  • /misc For miscellaneous purposes.
  • /mnt Standard mount point for external file systems, e.g. a CD-ROM or a digital camera.
  • /net Standard mount point for entire remote file systems
  • /opt Typically contains extra and third party software.
  • /proc A virtual file system containing information about system resources. More information about the meaning of the files in proc is obtained by entering the command man proc in a terminal window. The file proc.txt discusses the virtual file system in detail.
  • /root The administrative user’s home directory. Mind the difference between /, the root directory and /root, the home directory of the root user.
  • /sbin Programs for use by the system and the system administrator.
  • /tmp Temporary space for use by the system, cleaned upon reboot, so don’t use this for saving any work!
  • /usr Programs, libraries, documentation etc. for all user-related programs.
  • /var Storage for all variable files and temporary files created by users, such as log files, the mail queue, the prin

Create File Systems

To create a file system on a partition, use mkfs.

mkfs [options] -t [fstype] device [blocksize]

Common options:

  • -t: fstype: File system type.
  • -c : Check the device for bad blocks before building the filesystem.

The full partition will be ereased and organized to the type of filesystem requested. There is no undo command. The fstype possible are: msdos, ext2, ext3, reiserfs,minix,xfs

The blocksize allows to customize the block size for your filesystem.

Examples of how to create Linux File Systems

mkfs -t msdos /dev/fd0

Create extended file systems

To create a extended (ext2, ext3) filesystem on an partition, use mke2fs.

mke2fs [options] device [blocksize]

Common options:

  • -b: Specify the block sizefstype: File system type.
  • -c : Check the device for bad blocks before building the filesystem.
  • -j: Create the filesystem with an ext3 journal.
  • -L: Set the volume label for the filesystem.

With mke2fs it is possible to store the super-block the journal information on another device. Examples:

  • mkefs -b 2048 /dev/fd0 -L floppy
  • mkfs -V
  • mke2fs 1.26 (3-Feb-2002) Using EXT2FS Library version 1.263

Monitoring disk usage

To print the disk usage, use du.

du [options] [files...]

Common options:

  • -a: All files not just directories
  • -b: Print size in bytes
  • -c: Total
  • -h: Human readable format. (1K, 20M,…)


$ du -ch Documents

du -sk ~ # Sums up your total disk usage in kilobytes

du -ak ~ | sort -n | more # Display every file and its disk space in numerical order.

File Systems disk space

A filesystem is composed of a meta-data structure plus a list of blocks. To print the filesystem disk space usage, use df.

df [options] [files...]

Common options:

  • -a: All included filesystems with 0 blocks.
  • -t: Limit listing to a filesystem type.
  • -h: Human readable format. (1K, 20M,…)


$ df -t reiserfs -h

Checking file systems

To check file systems consistency, use fsck.

fsck [options] -t [fstype] device [fsck-options]

Common options:

  • -A: Go through the /etc/fstab file and try to check all file systems. Typically used at boot time from a script.
  • -t fslist: Specify the type of file system to be checked. With -A, only filesystems that match fslist are checked
  • -C: Display completion/progression bar.
Common fsck-options:
  • -a: Automatically repair.
  • -r: Interactively repair.


fsck -t msdos /dev/fd0 -a
fsck -t reiserfs /dev/hda2 -r

Checking extended file systems

To check extended filesystems consistency, use e2fsck.

e2fsck [options] device

Common options:

  • -b: Use an alternate super block filename.
  • -c: This option makes badblocks program to run and marks all the bad blocks.
  • -f: Force checking even if the filesystem seems clean.
  • -a or -p: Automatically repair.
  • -y: non-interactive mode


e2fsck -ay /dev/fd0
e2fsck -f /dev/hda2

Attach a filesystem

The mount command serves to attach the file system found on some device to the big file tree.

mount [options]
mount [options] [-t vfstype] [-o options] device dir

If the device or directory is listed in /etc/fstab you can use the following:

mount [options] [-o options [,...]] device | dir

Normally only root has the priviledge to mount devices unless it is specified in the /etc/fstab file. Examples:

Print all the mouted filesystems (/etc/mtab).


Mount devices or dirs listed in /etc/fstab.

mount -a

Mount /dev/hdc partition in read only mode without updating /etc/mtab.

mount -n -o ro /dev/hdc /mnt

Allow a user to mount the CDROM if the following line is in /etc/fstab:

/dev/cdrom /media/cdrom iso9660 ro,user,noauto,unhide

Detach file system

To detach a filesystem from the file tree, use umount.

umount [options]
umount [options] [-o options [,...]] device | dir

A busy filesystem cannot be unmounted.

  • Open files

  • Working directory of a process.


umount -a # Unmount devices or dirs listed in /etc/fstab.

umount /mnt # Unmount the filesystem attached to /mnt.

umount /media/cdrom  # Allow a user to unmount the CDROM if the following line is in /etc/fstab:

/dev/cdrom  /media/cdrom  iso9660  ro,user,noauto,unhide

Unix-like operating systems

Unix-like operating systems create a virtual file system, which makes all the files on all the devices appear to exist in a single hierarchy. This means, in those systems, there is one root directory, and every file existing on the system is located under it somewhere. Unix-like systems can use a RAM disk or network shared resource as its root directory.

Unix-like systems assign a device name to each device, but this is not how the files on that device are accessed. Instead, to gain access to files on another device, the operating system must first be informed where in the directory tree those files should appear. This process is called mounting a file system. For example, to access the files on a CD-ROM, one must tell the operating system “Take the file system from this CD-ROM and make it appear under such-and-such directory”. The directory given to the operating system is called the mount point – it might, for example, be /media. The/media directory exists on many Unix systems (as specified in the Filesystem Hierarchy Standard) and is intended specifically for use as a mount point for removable media such as CDs, DVDs, USB drives or floppy disks. It may be empty, or it may contain subdirectories for mounting individual devices. Generally, only the administrator may authorize the mounting of file systems. Read details…

You must be logged in to post a comment.

Proudly powered by WordPress   Premium Style Theme by
%d bloggers like this: