Linux Convert ext3 to ext4 File system

last updated in Categories CentOS, Data recovery, Linux, Linux desktop, Linux distribution, RedHat/Fedora Linux, Storage, Suse Linux, Sys admin, Tips, Troubleshooting, Tuning, Ubuntu Linux

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:
Here is sample config (note I’ve custom kernel names):

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

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:


Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.

21 comment

  1. 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
    -should list your partition as using ext4dev as the fs type

  2. 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?

  3. @ 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!

  4. 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.

  5. @ 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.

  6. 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.

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

  8. 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.

  9. 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)

  10. 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)?)

  11. 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 ?

  12. “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.

  13. 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


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

    Have a question? Post it on our forum!