Convert ext2/3 to ext4

Jack Wallen
Aug 11, 2010
Updated • Nov 28, 2012
Linux
|
21

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.

Kernel pre-requisite

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.

Step 1

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.

Step 2:

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:

sudo bash
tune2fs -O extents,uninit_bg,dir_index,has_journal /dev/sda1

If you are wanting to convert ext3 to ext4 issue the following commands:
sudo bash
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.

Step 3:

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

Step 4:

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.

Step 5:

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.

Step 6:

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:

sudo bash
mkdir /mnt/boot
mount /dev/sda1 /mnt/boot
grub-install /dev/sda --root-directory=/mnt --recheck

If your boot partition is NOT separate, do the following:

sudo bash
mount /dev/sda1 /mnt
grub-install /dev/sda --root-directory=/mnt --recheck

Step 7:

Reboot. Once up and running you will now be using the ext4 file system!

Final thoughts

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

Previous Post: «
Next Post: «

Comments

  1. Anonymous said on September 22, 2018 at 5:44 pm
    Reply

    Shouldn’t fsck be done before tune2fs too?

  2. Subha said on August 15, 2018 at 2:30 pm
    Reply

    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.

  3. Seann Giffin said on January 2, 2018 at 5:46 am
    Reply

    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!

  4. Arnold said on August 23, 2015 at 6:24 pm
    Reply

    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.

  5. Vic said on April 25, 2014 at 5:31 pm
    Reply

    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!

  6. Funnick said on January 5, 2014 at 9:07 am
    Reply

    What about the latest Ubuntu like 13.10 and how do you install in different ways. It is very complicated at install.

  7. ali said on July 26, 2013 at 11:43 am
    Reply

    What about initramfs?

    Isn’t it necessary to add ext4 support in it, when root partition is being converted?

  8. ceaualbi said on June 3, 2012 at 2:16 am
    Reply

    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.

  9. gavin said on October 15, 2011 at 10:56 am
    Reply

    Worked perfectly. Thank you.

  10. It's Not a Puck said on March 12, 2011 at 10:53 am
    Reply

    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.

  11. woo said on November 8, 2010 at 9:53 am
    Reply

    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

  12. sankaran said on August 19, 2010 at 8:36 pm
    Reply

    http://wiki.archlinux.org/index.php/Ext4#Converting_ext3_Partitions_to_ext4

    This mentions about adding extents attributes to files migrated, have a look

  13. Abhishek said on August 15, 2010 at 9:14 pm
    Reply

    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.

    Simpler!

  14. Mari Donkers said on August 12, 2010 at 8:03 am
    Reply

    fdisk -l

    is very useful to find out which partitions are in use

Leave a Reply

Check the box to consent to your data being stored in line with the guidelines set out in our privacy policy

We love comments and welcome thoughtful and civilized discussion. Rudeness and personal attacks will not be tolerated. Please stay on-topic.
Please note that your comment may not appear immediately after you post it.