Linux Convert ext3 to ext4 File system

by on January 23, 2009 · 20 comments· LAST UPDATED January 24, 2009

in , ,

Some time ago ext4 was released and available for Linux kernel. ext4 provides some additional benefits and perforce over ext3 file system. You can easily convert ext3 to ext4 file system. The next release of Fedora, 11, will default to the ext4 file system unless serious regressions are seen. In this quick tutorial you will learn about converting ext3 to ext4 file system.

ext4 Filesystem Features

The ext4 filesystem has more features and generally better performance than ext3, which is showing its age in the Linux filesystem world. Features include:

Delayed allocation & mballoc allocator for better on-disk allocation

  • Sub-second timestamps
  • Space preallocation
  • Journal checksumming
  • Large (>2T) file support
  • Large (>16T) filesystem support
  • Defragmentation support
WARNING! Once you run following commands, the filesystem will no longer be mountable using the ext3. Please note that ext4 may have some bugs so do not use for production servers (wait for sometime watch Linux kernel mailing list for ext4 bugs). It's recommended that you keep /boot in a ext3 partition for sometime.

You need ext4 patch applied into kernel and compile kernel with ext4 support. Once done type the following command to convert an existing ext3 filesystem to use ext4, type:
# tune2fs -O extents,uninit_bg,dir_index /dev/dev-name
For example convert /dev/sdb1 to ext4, enter:
# cd /; umount /dev/sdb1
# tune2fs -O extents,uninit_bg,dir_index /dev/sdb1

Next run fsck, enter:
# fsck -pf /dev/sdb1

How do I mount ext4 partition?

mount -t ext4 /dev/sdb1 /path
mount -t ext4 /dev/sdb1 /share
mount -t ext4 /dev/disk/by-uuid/YOUR-PARTITION-UUID /share

Use blkid to get UUID.

How do I boot from ext4 (/boot)?

If you have converted /boot file system (or / used for /boot), update /boot/grub.conf (/boot/grub/menu.lst). Open file and find out current kernel config file and append the following:
rootfstype=ext4
Here is sample config (note I've custom kernel names):

title		Ubuntu 8.10, kernel 2.6.28.1-vmware-guest-server
root		(hd0,1)
kernel	/boot/vmlinuz-2.6.28.1-vmware-guest-server root=UUID=8c2da865-13f4-47a2-9c92-2f31738469e8 ro quiet splash rootfstype=ext4
initrd		/boot/initrd.img-2.6.28.1-vmware-guest-server
quiet

Save and close the file. And run update-grub:
$ sudo update-grub
Next, update your /etc/fstab file so that it can be mounted as ext4 file system:

UUID=41c22818-fbad-4da6-8196-c816df0b7aa8 	/share	ext4	defaults,errors=remount-ro,relatime 0       1

Finally, reboot the system:
$ sudo reboot

Further readings:

TwitterFacebookGoogle+PDF versionFound an error/typo on this page? Help us!

{ 20 comments… read them below or add one }

1 Daniel January 23, 2009 at 9:39 pm

I just did this in Intrepid the other day, but took a different approach. You may want to advise your readers that Grub won’t boot to an ext4 partition. Since I have a separate /boot, I just converted my / to ext4 with no problems.

This is really simple actually, just requires a couple reboots:
sudo nano /etc/fstab
-change the fs type from ext3 to ext4dev for you root partition, the default options for ext4dev have extents enabled, so you cannot switch back to ext3
sudo touch /forcefsck
-this runs a fsck on reboot
sudo reboot
-let it run through the fsck, and once the system is up reboot again, it will need one more reboot and fsck to correct the journal
mount
-should list your partition as using ext4dev as the fs type

Reply

2 nixCraft January 23, 2009 at 10:08 pm

@Daniel,

The post has been updated.

Appreciate your comment.

Reply

3 Peter January 24, 2009 at 3:51 am

From your post it says a benefit of ext4 is Defragmentation support. What is happening here … I thought the benefit of linux file systems was that the files did not fragment ………. Are we about to see a flood of Windows style disk defragmenters?

Reply

4 Alec January 24, 2009 at 3:11 pm

@ Peter:
I agree. File system fragmentation???
I’ve always enjoyed my linux clients and servers because I never had to schedule routine defragmentations like I have to do with Windows’ FAT and NTFS partitions…
I will have to look into this some and experement.
Thanks for the great post Vivek!

Reply

5 BobCFC January 24, 2009 at 5:38 pm

Thanks I am using Ext4 with Jaunty Alpha 3 as my main system for / and /home partitions (using the Alternated CD) and it is so fast I don’t even notice that I enabled encryption for the whole home directory. Now I can convert my data partitions too!

BTW I think the defrag feature refers to on-the-fly defragging while in use.

Reply

6 nixCraft January 24, 2009 at 5:51 pm

@ Peter / Alec

BobCFC is correct about defragmentation. This new feature is called online fragmentation. Right now it is *NOT* available in v2.6.28, but will be probably available in the next release. Quoting from ext4 wiki:

While delayed allocation, extents and multiblock allocation help to reduce the fragmentation, with usage filesystems can still fragment. For example: You write three files in a directory and continually on the disk. Some day you need to update the file of the middle, but the updated file has grown a bit, so there’s not enough room for it. You have no option but fragment the excess of data to another place of the disk, which will cause a seek, or allocate the updated file continually in another place, far from the other two files, resulting in seeks if an application needs to read all the files on a directory (say, a file manager doing thumbnails on a directory full of images). Besides, the filesystem can only care about certain types of fragmentation, it can’t know, for example, that it must keep all the boot-related files contiguous, because it doesn’t know which files are boot-related. To solve this issue, Ext4 will support online fragmentation, and there’s a e4defrag tool which can defragment individual files or the whole filesystem.

Reply

7 p-root January 27, 2009 at 3:57 am

Great knowledge base that i ever found…….. :)

