Linux file systems

The most commonly used file systems in Linux is ext2, ext3, and ext4. ext3 and ext4 are similar to ext2 but have journaling feature that keeps track of what is written to the disk and might be helpful after a system crash. .

Those file systems are not directly accessed by the kernel. VFS the Virtual File System is a layer between the kernel and the real file system to get flexibility. Therefore it is possible to have support different file systems, but also RAID.

As usual bytes for a block. Blocks are further grouped to block groups. Those block groups contain other data as: a copy of the superblock, the block group descriptor table that defines the block bitmap, an inode bitmap, and an inode table.

Every file or directory is represented by an inode. The inode contains the description of the file: file type, access rights, owners, timestamps, size. Additionally the inode holds pointers:

  1. 12 pointers that point directly to blocks that hold data.

  2. The 13st pointer points to a block that does not hold data but holds pointers to additional blocks. It is therefore called an indirect block.

  3. The 14st pointer that points to a block that points to other indirect blocks. It is therefore called a doubly-indirect block.

  4. The 15st pointer that points to doubly-indirect blocks. It is therefore called a trebly-indirect block

The reason for this rather complicated structure is that small files can be accessed fast without a lot of addressing overhead and still support large files.

Directories are handled by special files holding directory entries that define the file and directory names and there inode number that contains the data. This separation allows to have links. The root directory is in inode number 2, to find the way how to read the directory tree.

After created a partition with fdisk type 83, the partition needs to be formated:

mkfs.ext2, mkfs.ext3 or mkfs.ext4 do that

To see what you have: tune2fs -l /dev/<your drive>

e2label /dev/<disk> shows the label

e2label /dev/<disk><name> sets it

tune2fs -L <name> /dev/<disk> sets the label too

tune2fs -l /dev/sda10 to see

tune2fs -c 4 /dev/sda10 to force checking after 4 mounts

tune2fs -i 2d /dev/sda10 to force checking after 2 days

dumpe2fs /dev/sda1 to see information about the filesystem

Copy filesystems

Filesystems can be easily copied using cat as cat /dev/sda1 > /dev/sdb1 since the sizes of the disks partitions might be different the filesystem can be expanded to cover the complete space: resize2fs /dev/sdb1

Partitions can be copied using dd as dd if=/dev/sdb1 of=/dev/sdc1 and complete disks as dd if=/dev/sdb of=/dev/sdc and to not loose the master boot record: dd if=/dev/sda of=/backup/mbr.img bs=512 count=1

Linurs startpage