Wednesday, 13 January 2016

Linux File Systems: Ext2 vs Ext3 vs Ext4

Linux File Systems: Ext2 vs Ext3 vs Ext4

ext2, ext3 and ext4 are all filesystems created for Linux. This article explains the following:
  • High level difference between these filesystems.
  • How to create these filesystems.
  • How to convert from one filesystem type to another.

Ext2

  • Ext2 stands for second extended file system.
  • It was introduced in 1993. Developed by Rémy Card.
  • This was developed to overcome the limitation of the original ext file system.
  • Ext2 does not have journaling feature.
  • On flash drives, usb drives, ext2 is recommended, as it doesn’t need to do the over head of journaling.
  • Maximum individual file size can be from 16 GB to 2 TB
  • Overall ext2 file system size can be from 2 TB to 32 TB

Ext3

  • Ext3 stands for third extended file system.
  • It was introduced in 2001. Developed by Stephen Tweedie.
  • Starting from Linux Kernel 2.4.15 ext3 was available.
  • The main benefit of ext3 is that it allows journaling.
  • Journaling has a dedicated area in the file system, where all the changes are tracked. When the system crashes, the possibility of file system corruption is less because of journaling.
  • Maximum individual file size can be from 16 GB to 2 TB
  • Overall ext3 file system size can be from 2 TB to 32 TB
  • There are three types of journaling available in ext3 file system.
    • Journal – Metadata and content are saved in the journal.
    • Ordered – Only metadata is saved in the journal. Metadata are journaled only after writing the content to disk. This is the default.
    • Writeback – Only metadata is saved in the journal. Metadata might be journaled either before or after the content is written to the disk.
  • You can convert a ext2 file system to ext3 file system directly (without backup/restore).

Ext4

  • Ext4 stands for fourth extended file system.
  • It was introduced in 2008.
  • Starting from Linux Kernel 2.6.19 ext4 was available.
  • Supports huge individual file size and overall file system size.
  • Maximum individual file size can be from 16 GB to 16 TB
  • Overall maximum ext4 file system size is 1 EB (exabyte). 1 EB = 1024 PB (petabyte). 1 PB = 1024 TB (terabyte).
  • Directory can contain a maximum of 64,000 subdirectories (as opposed to 32,000 in ext3)
  • You can also mount an existing ext3 fs as ext4 fs (without having to upgrade it).
  • Several other new features are introduced in ext4: multiblock allocation, delayed allocation, journal checksum. fast fsck, etc. All you need to know is that these new features have improved the performance and reliability of the filesystem when compared to ext3.
  • In ext4, you also have the option of turning the journaling feature “off”.
Use the method we discussed earlier to identify whether you have ext2 or ext3 or ext4 file system.
Warning: Don’t execute any of the commands given below, if you don’t know what you are doing. You will lose your data!

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/sda1
Create an ext3 file system:
mkfs.ext3 /dev/sda1

(or)

mke2fs –j /dev/sda1
Create an ext4 file system:
mkfs.ext4 /dev/sda1

(or)

mke2fs -t ext4 /dev/sda1

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
Note: You really don’t need to umount and mount it, as ext2 to ext3 conversion can happen on a live file system. But, I feel better doing the conversion offline.

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.

If you enjoyed this article, you might also like..

  1. 50 Linux Sysadmin Tutorials
  2. 50 Most Frequently Used Linux Commands (With Examples)
  3. Top 25 Best Linux Performance Monitoring and Debugging Tools
  4. Mommy, I found it! – 15 Practical Linux Find Command Examples
  5. Linux 101 Hacks 2nd Edition eBook Linux 101 Hacks Book

