I installed Ubuntu 12.10, and I don't know why, I have an ext2 partition.
- How can I convert this
ext2file system to anext4? - Will I lose all my data?
I installed Ubuntu 12.10, and I don't know why, I have an ext2 partition.
ext2 file system to an ext4?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.
Follow the instructions detailed in this post: Convert ext2/3 to ext4
mount to show what partitions are mounted where. You can also run sudo parted list to print a list of partitions.
– dobey
Nov 02 '12 at 20:14
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?)
extents is now extent (without the s at the end). Also, what does e2fsck -v -pf do exactly? As far as I can see this is nothing out of the ordinary: verbose, automatic repair ("preen"), force check even when marked as clean. Is this the whole story? I doubt that...
– luttztfz
Jul 20 '25 at 16:36
First of all, it is recommended to backup all the files, create a completely new filesystem, then restore all the files. It is not recommended to simply add features, especially if the filesystem is quite old and full... That said: make a backup first!
First, run dumpe2fs on the filesystem in question. Replace /dev/DEV with your actual device, e.g. /dev/sdx5. If you've just connected the device (for example when it is an external HDD) you can see the device recognized by the kernel with the dmesg command as such: dmesg | tail, or you can mount it, then unmount it. Again, dmesg should show which device it was. Or, mount it, then run mount without a command line argument and it will print out all mounted volumes, including the one you just mounted. If it is the only ext2 or ext3 filesystem, you can use grep to get only the specific line, e.g. mount | grep ext2.
dumpe2fs -h /dev/DEV
Check the line that says "Inode size". If it is less than 256, you cannot continue. (Very, very old ext2 filesystems used a 128 byte inode size, and this simply is not enough space for modern features!)
So, according to UpgradeToExt4 in the kernel.org wiki archive a "Less Effective In-Place Upgrade" is possible. Be aware that on a full filesystem with lots of files the procedure will take a very long time! The following steps are important:
umount /dev/DEVe2fsck -fy /dev/DEV (will take time!)tune2fs -j /dev/DEV (will take time!)tune2fs -O extent,huge_file,flex_bg,metadata_csum,metadata_csum_seed,64bit,dir_nlink,extra_isize,orphan_file /dev/DEV will most likely not work, so you may want to play with adding feature by feature, one at a time!e2fsck -fDC0 /dev/DEVTo see the default ext4 filesystem features currently used on your system, look them up in /etc/mke2fs.conf, under [fs_types], ext4 = { features = .... On my system, mid 2025, these default features were:
has_journal,extent,huge_file,flex_bg,metadata_csum,metadata_csum_seed,64bit,dir_nlink,extra_isize,orphan_file
Running the full tune2fs -O extent,huge_file,flex_bg,metadata_csum,metadata_csum_seed,64bit,dir_nlink,extra_isize,orphan_file /dev/DEV didn't work for me, it returned an error. (Since I added the journal as an extra step before anyway, I omitted has_journal.)
My suggestion is to add feature by feature, one at a time. E.g.
tune2fs -O extra_isize /dev/DEVtune2fs -O extent /dev/DEVdume2fs -h /dev/DEV in-between to see what you already have...)Not all features may work, but most importantly some feature require additional steps, e.g. after tune2fs -O 64bit /dev/DEV you will be instructed to run resize2fs -b /dev/DEV, which you must do!
Note: if you've inadvertently activated a feature, it can be disabled the same way by adding a leading ^ to it, e.g. tune2fs -O ^uninit_bg /dev/DEV will disable uninit_bg.
Also, take a closer look at the e2fsck options using man. You will see that -f forces a filesystem check, even when a filesystem is marked as clean. To rebuild all directory structures, -D is mandatory. For a more informative output, -C0 will display a progress bar. This command will take a very long time to complete on a big drive with lots of directories and files! Newer ext4 features like first uninit_bg and now metadata_csum have reduced the time needed to check an Extended Filesystem considerably, but for ext2 and ext3, it will take as long as it takes, and this means much much... much longer than one coffee break!
But that's not all. Since we've just enabled extents, we would like to use them for our files too! Only newly created files will use extents, the already existing files will use standard block groups just as before. In order to convert all existing files to use extents as well, an additional e2fsck run is required (amongst other possibilities):
e2fsck -E bmap2extent -fy /dev/DEVAnother possibility is to manually set the extend attribute on each file.
Before you start, please read this:
extents → extent and uninit_bg has been superseded by metadata_csum)Bear in mind that a lot has changed since extents were introduced to the ext4 filesystem. For example, the uninit_bg feature mentioned in the kernel wiki archive has been superseded by metadata_csum.
Important: if this convertion is intended for a system partition, e.g. the root partition /, I would highly recommend to use a live-bootable system to convert it. I don't even know if it would be possible otherwise. I don't think so, because if / is in use, it cannot be converted. Also, configuration files such as /etc/fstab have to be corrected (ext2 to ext4)—and quite possibly more. For example, there may be a statement covering the root filesystem on the kernel command-line, like rootfstype=ext2 or =ext3 which have to be corrected to =ext4 as well, and the procedure will be different depending on the bootloader in use (i.e. GRUB2, Dracut, rEFInd, systemd-boot, ...).
Good luck! I sincerely hope you did make a backup first!
As an alternative, you can enable some of the features of ext4 by running the following command, and rebooting:
sudo tune2fs -O has_journal,uninit_bg,extents /dev/sda1
extents is now extent. For a longer answer see https://askubuntu.com/a/1553225/1105946 – 1.) it is highly recommended to backup, reformat and restore. 2) yes, conversion ext2/ext3 → ext4 is possible, albeit not recommended.
– luttztfz
Jul 24 '25 at 06:32
s/tunee2fs/tune2fs/– josch Feb 24 '22 at 21:11