UpgradeToExt4

From Ext4
Jump to: navigation, search

Converting an ext2 filesystem to ext4

The recommended method for upgrading an ext2 filesystem to ext4 is to back up the entire volume, reformat the storage device with ext4, and restore the entire volume onto the fresh filesystem. This has the effect of defragmenting all files, formatting with larger inodes, adding directory indexes, and speeding up both e2fsck and metadata access by clustering metadata together. Furthermore, all files will have higher size limits and better capabilities than before.

If your workload absolutely requires not having a journal, ext4 filesystems can be formatted with "-O ^journal" to disable the journal. This is NOT recommended for the general case!

With the upcoming e2fsprogs 1.43, a fresh format will also enable 64-bit operation and metadata checksumming. e2fsck will also be able to prefetch the clustered metadata, which will make it even faster.

However, it is also possible to mount ext2 filesystems with the ext4.ko module, see the caveats below.

Converting an ext3 filesystem to ext4

Note: The ext3 driver will be removed from the kernel in 4.3. The ext4 driver will mount ext3 volumes while maintaining ext3 disk format compatibility.

The recommended method for upgrading an ext3 filesystem to ext4 is to back up the entire volume, reformat the storage device with ext4, and restore the entire volume onto the fresh filesystem. This has the effect of defragmenting all files, adding directory indexes, and speeding up both e2fsck and metadata access by clustering metadata together. Furthermore, all files will have higher size limits and better capabilities than before.

With the upcoming e2fsprogs 1.43, a fresh format will also enable 64-bit operation and metadata checksumming. e2fsck will also be able to prefetch the clustered metadata, which will make it even faster.

Less Effective In-Place Upgrade

You are strongly advised to use the upgrade procedure outlined at the top of this document.

NOTE: It is possible to mount both ext3 (and ext2, in kernels 2.6.28 and later) filesystems directly using the ext4 filesystem driver. Simply mounting an ext3 (or ext2) filesystem with a modern (2.6.27+) version of ext4 will not change the on-disk structures, and it is possible to revert to the ext3 (or ext2) driver should there be any problem with ext4. If you plan to use the ext4 driver to boot from an ext2/3 partition, and you compile your kernel without the ext2/3 drivers, you may need to add rootfstype=ext4 to the kernel command line.

If you simply cannot reformat and restore as specified above, it is possible to turn on some of the ext4 features. Do NOT do this until you have determined that the recommended approach cannot work for your situation! By performing this procedure instead, you do not get to take advantage of metadata locality that you'd get with a freshly formatted ext4. It is possible to enable journalling, extents, directory indexes, and uninitialized block groups for a modest speedup.

First, ensure that your e2fsprogs is up to date. Newer versions have many, many bug fixes.

Second, ensure that your filesystem is in good working order!

# umount /dev/DEV

# e2fsck -fy /dev/DEV

Next, to change an ext2 filesystem to ext3 (enabling the journal feature), use the command:

# tune2fs -j /dev/DEV

To enable the ext4 features on an existing ext3 filesystem, use the command:

# tune2fs -O extents,uninit_bg,dir_index /dev/DEV

WARNING: Once you run this command, the filesystem will no longer be mountable using the ext2 or ext3 filesystem driver!

After running this command (specifically, after setting the uninit_bg parameter), you MUST run fsck to fix up some on-disk structures that tune2fs has modified:

# e2fsck -fDC0 /dev/DEV

Finally, edit /etc/fstab to change the filesystem type to ext4.

Notes:

  • Running fsck will complain about "One or more block group descriptor checksums are invalid" - this is expected and one of the reasons why tune2fs requests to fsck.
  • By enabling the extents feature new files will be created in extents format, but this will not convert existing files to use extents. Non-extent files can be transparently read and written by Ext4. You can convert files to extent format by running chattr +e on each file. Starting in e2fsprogs 1.43 you will be able to run e2fsck with -E bmap2extent -fy to do this conversion.
  • If you convert your root filesystem ("/") to ext4, and you use the GRUB boot loader, you will need to install a version of GRUB which understands ext4. Your system may boot OK the first time, but when your kernel is upgraded, it will become unbootable (press Alt+F+F to check the filesystem).
  • If you do the conversion for the root fs on a live system you'll have to reboot for fsck to run safely. You might also need to add rootfstype=ext4 to the kernel's command line so the partition is not mounted as ext3.
  • WARNING: It is NOT recommended to resize the inodes using resize2fs with e2fsprogs 1.41.0 or later, as this is known to corrupt some filesystems.
  • If you omit "uninit_bg" on the tunefs command, you can skip the fsck step.
Personal tools