What Ext can do for you

Posted by | Comments (0) | Trackbacks (0)

The Linux Extended File System (Ext) originally invented in 1992 was the first generation of the well known Linux default file system. Ext is inspired by the Unix File System (UFS) and now exists in the fourth generation which is Ext4. Ext by now is superseded by its descendant Ext2 which is also old but still widely used even though it's not a journaled file system like Ext3 and Ext4 (see below).

Today Ext4 has become the default file system on most Linux distributions but many users don't care about the opportunities they have with this file system. Ext2/3/4 have a lot of features besides their complex rights management of files. As the first blog entry here on refining-linux.org I'll be showing you some of the great features of Ext2, Ext3 and Ext4!

But first if you want to experiment with the fs tools and you don't have an unused partition don't despair. Since on Linux everything is a file you can easily use a file as a loopback device. E.g. to create a 50MB Ext4 partition on a file called test-partition just run:

dd if=/dev/zero count=102400 of=./test-partition
mke2fs -t ext4 -F ./test-partition
mkdir /mnt/test-partition
mount -o loop ./test-partition /mnt/test-partition

This first creates a file of 50MB (102400 blocks at 512 bytes), formats it with Ext4 and mounts it at /mnt/test-partition. Now you have a virtual device called test-partition which you can freely use for experimenting.

Configuring File System

Ext file systems have a lot of configurable features which can partially be set in your /etc/fstab or directly in the file system via tune2fs. The most well known option of tune2fs is

tune2fs -c <max-mount-counts> <device>

This sets the the number of mounts after which e2fsck will check the file system for data corruption. Less well known is

tune2fs -i <time-between-checks> <device>

which sets a time interval after which the file system will be checked. You can specify the interval in days (d), months (m) or weeks (w). You can also manipulate the time of the last check with parameter -T or the number of mounts since the last check with parameter -C.

Note: Many users turn off file system checks by setting the value to 0 but you should never ever do this on writable mounted file systems! In some cases periodic fs checks can save your head. If you dislike regular checks set the interval to a higher number but you should at least leave one of the above mentioned intervals enabled. Anyway when you use Ext4 the check should be very fast since only the used inodes are checked and not the whole device.

Further you can specify some default mount options with tune2fs -o <mount-options> which can be overridden in your /etc/fstab or by giving mount options to the mount command. To see which options these are take a look at the man page of tune2fs.

tune2fs provides a lot more options but covering all of them would go beyond the scope of this article. So please take a close look at the man page. You'll find many interesting settings there like setting a file system label with parameter -L as you might know from Windows, controlling the size of reserved blocks and which user might use them and a lot more.

Journaling and data integrity

Ext3 introduced a feature called journaling. Journaling provides better data integrity by first writing all data into a journal before actually writing it into the actual file system. If your computer crashes or must be restarted for any other reason during the write process inconsistent data can be recovered from the journal. But unfortunately Ext3 does not use checksums for the journal thus there is a slight risk of damaged journals. Checksums for journals have primarily been introduced in Ext4. Therefore if you wish a better data security choose Ext4. But of course journals don't save your data when your harddrive itself crashes. Journals are NOT a replacement for backups and/or a RAID1 setup! (indeed)

Ext3 and Ext4 provide journaling as we know. Most people using Ext3 or Ext4 know this but only a few know that there are three levels of journaling called journal, writeback and ordered. The last one is the default one. It's a compromise between the other two which are either unsafe or very expensive. journal writes all data into the journal and therefore it is very time-consuming (expensive). On the other hand writeback only writes the metadata into the journal the file contents themselves are directly written into the file system. However ordered first saves the data to disk, then writes the metadata into the journal. If you wish better performance and accept less data security choose writeback or if you need better data security choose journal. If neither of them is crucial for you stay with the default ordered.

But how do we control the level of journaling? That's quite easy. You can either do this with tune2fs:

tune2fs -o {journal_data|journal_data_writeback|journal_data_ordered} <device>

or in your /etc/fstab

# <fs>                  <mountpoint>    <type>  <opts>                                      <dump/pass>
/dev/my-example-device  /my/mountpoint  ext4    defaults,data={journal|writeback|ordered}   1 1
# ...

That's easy, isn't it? Of course you can only specify one level at once.


There is yet another cool feature called “Quota”. With quota you can limit the disk space a user or even a group can take. There are two types of quotas: soft quotas and hard quotas. Soft quotas can be exceeded for a specific amount of time (grace period), hard quotas immediately refuse write actions if the file size goes beyond the limit.

Quotas are an easy to understand but very huge topic and therefore I will not cover it in this blog entry. If you're interested in this, just enter it as a search term in Google, you'll find a lot. I first considered writing an article about quota, but since this topic has been discussed so many times on the web, I dropped the idea. I'm sorry for that.


There is a widely spread myth about Linux file systems and that is that these file systems would not fragment their data. That's not true. That can't be true since a file system without fragmentation would refuse to save big files very soon since there's not enough space on disk. Also Linux file systems fragment their data but they do a better job than FAT and maybe even better than NTFS. The only thing is that there has never been a defrag tool for Ext file systems but these times are over. Ext4 now has a defrag tool called e4defrag but it's still in a very early development state and yet very primitive. It's still not in stable e2fsprogs thus you have to download the sources from Git. With e4defrag you can defrag file systems or individual folders and files. That's very handy when you have a large file which is excessively fragmented.

Fragmentation normally shouldn't be a big problem on desktop PCs but sometimes you can come into trouble especially when your disk is very full. You can inspect the grade of fragmentation with e2freefrag. This shows you how the free space on your harddisk is fragmented. Normally it should look like this:

Device: /dev/sdaX
Blocksize: 4096 bytes
Total blocks: 232109104
Free blocks: 193278173 (83.3%)

Min. free extent: 4 KB 
Max. free extent: 2064256 KB
Avg. free extent: 165436 KB

Extent Size Range :  Free extents   Free Blocks  Percent
    4K...    8K-  :           695           695    0.00%
    8K...   16K-  :           420           980    0.00%
   16K...   32K-  :           269          1353    0.00%
   32K...   64K-  :           368          4356    0.00%
   64K...  128K-  :           267          5920    0.00%
  128K...  256K-  :           290         13329    0.01%
  256K...  512K-  :           273         24941    0.01%
  512K... 1024K-  :           278         50256    0.03%
    1M...    2M-  :           344        132398    0.07%
    2M...    4M-  :           296        212563    0.11%
    4M...    8M-  :           244        377036    0.20%
    8M...   16M-  :           225        528833    0.27%
   16M...   32M-  :           100        526000    0.27%
   32M...   64M-  :            76        849109    0.44%
   64M...  128M-  :           101       2517389    1.30%
  128M...  256M-  :            32       1452032    0.75%
  256M...  512M-  :            19       1677300    0.87%
  512M... 1024M-  :            18       3588729    1.86%
    1G...    2G-  :           359     181351170   93.83%

If you have a lot of small spaces but only a few contiguous ones you should think about defragmenting but that should not happen in most cases. If you need to defragment a disk but don't have a defrag tool you can copy the contents to a second harddisk, clean the first one completely and copy your files back at one go. That's very time-consuming but without a defrag tool it's the only efficient way.


No Trackbacks for this entry.


No comments have been submitted yet. Be the first!

Write a comment:

HTML-Tags will be converted to Entities.
Textile-formatting allowed
Standard emoticons like :-) and ;-) are converted to images.
Design and Code Copyright © 2010-2017 Janek Bevendorff Content on this site is published under the terms of the GNU Free Documentation License (GFDL). You may redistribute content only in compliance with these terms. tweetbackcheck