Prakash Sawarkar: Kernel 3.8 Released, how to Compile in Redhat, CenOS and Fedora..

Kernel 3.8 Released, how to Compile in Redhat, CentOS and Fedora.

Saturday, 22 October 2011

How to create & convert Linux File Systems Ext2, Ext3 & Ext4

ext2,ext3 and ext4 are all filesystems created for Linux.

High level difference between these filesystems.
How to create these filesystems.
How to convert from one filesystem type to another.

I converted from ext2 to ext3, ext3 to ext4 and ext2 to ext4 file systems successfully. By following this guide anyone can convert their file systems smartly, but still I like to WARN you’ll before doing this, because the following task required skilled administrative practices and make sure you must take important backup of your files before doing this. If in case something goes wrong at least you can revert to back with your backup data.
File system is divided in two segments called User Data and Metadata. In this article I am trying to explore how to create and convert various Linux file systems and high level difference amongst Ext2, Ext3 and Ext4 file systems. Before moving further readings, let me introduce a brief about Linux file systems.

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:- 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:- 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”.

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.

Creating Ext2 File System

#  mke2fs /dev/sdXX

Creating Ext3 File System

#  mke2fs –j  /dev/sdXX

-j option is used for journaling.

Creating Ext4 File System

# mke2fs -t ext4 /dev/sdXX

-t option to specify the file system type.

Converting an Ext2, or Ext3, or Ext4 File Systems

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

Converting Ext2 to Ext3

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

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

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

-p option automatically repairs the file system.
-f option force checking file system even it seems clean.
WARNING: You cannot revert or mount back to ext3 filesystem once you run above command.

Converting Ext2 to Ext4

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

#  umount /dev/sdxx
#  tune2fs -O dir_index,has_journal,uninit_bg /dev/sdxx
#  e2fsck -pf /dev/sdXX
#  mount /dev/sdxx /home

Note: all of the above commands only on a test Linux server, where you can afford to lose all your data.