Reply

8 Prakash February 25, 2009 at 9:22 am

Ext4 users are reporting few problems :
http://ubuntuforums.org/showpost.php?p=6796365&postcount=251
and thread:
http://ubuntuforums.org/showthread.php?t=965879

Then ,we need e2fsprogs 1.41 or higher for ext4.kernel 2.6.28 for stable(eh?) ext4 unlike ext4dev.then converting a Linux root system from ext3 to ext4.Isn’t it risky with the current status of kernel support?

Reply

9 Shanker Jadapa March 5, 2009 at 10:54 am

First time i heard about ext4 file system. thanks for the information

Reply

10 Joachim Otahal April 26, 2009 at 1:12 pm

In case of Debian lenny: the fs-type must be “ext4dev” in fstab, since debian does not yet consider ext4 stable enough to call it “ext4″, that will probably make it in sid.

Reply

11 Drew May 6, 2009 at 11:17 pm

Oh yeah, when you reboot it seems to break a couple of desktop applets such as Quicklaunch (at least in my VM). And I did not notice an increase in boot times at all like so many have reported. Maybe it only applies to a fresh format ext4 w/ Ubuntu disc.

Reply

12 Joachim Otahal May 21, 2009 at 10:38 am

If you “convert” from ext3 to ext4 only new created files are “true” ext4, the existing files are still ext3-like, so existing files are as slow as usual, and deleting those files is as slow as usual too.
Use fresh formatted ext4 or copy the files around (not move inside one partition!) will help.

Reply

13 brijesh September 10, 2009 at 1:56 pm

sir
i want to know depth of linux file system can you provide me detail matter..
i am very much thankfull to you.
your faithfully
brijesh kumar
allahabad (india)

Reply

14 hooborg October 26, 2009 at 10:30 am

Hi,
In Redhat and Fedora there is /etc/grub.conf or /boot/grub/grub.conf not /boot/grub.conf (in How do I boot from ext4 (/boot)?)

Reply

15 Olivier November 27, 2009 at 8:56 pm

I don’t understand why people are using ext3 or ext4 for /boot. Isn’t ext2 good enough ? Why the journaling would be useful for this partition ?

Reply

16 James Buergel January 4, 2010 at 8:07 am

Any more good web sites on ext 4 and or the new grub 2 ?

Reply

17 treah blade May 17, 2010 at 2:07 am

“How do I boot from ext4 (/boot)?”

The info in this section is incorrect please do not use. See the grub wiki for correct details on how to modify a grub2 boot files.

Reply

18 matter April 8, 2011 at 1:23 am

Another reference advised to run fsck.ext4 with -D after tune2fs:

fsck.ext4 -yfD /dev/sdc1

Linas also advised enabling extents on all files / directories which will save the trouble of copying things around in order to achieve the full ext4 benefit. I used this after mounting the partition:

find . -xdev -type f -print0 |\
while read -d $” FILE; do chattr +e “${FILE}”; done
find . -xdev -type d -print0 |\
while read -d $” DIR; do chattr +e “${DIR}”; done

Cheers!

Reply

19 NP October 9, 2011 at 10:38 am

This is an incomplete tutorial if you read.

Need to specify -D with the ext4 fsck for a start. See for info.

Reply

20 Nikolay April 3, 2012 at 11:38 pm

Thanks,
was very helpful, old article, but well written.
probably best descriptive article on this topic.
My 1.3 TB filesystem is converted successfully.

Reply

Leave a Comment

Tagged as: , , , , , , , , , , , , , ,

Previous post:

Next post: