How to upgrade to ext4 in place

Here’s how you upgrade to ext4.  The process is pretty easy, but requires an fsck which means unmounting or rebooting if the file system is in use.

Make sure you are using at least e2fstools 1.41.3 and kernel 2.6.28 (or a vendor kernel with latest ext4 patches applied)!  Also, its probably a good idea to have proper backups (really!).  ext4 has just been declared stable, but what that really means is that the battle hardening has just begun.  I’ve done several heavily used systems without fault so far though, so its probably good enough for your desktop.

WARNING: DON’T CONVERT YOUR /boot PARTITION. Right now, there is no stable version of grub with ext3 support.  Even if there was, it really won’t gain you anything  :-) .

Run tune2fs, e.g.:

tune2fs -I 256 -O sparse_super,filetype,resize_inode,dir_index,ext_attr,has_journal,\
extents,huge_file,flex_bg,uninit_bg,dir_nlink,extra_isize /dev/sd[x][n]

Those are the default options for an ext4 file system if you were to create it with mkfs.ext4 (e2fsprogs 1.41.3 – see /etc/mke2fs.conf).  I’m getting pretty damn good performance with this!  The ‘-I 256′ option sets 256 bit inodes, which most recent ext3 FSs use already. If this is the case, and you get a message telling you so, remove this option.  Note that extents will make the FS backwards INCOMPATIBLE with ext3.

Next, edit /etc/fstab, e.g.:

/dev/vg/home /home ext4 defaults 0 0

Either unmount and mount or reboot your system.  tune2fs marks the fs as dirty and performs a fsck and conversion.
NOTICE: distros with initrds may need to be regenerated or you won’t be able to mount your root file system.  In Fedora (replace kernel version with your own):

cd /boot
mv initrd- initrd-
mkinitrd initrd- initrd-

That’s all there is to it.  Stay tuned for future ext4 developments like online defragmentation.

Also, ext{2,3,4} reserve 5% of space for root in case the drive fills up.  On large modern drives, this can be excessive (e.g: 50GB on a 1TB disk).  Consider running ‘tune2fs -m 1 /dev/sd[x][n]‘ to reduce this to 1%.

For more information and tweaking:

  1. Documentation/filesystems/ext4.txt from the latest kernel sources
  3. man tune2fs
Be Sociable, Share!
  • email
  • Reddit
  • HackerNews

11 thoughts on “How to upgrade to ext4 in place”

  1. Excellent Instructions. I definitely recommend the backup. Had quite the scare today with my complicated Gentoo setup and still don’t have a successful conversion (cryptsetup home and pam mounted). I had to use debugfs to back off of the new ext4 features and use fsck to fix those “features” so that I could remount ext3.

    I wouldn’t have lost much more than time and some pride had I lost my data but whatever I did different means these instructions aren’t foolproof. I either had segfault or CONFIG_LFS errors trying to mount the new ext4. I recompiled and installed the kernel with CONFIG_LFS with no improvement.

    I may give this another try after I have a real backup. :)

    -= Yet another Kevin running Gentoo =-

  2. Be careful with the -I inode adjustment, I think it is getting some renovations right now so its best to do that as ext3. Probably better to chunk off the upgrades anyways, i.e do inodes, then extents, then the rest. FWIW your drive will appear corrupt a couple of times as fsck regenerates stuff, so it can look a little bit scary. I thought I hosed mine the first time around. But bottom line, if you don’t have backups and aren’t good with a LiveCD, stay away for now :-).

  3. I left the inodes alone since they were already at 256 as you had mentioned. I tried the conversion on my USB can and got the same error there. Between disabling huge_file and making darn sure I had LSF support I got the can to work and I’m doing an rsync to it now. Whenever that’s finished I’ll tackle home, root, then maybe getting the newest pam_mount to play nice with my encryption.

    I’m anxious for this to finish. I’m hoping if nothing else this will increase my drive performance a bit. A lot of what I do seems to stall around the hdd and with a 7200 RPM drive I’ve seen some improvement but not as much as I had hoped. But hey, this is a year old laptop so what can I expect :) I’ve timed a few of my common operations under ext3. I’d be glad to post some totally unscientific stats if you are interested.

  4. Just some really initial figures with root and home fully ext4, and this is all I can probably compare since I rushed along and didn’t test any other apps…

    From hitting Enter at the grub prompt till I could login dropped from 45 seconds to 40. From login to “Fully loaded*” XFCE dropped from 45 seconds to 25 seconds. Total boot till login time is now 65 seconds compared to 90 before.

    *Fully loaded implies all my autostart stuff completed and the desktop is idle.

  5. WARNING: DON’T CONVERT YOUR /boot PARTITION. Right now, there is no stable version of grub with ext3 support. Even if there was, it really won’t gain you anything :-) .

    Err, you mean ext4. :)

  6. This is resolved in most current distributions (source: Ext4 Wiki), from as far as I know.

    Stumbled across this article while searching for information on a similar procedure (‘cept on Android instead), thought it worth noting for other travelers emerging from the search tunnels.

  7. Hi,
    1) Is there any way to convert ext4 back to ext3 file system?
    2) can i inject new commands into existing kernel command, which are used at boot time by the kernel?


Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>