Migrating an ext3 filesystem to ext4 (Debian Squeeze)

Interestingly (well, perhaps not really) this is very easy.

In my case, I’m hoping that the migration will lead to faster fsck times (currently it’s taking about an hour, which is somewhat excessive, each time the server crashes for whatever reason).

In my case, the filesystem is /dev/md0 and mounted at /home – change the bits below as appropriate.

Anyway —

  1. Unmount the filesystem (umount /home, in my case)
  2. tune2fs -O extents,uninit_bg,dir_index /dev/md0
  3. fsck -DCpf /dev/md0
  4. mount -t ext4 /dev/md0 /home
  5. Update /etc/fstab, reboot and make sure everything works ….

The fsck operation will probably take ages; hence having the -C in there so I get some idea of progress. The -D flag to fsck does makes it optimise the directory structure on the filesystem, and will probably happen anyway due to you changing the fs options with tune2fs.

Your existing / old data will still be on disk, using the ext3 format. You can prompt the kernel to write to the files using extents – which presumably gives you more ext4 benefits (all new files will be written using extents). If you don’t want to wait, you can use something like the following to migrate files and directories to extents straight away :

find /home -xdev -type f -print0 | xargs -0 chattr +e
find /home -xdev -type d -print0 | xargs -0 chattr +e

Leave a comment

Your email address will not be published.