Wednesday, February 6, 2013

The Linux File System One must Opt

The Linux file system support is drastically different from Windows and OS X. In Windows and OS X you can find software that will add support for non-standard file systems, but both operating systems can only be installed on their native file system and third party support is added after the fact. Linux on the other hand has a vast array of supported file systems built into the kernel. But how are you supposed to know which file system to pick when installing?

Fig1: File Systems

We will take a look at some of the most popular choices available and give you use cases to consider the choice is ultimately up to you based on your needs.

Before we go to far down the rabbit hole talking about options, we need to first take a quick look at journaling. The only real thing you need to know about journaling is that every modern file system uses journaling in some form or another and on any desktop or laptop you are setting up with Linux you will want to use a journaling file system.

  Fig2 : File system flow

Journaling is only used when writing to a disk and it acts as a sort of punch clock for all writes. This fixes the problem of disk corruption when things are written to the hard drive and then the computer crashes or power is lost. Without a journal the operating system would have no way to know if the file was completely written to disk.
With a journal the file is first written to the journal, punch-in, and then the journal writes the file to disk when ready. Once it has successfully written to the disk, it is removed from the journal, punch-out, and the operation is complete. If power is lost while being written to disk the file system can check the journal for all operations that have not yet been completed and remember where it left off. The biggest downside to journaling is that it sacrifices some performance in exchange for stability. There is more overhead to write a file to disk but file systems get around this overhead by not writing the full file to the journal. Instead only the file metadata, inode, or disk location is recorded before actually being written to disk.

File System Options

As we look at some of the major file systems available to Linux we are going to touch briefly on each one and give a couple suggestions for when you may or may not want to use the file system based on features. This in no way means these file systems cannot be used in other cases, these suggestions are just areas where each file system will excel.

Fig3: Extended file systems
Ext :
It stands for Extended file system and was the first created specifically for Linux. It has had four revisions and each one has added fairly significant features. The first version of Ext was a major upgrade from the Minix file system used at the time, but it lacks major features used in today’s computing.
  •  At this time you probably should not use Ext in any machine due to its limitation and age. It also is no longer supported in many distributions.
Ext2 :
It is not a journaling file system, and when introduced was the first to allow for extended file attributes and 2 terabyte drives. Because Ext2 does not use a journal it has significantly less writes applied to the disk.
  •  Due to lower write requirements, and hence lower erases, it is ideal for flash memory especially on USB flash drives.
  • Modern SSDs have a increased life span and additional features that can negate the need for using a non-journaling file systems.
Ext3 :
It is basically just Ext2 with journaling. The aim of Ext3 was to be backwards compatible with Ext2 and therefore disks can be converted between the two without needing to format the drive. The problem with keeping compatibility is many of the limitations of Ext2 still exist in Ext3. The benefit of keeping backwards compatibility is the fact that most of the testing, bug fixes, and use cases for Ext2 also apply to Ext3 making it stable and fast.
  • Use if you need to upgrade a previous Ext2 file system to have journaling.
  • You will probably get the best database performance from Ext3 due to years of optimizations.
  • Not the best choice for file servers because it lacks disk snapshots and file recovery is very difficult if deleted.
Ext4 :
Just like Ext3 before it, keeps backwards compatibility with its predecessors. As a matter of fact, you can mount Ext2 and Ext3 as an Ext4 file system in Linux and that alone can increase performance under certain conditions. You can also mount an Ext4 file system as Ext3 without ill effects.
Ext4 reduces file fragmentation, allows for larger volumes and files, and employs delayed allocation which helps with flash memory life as well as fragmentation. Although it is used in other file systems, delayed allocation has potential for data loss and has come under some scrutiny.
  • A better choice for SSDs than Ext3 and improves on general performance over both previous Ext versions. If this is your distro’s default supported file system, you should probably stick with it for any desktop or laptop you set up.
  • It also shows promising performance numbers for database servers, but hasn’t been around as long as Ext3.

