Ubuntu / Linux news and application reviews.

If you are one of those people and you don't want to miss out using the new ext4 file system, there is a way to convert your existing ext3 file system to ext4.

Please note that converting-to/using ext4 is by no means necessary, you are not missing out if you are using ext3 (hell, ext2 is still widely in use). So only do this if you like to hack and get your hands dirty.

Before starting, take a look at the known issues with ext4!


Step one:
Upgrade to Jaunty. You now have a working jaunty install running the ext3 file system.

Step two:
Make a backup of all your (important) data. You can use fwbackups or any other app.


Step three:
Boot from a (jaunty) live-cd and run the following code (in this example the partition to convert is on /dev/sda1) to convert the partition:
sudo bashtune2fs -O extents,uninit_bg,dir_index /dev/sda1e2fsck -pf /dev/sda1

Step four:
Mount the partition and change the type of the converted partition in fstab:
sudo bashmount -t ext4 /dev/sda1 /mntnano /mnt/etc/fstab

change "ext3" to "ext4" like in the example below:
# /dev/sda1UUID=XXXXXXXXXXXXXXXXXXXXXXXXXX /               ext3    relatime,errors=remount-ro 0       1

change it to:
# /dev/sda1UUID=XXXXXXXXXXXXXXXXXXXXXXXXXX /               ext4    relatime,errors=remount-ro 0       1

and save the changes.

Step five:
This step might be optional but when I upgraded from Intrepid to Jaunty the upgrade process did not install/update the new grub stage. So if you don't run either of the following code examples you might get an (fatal) error 13 when booting the machine.
Use this code to refresh grub when you do not have a separate /boot partition (in this example the root partition is sda1)
sudo bashmount /dev/sda1 /mntgrub-install /dev/sda --root-directory=/mnt --recheck

Use this code to refresh grub when you do have a separate /boot partition (in this example the /boot partition is sda1)
sudo bashmkdir /mnt/bootmount /dev/sda1 /mnt/bootgrub-install /dev/sda --root-directory=/mnt --recheck

That's it, after you reboot you you will be running from an ext4 file system.
As a side note, all the files that where present before the conversion will not benefit from the conversion as they were written to disk using ext3 technology. Only newly created or overwritten files will be using the true ext4 technology (so now, using update-manager will be extra beneficial). As ext3 and ext4 are compatible with each other having files written to disk in ext3 mode on your ext4 file system do not impose any risks (and most if not all ext3 sectors could eventually disappear even without defragging).

There is currently a online-defragging tool in development (e4defrag) which should be available with the next kernel release.

Credits: whoop user @ ubuntuforums.org