Introduction
With the 2.6.28 Kernel the Ext4 file system was marked stable. Ext4 provides many improvements over Ext3, most notably better performance and faster file system checks. As of Ubuntu 9.04 (Jaunty Jackalope), Ext4 can be used to do a new install. However, it is also possible to convert an existing Ext3 file system to the new Ext4 format.
For further reading on the benefits of Ext4, see: http://en.wikipedia.org/wiki/Ext4
Caution
Do not attempt converting to Ext4 on versions prior to Ubuntu 9.04 (Jaunty Jackalope)! Older versions of Ubuntu do not have an Ext4 aware Kernel and you will end with a non-bootable system. You have been warned.
To verify your kernel version, open a terminal and type:
uname -a
The 3rd term is the Kernel version. It MUST be 2.6.28 or higher.
Note: Working on a mounted filesystem is really dangerous. Firstly, always, always back up your data. Secondly I would recommend carrying out the steps below from a 9.10 live CD. Firstly, if as I did, you render your system un-mountable you have already gone through the steps of creating a "rescue option". Further you can then carry out all the steps below without having to reboot.
Step 1: Switch the existing Ext3 file system to the new Ext4 driver
We will start by switching over to the Kernel's Ext4 driver without changing the existing files on disk. We can do this as the Ext4 driver is backwards compatible and can mount an Ext3 file system.
sudo nano /etc/fstab
Look for ext3 on the line that defines your disk and change it to ext4. Here's an example of what the file may look like:
# /etc/fstab: static file system information. # # <file system> <mount point> <type> <options> <dump> <pass> proc /proc proc defaults 0 0 # /dev/sda1 UUID=327c1819-14e1-4b96-b9d2-d5e55e50f1ae / ext3 defaults,errors=remount-ro,relatime 0 1 # /dev/sda5 UUID=900e39f2-ad49-42ee-a7f5-8e6807d6b35b none swap sw 0 0 /dev/scd0 /media/cdrom0 udf,iso9660 user,noauto 0 0
The only change we need to make is to replace ext3 with ext4 for dev/sda1. In case you did a manual partitioning back when you first installed Ubuntu you may have more than one entry with ext3. In that case, change all of them to ext4.
Make a note of the device as you will need it in the next step. In the example above, the device is /dev/sda1.
Next reboot your system. This is required so that you switch to the Ext4 Kernel driver. Do not continue this guide without rebooting first.
Step 2: Enable Ext4 features
Now that we're using the Ext4 driver we can enable the Ext4 features. Open a Console and type (replace <dev> with the device noted in the previous step):
sudo tune2fs -O extents,uninit_bg,dir_index <dev>
For the example above where the device was /dev/sda1 the command would look like this:
sudo tune2fs -O extents,uninit_bg,dir_index /dev/sda1
The next step is to do another reboot. The reason is that after enabling the Ext4 features it is required to run a file system check which can only be done on an unmounted file system. Of course, unmounting your root file system while the system is running is not so good. Luckily running the tune2fs command above marks the file system as "dirty" and a file system check will be automatically performed at next boot.
Note that when you boot the first time you will see a long list of warnings of file system issues. These can be ignored and are perfectly normal. After the warnings are printed it will run a forced file system check and proceed with the boot. In newer Ubuntu versions you will have to press "f" when you see the start-up screen. Then just wait until you can login again.
Once the system comes up you're almost done, you are now running Ext4.
Step 3: Re-installing GRUB
If you convert your boot file-system ("/boot") to ext4, and you use the GRUB boot loader, you will need to install a version of GRUB which understands ext4. Your system may boot OK the first time, but when your kernel is upgraded, it will become un-bootable.
To fix this, you can issue the command (replace <dev> with the device noted in the previous step):
sudo grub-install <dev>
For the example above where the device was /dev/sda1 the command would look like this:
sudo grub-install /dev/sda
Note: If you are upgrading from 8.04 LTS to 10.04 LTS, running grub-install will not install grub2 and your existing grub is unable to handle ext4. Fortunately, your kernel files will not immediately be moved into ext4 blocks, so to fix this, as quickly as possible after the first boot, issue the commands:
sudo apt-get install grub2
And then:
sudo update-grub
Finally, one thing to note: Only files written after this conversion will take full advantage of Ext4. Existing files will stay with the Ext3 format. What this means on a practical level is that you will not notice much of a speed increase right away, but as files get re-written it will gradually speed up. It's yet another reason to do your Ubuntu updates, as the updates replace files.
Further Reading
http://en.wikipedia.org/wiki/Ext4
http://ext4.wiki.kernel.org/index.php/Ext4_Howto#Converting_an_ext3_filesystem_to_ext4