BtrFS :
It is pronounced “Butter” or “Better” FS, is being  developed by Oracle and contains similar features found in ReiserFS. It stands for B-Tree File System and allows for drive pooling, on the fly snapshots, transparent compression, and on-line defragmentation. It is being specifically designed for enterprises but most every consumer distro has plans to move to it as the default file system eventually.
Although it’s not stable in some distros, it will eventually be the default replacement for Ext4 and currently offers on-the-fly conversion from Ext3/4. It is also key to note that the principle developer for ext3/4, Theodore Ts’o, has said that BtrFS is the “way forward”.
  •  BtrFS makes a great server file system due to it’s performance, snapshots, and many other features.
  •  Oracle is also working on a replacement for NFS and CIFS called CRFS which boasts better performance and more features. Making it the best choice for a file server.
  •  The performance tests have shown it to lag behind Ext4 on flash memory such as SSDs, as a database server,and even certain cases of general system read/writes.
  •  Ubuntu 10.10 only allows you to install BtrFS if you use the text base alternate install CD and your /boot partition still requires an Ext file system.
ReiserFS :
It was a big leap forward for Linux file systems when it was introduced in 2001 and it included many new features that Ext would never be able to implement. ReiserFS was replaced by Reiser4 in 2004 which improved on many of the features that were incomplete or lacking in the initial release. However Reiser4 development is very slow and it still does not have support in the main Linux kernel. ReiserFS is the only version currently available in many distributions.
  •  Has great performance for small files such as logs and is suited for databases and email servers.
  •  ReiserFS can be dynamically expanded but not shrunk and does not support FS level encryption.
  • The future of Reiser4 is questionable and BtrFS is probably a better choice.
It was developed by Silicon Graphics in 1994 for their own operating system and was later ported to Linux in 2001. It is comparable to Ext4 is some regards because it also uses delayed allocation to help with file fragmentation and does not allow for mounted snapshots. XFS has shown itself to provide good performance with large files and has the ability to be resized, however you are not able to shrink an XFS volume.

Fig4: Silicon Graphics
  • Good for a media file server because of constant throughput for large files.
  •  Most distributions require separate /boot partition because XFS and GRUB can be unpredictable
  •  Performance with small files is not as good as other file systems making it a poor choice for databases, email, and other servers that have a lot of logs.
  •  Not as well supported as Ext for personal computers and doesn’t have significant performance improvements or features over Ext3/4.
It was developed by IBM in 1990 and later ported to Linux. It boasts low CPU usage and good performance for both large and small files. JFS partitions can be dynamically resized but not shrunk like ReiserFS and XFS.

Fig5: IBM
It was extremely well planned and has support in most every major distribution, however its production testing on Linux servers isn’t as extensive as Ext as it was designed for AIX.
  •  Good performance for both large and small files and because of its low CPU usage is probably best for low powered servers and computers
  •  It does not have built in tools for drive pooling so it may not be as expandable as something like BtrFS but a netbook with only 1 hard drive may be a good option
  •  It also has fast disk checking compared to Ext but there have been some reports of disk corruption after long term use.

It is worth a mention because it is also be being developed by Oracle and has similar features to Btrfs and ReiserFS. It was in the news in recent years when Apple was rumored to move to it as their default file system. Due to its licensing, Sun CDDL, it is not compatible to be included in the Linux kernel. It does however have support through Linux’s Filesystem in Userspace (FUSE) which makes using ZFS possible.

Fig6: Oracle
  • Shows great performance in large disk arrays.
  •  Supports a lot of advanced features including drive pooling, snapshots, and dynamic disk striping.
  •  It may be difficult to install in Linux because it requires FUSE and might not be supported by your distribution.
Swap :
It is not actually a file system. It is used as virtual memory and doesn’t have a file system structure. It cannot be mounted and read but is only used by the kernel to write memory pages to disk. It is typically only used when you either run out of physical memory or when you put your computer in hibernate but it is important to know what your partitioning tools mean when it asks for a swap space.

So now the main question arises that,which file system one should opt?

For a general use case on your laptop or desktop, you will probably want to stick with ext4,since it’s a modern file system that’s supported in most distributions.