How to convert ext2 to ext4?

22,202

Solution 1

Follow the instructions detailed in this post: Convert ext2/3 to ext4

Solution 2

The short version for the impatient:

dev=/dev/sdXn # <-- Adjust this

then

umount $dev && tune2fs -O extents,uninit_bg,dir_index,has_journal $dev && e2fsck -v -pf $dev

If you cannot unmount because it's your system partition, then of course you will need to first boot from another system like a Live CD.

And no, you will not lose data. Unless something very weird happens, in which case you will have to reach to your backup. (You do have backups, of course. Right?)

Solution 3

A lot has changed in ext4 since the article linked to in the accepted answer was written. There are a lot more ext4 features that can be enabled now. To convert an ext2 filesystem to a full-featured ext4 (at the time of this writing), The command is:

tune2fs -O extents,uninit_bg,dir_index,has_journal,flex_bg,huge_file,extra_isize,dir_nlink,uninit_bg /dev/EXT2DEVICE

There really isn't a set "ext2", "ext3", or "ext4" any more. There is a whole spectrum of features. To see the features enabled for your extX filesystem, use the command:

dumpe2fs -h /dev/DEVICE

The core set of features for ext2 are: ext_attr,resize_inode,filetype,sparse_super,large_file. Generally, ext3 is considered to be ext2 plus a journal. And ext4 is basically ext3 plus any combination of the rest of the available features. In the future they may name it ext5, 6 or 7. Really it's all one filesystem family with a variable set of features.

To find out what the most current set of extWHATEVER features are at the time you read this, the best thing you can do is just create a small filesystem and look at its feature list. For ext4 it is:

dd if=/dev/zero of=ext4test bs=1M count=256
mkfs.ext4 ext4test
dumpe2fs -h ext4test

Look at the line that says "Filesystem features:" and it will tell you what features have been included on that filesystem. At the time of this writing it is:

Filesystem features:      has_journal ext_attr resize_inode dir_index filetype extent flex_bg sparse_super huge_file uninit_bg dir_nlink extra_isize

Once you do that, you can create your own method for updating your extX to the extLATEST. Do a dumpe2fs on the filesystem you want to upgrade and compare the features on it to the features on your test ext filesystem. For any or all of the features that are missing on the old filesystem you:

tune2fs -O <comma-delimited list of missing features>

Once you are done adding the features, force a filesystem check with:

e2fsck -f /dev/DEVICE

And you have just now ensured your extX is now the extLATEST with all the available features.

Share:
22,202

Related videos on Youtube

Lucio
Author by

Lucio

Web Developer building cool stuff on Spotify! Do you like recursion? Enjoy it! Full Profile

Updated on September 18, 2022

Comments

  • Lucio
    Lucio over 1 year

    I installed Ubuntu 12.10, and I don't know why, I have an ext2 partition.

    • How can I convert this ext2 file system to an ext4?
    • Will I lose all my data?
  • Clive van Hilten
    Clive van Hilten over 11 years
    The partition may not be /dev/sda1 ... ?
  • psusi
    psusi over 11 years
    @user30275, obviously....
  • Lucio
    Lucio over 11 years
    Will I lose all my data? How do I know if my boot partition is SEPARATE? Should I do the Step 3 or not?
  • dobey
    dobey over 11 years
    You won't lose you're data, unless you do something incorrectly. If you're worried about data loss, you should always back it up somewhere else first. You can use mount to show what partitions are mounted where. You can also run sudo parted list to print a list of partitions.
  • Clive van Hilten
    Clive van Hilten over 11 years
    to psusi - in which case you should have pointed this out to the OP
  • Lucio
    Lucio over 11 years
    The command sudo parted list doesn't work, but sudo parted -l does.
  • psusi
    psusi over 10 years
    Note that this only enables some of the features of ext4. Some can not be enabled without reformatting.
  • jrg
    jrg almost 7 years
    Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference.
  • Kurt Fitzner
    Kurt Fitzner about 3 years
    This has changed a lot in the 11 years since the article you posted was made. There are a lot more ext4 features than the article's command enabled. See answer below.
  • josch
    josch about 2 years
    small typo: s/tunee2fs/tune2fs/