Convert ext2/3 to ext4
Let's say you're a little bit behind the times. You've wanted to do some upgrading of your Linux machines but you've just not really had the time. Or let's say you did do some upgrading of your Linux system but you didn't make any changes to your file system and you're still running a machine with either ext2 or ext3. Now that's not necessarily a bad thing as both file systems work and work well. But let's say you do want to take advantage of some of the features of ext4.
In this article I am going to show you how to migrate your ext2 or ext3 partition to ext4. I will use a Ubuntu machine as an example. I want to warn you that you could lose data by doing this so, following good administrative practices, back up your data! Once you are certain you have that backup of your data, it's time to begin.
You must be certain you have a kernel that is at least 2.6.28-11-generic or higher. If not, do NOT continue on with this. To find out what kernel you are running issue the command
uname -r. If your kernel is lower thatn 2.6.28-11 stop where you are and close your browser.
The first step is to boot from a Ubuntu Live CD. You do this because you can't convert a file system that has been mounted. If you are converting a second drive on your machine (one that doesn't contain your OS or your ~/ (home) directory, you can always just unmount that drive and do this without booting the Live CD.
Now it's time to convert. We're going to use /dev/sda1 as an example for converting. You will want to know the exact name of the drive and/or partition you are wanting to covert.Â If you are converting from ext2 to ext4 issue the following commands:
tune2fs -O extents,uninit_bg,dir_index,has_journal /dev/sda1
If you are wanting to convert ext3 to ext4 issue the following commands:
tune2fs -O extents,uninit_bg,dir_index /dev/sda1
NOTE: After you enter either of the sudo bash commands you will have to enter your sudo password.
Regardless of which conversion you are doing you will want to check the drive (or partition) after the conversion and repair any issues. Do this with the command:
e2fsck -pf /dev/sda1
Now you need to make sure the partition will mount. Do this with the command:
sudoÂ mount -t ext4 /dev/sda1 /mnt
Hopefully you won't see any errors. You should now see the contents of that drive listed in the /mnt directory.
It's time to edit your /etc/fstab file to reflect the change. Open this file up with your favorite text editor and look for the line that corresponds to the drive/partition you just changed. In that line you will reference to either ext2 or ext3. Change that reference to ext4. Save and close that file.
Now you need to refresh grub. Depending upon how your boot partition is will determine how you do this. If your boot partition isÂ SEPARATE, do the following:
mount /dev/sda1 /mnt/boot
grub-install /dev/sda --root-directory=/mnt --recheck
If your boot partition is NOT separate, do the following:
mount /dev/sda1 /mnt
grub-install /dev/sda --root-directory=/mnt --recheck
Reboot. Once up and running you will now be using the ext4 file system!
If you areÂ leeryÂ of any of the above, don't worry...you don't HAVE to do this. Your system will run fine with ext2 or ex3. But if you love to get your hands dirty with your machines...then you will enjoy converting a working file system from one type to another. Just remember BACK UP YOUR DATA!Advertisement
is very useful to find out which partitions are in use
Just remember BACK UP YOUR DATA!
Just a small note
If you can backup _all_ data on the partition which you plan to change from ext2/3 to ext4, you might as well reformat it into ext4 after backing up the data.
This mentions about adding extents attributes to files migrated, have a look
It might be useful to mention at Step 5 that the /etc/fstab file that needs to be edited will(for now) be located at /mnt/etc/fstab
EXT4 also has a no journaling mode, so you don’t have to add a journal if you don’t want to. You can also mount EXT3 and EXT2 as EXT4 without changing the on disk format and get some of the benefits such as delayed allocation.
Worked perfectly. Thank you.
Thanks a lot, it worked perfectly. After all, when upgrading from kubuntu 8.10 to kubuntu 10.04 back then ext4 was still in experimental stages.
What about initramfs?
Isn’t it necessary to add ext4 support in it, when root partition is being converted?
What about the latest Ubuntu like 13.10 and how do you install in different ways. It is very complicated at install.
Thanx to Jack I finaly found a solution to the Ubuntu (12, 13) problem of not cleanly unmounting a partition with ext2 on shutdown/reboot!
Thanks Jack! I had used ext2 on an SSD, so i dearly wanted to migrate to ext4. Your step by step plan worked fine, and the whole conversion only took 15 minutes.
I realize this is pretty old now, but I didn’t even need a Live Environment – my production install of Linux Mint 17 had “tune2fs” installed already, so I ran it like you said, and I converted a 320 GB drive in about 30 seconds. After, I ran e2fsck (took about 5 minutes for that) and it came up clean. Thanks!
A question –
I have my OS mounted on “/” in partition /dev/sda6 and my home on “/home” in partition /dev/sda4.
Can I reformat or move my /home from ext2 to ext4 filesystem using tune2fs ?
Dropbox wants it.
Shouldn’t fsck be done before tune2fs too?