How to convert partitions from ext3 to ext4 without formatting the hard disk
Someone said stealing?
As you know, one of our best friends Wikipedia helps us frequently with definitions. This time he told us that ext4 or fourth extended filesystem is a journaling file system developed as the successor to ext3. It was born as a series of backward compatible extensions to add to ext3 64-bit storage limits and other performance improvements. However, other Linux kernel developers opposed accepting extensions to ext3 for stability reasons, and proposed to fork the source code of ext3, rename it as ext4, and do all the development there, without affecting the current ext3 users.

How do we start the convertion?
First thing we need to know, is which partition we'd like to convert to ext4. To get to know, we'll need to execute the following command in our command shell:
sudo fdisk -l
This command will list all partitions and hard discs conected to our computer, and we'll see something similar to the following image.
(click to enlarge)
As you can see on the image, the disc /dev/sda has four partitions, sda1, sda2, sda3 and sda4, but what we need to know is which partitions we need to convert to ext4. In the list above, Ubuntu tells us the system every partition uses (marked in red), in this case we can see, that /dev/sda1 uses a HPFS/NTFS system (Windows partition), /dev/sda2 uses a Linux system, so we'll remeber the name of this partition, /dev/sda3 uses a Linux swap system (exchange partition) and last but not least /dev/sda4 uses a Linux system, so we'll also remeber the name of this partition. To make it clear, we marked in blue all partitions we need to convert. Therefore we need to convert the following partitions to ext4: /dev/sda2 /dev/sda4 Now we'll need to iniciate Ubuntu from another device, as it could be a LiveCD or, if you've got a pendrive near, you can follow the instructions of a tutorial we published some minutes ago, that explains how to install Ubuntu on a pendrive. Most important thing, here, is that all following steps are done on Ubuntu Release Jaunty Jackalope or superior.
Before you go on, be sure you are running Ubuntu from a LiveCD or from a pendrive, if not, the following steps can cause you trouble.
Getting started with the conversion...
What we need to do, is execute the following lines in a terminal:
sudo tune2fs -O extents,uninit_bg,dir_index /dev/sda2
sudo fsck -pf /dev/sda2
This command will convert the partition /dev/sda2, so we need to repeat the same step for /dev/sda4
sudo tune2fs -O extents,uninit_bg,dir_index /dev/sda4
sudo fsck -pf /dev/sda4
In this example we are using a Ubuntu installation that uses three partitions: /dev/sda2 to mount / directory /dev/sda3 as exchange partition /dev/sda4 to mount /home directory Thats why we need to convert two partitions to ext4. By default, the Ubuntu installation process only creates two partitions, one to mout / directory and one as exchange area, so you'll probably only find one partition using a Linux system, in that case you'll only need to convert one partition.
Ubuntu needs to know...
Now we'll need to modify a file, that "tells" our operating system that the partitions are ext4 type so it can mount and use them without any problems. First we'll mount the partition in which our base system was installed, in our case its sda2 and after that we'll modify the file:
sudo mount /dev/sda2 /mnt
sudo gedit /mnt/etc/fstab
This file is the one that contains all parameteres to mount partitions. So we'll need to remeber which were the partitions we converted to ext3, and change there type to ext4. As shown in the following image.
(click to enlarge)
And everything has to work...
We'll now only need to reinstall grub , to do so, we'll need to execute the following command:
grub-install --root-directory=/mnt /dev/sda
Where /dev/sda would be the disc we are working with. Notice: you need to specify the disc not the specific partition! Now we're ready to run ubuntu from our hard drive again and enjoy the capacity of the ext4 file system.
Following this instruction, we can convert any ext3 system to ext4, maintaining our boot configuration, as it was configured before. Even if we've installed Windows in another Partition.











shbika said
am May 27 2009 @ 5:26 pm
thanks man it was helpful
Torsten said
am October 24 2009 @ 5:52 pm
Thanks for the useful article.
Noteworthy maybe, that the conversion won’t really give any advantages for existing files that were written with ext3. So I have actually copied my files to a temp disk and back.
The grub-install failed for me – I guess because I did that with a 9.10 live CD on a 9.04 which was upgraded to 9.10 where GRUB is not upgraded. I could fix that then with the 9.10 live CD.
Andy said
am December 21 2009 @ 3:21 am
The grub-part gave me an error (because I missed the space betwenn /mnt and /dev/sda) but it worked nevertheless after reboot. Is the grub-install really necessary?