Administration toolsLinux

What is Ext2, Ext3 & Ext4 and how to create and convert Linux File systems

A filesystem is a way of storing, organizing and accessing files (and/or directories) on a storage device. Some examples of filesystems are FAT, NTFS for Windows/DOS, HFS for MAC OS etc. In Linux, the popular filesystems are ext2, ext3 and ext4 file systems. Some other filesystems such as ReiserFS are also natively supported by Linux. This article discusses various features of extended filesystems in Linux, i.e. ext2, ext3 and ext4.

ext2 – Second Extended Filesystem

• Developed by Remi Card
• Introduced in January 1993
• Replacement for extended filesystem
• Maximum file size: 16GiB – 2TiB, depending upon block size (1K, 2K, 4K or 8K)
• Maximum volume/filesystem size: 2TiB – 32TiB
• Maximum filename length: 255 bytes (255 characters)
• Maximum number of files: 10^18
• Filenames: All characters except NULL(‘\0’) and ‘/’ are allowed in a file name
• Date range: December 14, 1901 – January 18, 2038

ext3 – Third Extended Filesystem

• Developed by Stephen Tweedie
• Introduced in November 2001 (with Linux 2.4.15)
• Journaled filesystem.
• An ext2 filesystem can be converted to ext3 without any need of backup.
• Maximum file size: 16GiB – 2TiB
• Maximum volume/filesystem size: 2TiB – 32TiB
• Maximum filename length: 255 bytes (255 characters)
• Maximum number of files: Variable
• Filenames: All characters except NULL(‘\0’) and ‘/’ are allowed
• Date range: December 14, 1901 – January 18, 2038

ext4 – Fourth extended filesystem

• Developers: Mingming Cao, Andreas Dilger, Alex Zhuravlev (Tomas), Dave Kleikamp, Theodore Ts’o, Eric Sandeen, Sam Naghshineh and others (from wikipedia.org)
• Introduced in October 2008 (stable)
• Journaled filesystem
• Performance enhancements over its predecessor (ext3)
• Maximum file size: 16TB
• Maximum volume/filesystem size: 1EIB (exabyte) (1Eib = 1024PiB, 1PiB = 1024TiB, 1TiB = 1024GiB)
• Maximum filename length: 255 bytes (255 characters)
• Maximum number of files: 4 billion
• Filenames: All characters except NULL(‘\0’) and ‘/’ are allowed
• Date range: December 14, 1901 – April 25, 2514
• Total filesystem check time improved (fsck time)

Creating an ext2, or ext3, or ext4 filesystem

Once you’ve partitioned your hard disk using fdisk command, use mke2fs to create either ext2, ext3, or ext4 file system.

Create an ext2 file system

# mke2fs /dev/sdxx

Create an ext3 file system

# mkfs.ext3 /dev/sdxx
(or)
# mke2fs –j /dev/sdxx

Create an ext4 file system

# mkfs.ext4 /dev/sdxx
(or)
mke2fs -t ext4 /dev/sdxx

How to convert Linux file systems

How to Determine File System Type?

To determing your Linux file system type, run the following command in a terminal as a root user.

# df -hT | awk '{print $1,$2,$NF}' | grep "^/dev"
/dev/sda1 ext4 /
/dev/sda2 ext4 /home

Converting ext2 to ext3

For example, if you are upgrading /dev/sda2 that is mounted as /home, from ext2 to ext3, do the following.

# umount /dev/sda2
# tune2fs -j /dev/sda2
# mount /dev/sda2 /home

Converting Ext2 to Ext4 To convert from old ext2 to new ext4 file system with latest journaling feature. Run the following command.

# tune2fs -O dir_index,has_journal,uninit_bg /dev/sda2

Next do a complete file system check with e2fsck command to fix and repair.

# e2fsck -pf /dev/sda2

-p option automatically repairs the file system.
-f option force checking file system even it seems clean.

Converting ext3 to ext4

If you are upgrading /dev/sda2 that is mounted as /home, from ext3 to ext4, do the following.

# umount /dev/sda2
# tune2fs -O extents,uninit_bg,dir_index /dev/sda2
# e2fsck -pf /dev/sda2
# mount /dev/sda2 /home

Again, try all of the above commands only on a test system, where you can afford to lose all your data.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Close
Close