Bash 101 Hacks BookSed and Awk 101 Hacks BookNagios Core 3 BookVim 101 Hacks Book
{ 27 comments… add one }
  • engel May 16, 2011, 3:14 am
    I have an external hard drive FAT32. How to convert to a file system readable ONLY from linux (i.e. Ubuntu 10.04) and OSX 10.4.11 and 10.6.7 but not windows (for security reason)?
  • Gaurav May 16, 2011, 3:47 am
    Gr8! This is very basic but important as well.
    ‘The Geek Stuff’ is very help full to understand nut n bolds of Linux.
    Keep it up!
  • Adam Żochowski May 16, 2011, 9:40 am
    The maximum size of the ext2/ext3/ext4 is just wrong. All of these systems split drive into small blocks (clusters). The blocks are never larger than 4kb. With 32bit addressing at 4kb per block gives us upper limit of 16TB for total file storage.
    Technically one could try to force blocks to be larger than 4kb, but this is not recommended, since most utilities are hard coded to 1kb/2kb and 4kb block sizes. (good luck having your system crash and no easy way to recover these files).
    Tso is working to get ext4 a larger addressing mode (48 or 64bit). Searching for 16TB ext4 limit on google reveals a plethora of people looking for a solution.
  • Júlio Hoffimann Mendes May 18, 2011, 10:34 am
    Hi Ramesh,
    Good summary of differences. :)
    Regards,
    Júlio.
  • Ashok May 18, 2011, 10:58 am
    Hi Ramesh,
    There is certainly a mistake on specification about number of sub-directories that can be created under a directory in ext4 files. You have mentioned it as 64,000 but its actually 6,40,000 (6 lakhs 40 thousands).
    I just tested by increasing the condition value in my script to 640,000 and it did created all the sub-directories.
  • yunus May 18, 2011, 10:24 pm
    Hi,
    All your documentation on linux are so helpful. I was wondering, if you could provide some documentation on linux servers hardening (centos latest version).
    Hope to hear from you on this.
    Regards
    Yunus
  • Rusty September 3, 2011, 9:07 pm
    @engel
    create an encrypted partition on your usb hdd using the instructions given here.
    There are several tools that allow windows to read ext2/3 and even ext4 file systems.
  • James Dashner September 19, 2011, 12:54 pm
    EXT4 already has 48 bit block addressing.
  • Eugene White November 8, 2011, 9:25 am
    this is a very good explanation of Ext2, Ext3 and Ext4. Whoever took their time to compile this, deserves a pat on the back. Well Done.
  • jourdin2 December 15, 2011, 1:14 am
    NICE!
    Two other sites to visit for furher iinfo on ext4 are Ext4 (and Ext2/Ext3) Wiki ,and Linux Kernel Newbies ext4
    BTW, one good way to format ext4 from scratch, W/O journalling, onto a device natively-named “/dev/sda1″ is to specifically issue the command
    ‘ mke2fs -t ext4 -O ^has_journal -cv /dev/sda1 ‘
    This is good to know for future reference 😉
  • GAGAN GILL March 27, 2012, 5:44 am
    very nice…and briefly…i got it….it explained very easy method…i really love it..
  • shrikant Desai April 4, 2012, 3:44 am
    can any one help me to know how to increase the individual file size limit in the ext4 file system in linux?
  • gaurav benelic April 17, 2012, 3:12 am
    greate, it is realy very important……………….
  • Alain Jacquet June 18, 2012, 5:24 am
    Hi there
    I have been looking out for a reliable home-NAS. I have bought a NEXStar Home NAS, which would work great if it permitted me more than 256 characters in the path/filename. Much of my folder structure is nested in folders which makes sense from a filing perspective , but not in a backup system.
    Does EXT4 provide for that depth (and more) of path/ filename support?
    I have been looking at the Synology set of NAS systems.
  • Pradeep August 1, 2012, 3:47 am
    gr8 summary of definitions…….
  • Gajendra September 10, 2012, 1:18 pm
    Its too good ….-:)
  • Zulma October 15, 2012, 8:29 pm
    Nice info.. thank you
  • Arul October 29, 2012, 11:53 pm
    Guys,
    There is a typo,
    tune4fs -O extents,uninit_bg,dir_index /dev/sda2
    You cannot use the tune2fs for ext4! :)
  • Anonymous May 23, 2013, 6:00 am
    Very beautifully explained..
  • manas May 23, 2013, 11:45 pm
    Great, its too good description of file system in linux.
  • James Dashner May 28, 2013, 4:27 am
    Arul, I’m using tune2fs ext4 on Debian Wheezy 64-bit.
    sudo tune2fs -l LABEL=system
    tune2fs 1.42.5 (29-Jul-2012)
    Filesystem volume name: system
    Last mounted on: /
    Filesystem UUID: d68bccf7-08bb-4ad1-81e0-a1c628cb0355
    Filesystem magic number: 0xEF53
    Filesystem revision #: 1 (dynamic)
    Filesystem features: has_journal ext_attr resize_inode dir_index filetype needs_recovery extent flex_bg sparse_super large_file huge_file uninit_bg dir_nlink extra_isize
    Filesystem flags: signed_directory_hash
    Default mount options: user_xattr acl
    Filesystem state: clean
    Errors behavior: Continue
    Filesystem OS type: Linux
    Inode count: 2101232
    Block count: 8396484
    Reserved block count: 419824
    Free blocks: 6533744
    Free inodes: 1784482
    First block: 0
    Block size: 4096
    Fragment size: 4096
    Reserved GDT blocks: 1021
    Blocks per group: 32768
    Fragments per group: 32768
    Inodes per group: 8176
    Inode blocks per group: 511
    Flex block group size: 16
    Filesystem created: Sun Apr 21 12:59:30 2013
    Last mount time: Fri May 24 03:13:45 2013
    Last write time: Fri May 24 03:13:45 2013
    Mount count: 37
    Maximum mount count: 100
    Last checked: Sun Apr 21 12:59:30 2013
    Check interval: 7776000 (3 months)
    Next check after: Sat Jul 20 12:59:30 2013
    Lifetime writes: 95 GB
    Reserved blocks uid: 0 (user root)
    Reserved blocks gid: 0 (group root)
    First inode: 11
    Inode size: 256
    Required extra isize: 28
    Desired extra isize: 28
    Journal inode: 8
    First orphan inode: 1583808
    Default directory hash: half_md4
    Directory Hash Seed: 3253a857-11f0-45a2-92f2-82c689d0f0bc
    Journal backup: inode blocks
  • Uzzal October 24, 2013, 1:09 am
    Really a Very Nice documents Specially when a beginner like me want to know difference between all the file systems in Linux.
    Thank you
  • starcute keihs February 25, 2014, 10:40 pm
    so helpful… bur is fat6 and fat32 a file system in linux?
  • Vignesh April 25, 2014, 10:21 am
    Very nice Info… got idea…
  • afaq April 26, 2014, 9:12 pm
    realy like, very informative keepup
  • wei chen December 27, 2014, 6:00 pm
    gr8 but i use android-x86 kitkat (4.4 r1) aka 4.4.2
    i created a boot able drive using unetbootin
    the default android installer only support ext2 and ext3
    i dunno if the system is going to crash if i convert my installed ext3 android into ext4
    any ideas?
    PS if any one use android x86 i suggest use ext2 or 3 format because ntfs and fat32 suck at android compitablity
  • khushbu July 12, 2015, 9:59 pm
    very nice info.thanks
Leave a Comment

No comments:

Post a Comment