Linux – Convert a software raid volume from ext3 to ext4 (or ext2)

ext3ext4linuxmdadmUbuntu

I have an mdadm created software raid volume in my ubuntu linux 11 machine. It is NOT the boot drive. It is a software raid 5 configuration made from 3 large sata drives.

When I created it initially, I made it ext3. I have since learned that I may benefit from converting it to ext4 (or ext2).

First, I would like to confirm that this makes sense, that converting to for example ext4 would give me better performance (searching around that seems to be a common benefit of ext4 over ext3).

Next, is there any reason to consider going to ext2 – or is this actually a bad idea?

Finally, HOW do I do this?

From what I gather (from this site for example), I need to unmount the volume, then execute some commands to convert the volume. My fstab is current set to 'auto' for the file system type.

Best Answer

The differences between the various and sundry ext[0-9] filesystems are more about features, and less about structure. The advantage is that they are fairly compatible with each other. For instance, you can mount an ext3 partition as ext2 and everything should work just fine. Similarly, you can mount an ext3 partition as ext4. Whenever you do either of these operations, you won't have access to the version specific features. For instance, if you mount an ext3 partition as ext2 you will lose access to the journal. Similarly, mounting an ext3 partition as ext4 won't let you use the newer features such as decreased fsck times and extents rather than bitmaps.

In order to make the conversion what you'll need to do, at a high level, is

  1. unmount the partition
  2. run the conversion
  3. mount the partition

So as long as this is not your primary disk you can do this without having to take down the system, you just have to expect the target partition to be down for some length of time. And, as always, before fiddling around with your filesystem you should take a full backup of the data on the off-chance you have some loss.

The exact commands you should run to do this are as followed. For my purpose, I'm going to assume your target device is /dev/md0

umount /dev/md0
fsck.ext3 -pf /dev/md0
tune2fs -O extents,uninit_bg,dir_index /dev/md0
fsck.ext4 -yfD /dev/md0

The first fsck is to make sure that your filesystem is in a clean and sane state before we do the conversion. Otherwise the process may fail, or even worse, may succeed but leave inconsistencies laying around. The tune2fs command is for fiddling with the filesystem settings. It was originally created for ext2, hence the '2fs' part of the name, however it is used for modifying all versions of the ext filesystem. In this case we are enabling the extra features that were added between ext3 and ext4. The final fsck is doing two things. First it makes sure that any necessary cleanup from the conversion happens, and secondly it will create, or rebuild, the directory index.

After all this you will need to edit the /etc/fstab to make sure it is mounted as ext4, though in truth the auto option should correctly identify it as such.

Congratulations, so long as nothing caught fire/blew up/committed mass genocide/convicted of murdering it's wife during the process then you should be the happy owner of an ext4 partition.