CentOS 5: Converting Ext3 to Ext4

Ext4 (fourth extended file system) is the successor of current widely used Ext3 filesystem in Linux.

Since Ext4 filesystem already in the market, we can fully utilise this and improve IO (input/output) performance. Ext4 is well-known to be good in handling large storage, reduce up to 9 times of file system checking (fsck) time compare to Ext3 (refer to this) and also checksums in the journal.

Variables as follow:

OS: CentOS 5.6 64bit
Kernel version: 2.6.18-238.19.1.el5
Backup partition: /backup (mount from /dev/sdb)

1. First of all, its recommended to backup everything first. We will us ‘dd‘ command to backup the whole partition to another hard disk. That hard disk is attached via SATA cable. We will format the backup hard disk with ext3 filesystem and and mount as /backup partition:

$ fdisk /dev/sdb
.....
 
Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-3916, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-3916, default 3916):
Using default value 3916
 
Command (m for help): w
The partition table has been altered!
 
......

The sequence I press in the keyboard is: n > p > 1 > enter > enter > w

2. Then, format the partition table /dev/sdb1 with ext3 filesystem:

$ mkfs.ext3 /dev/sdb1

3. Mount the backup partition to  /backup:

$ mkdir /backup
$ mount /dev/sdb1 /backup

4. Lets check our partition summary:

$ df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
                       47G  3.3G   41G   8% /
/dev/sda1              99M   20M   75M  21% /boot
tmpfs                 501M     0  501M   0% /dev/shm
/dev/sdb1              76G  173M   75G   1% /backup

5. Lets backup “/” partition and put the image into backup directory:

$ dd if=/dev/VolGroup00/LogVol00 of=/backup/VolGroup00-LogVol00.bak
100466688+0 records in
100466688+0 records out
51438944256 bytes (51 GB) copied, 807.368 seconds, 63.7 MB/s

6. Now we need to install one package called e4fsprogs. The e4fsprogs packages contain a number of utilities for creating, checking, modifying, and correcting inconsistencies in fourth extended (ext4 and ext4dev) file systems:

$ yum -y install e4fsprogs

7. We start to do the ext4 filesystem conversion:

$ tune4fs -O extents,uninit_bg,dir_index /dev/VolGroup00/LogVol00
tune4fs 1.41.12 (17-May-2010)
 
Please run e4fsck on the filesystem.

8. As what has been advised, we need to run filesystem check after tune. I rather do this in single-mode (init 1) to reduce risks. DON’T PROCEED TO REBOOT ONCE THIS STEP COMPLETE!

$ init 1
$ e4fsck -fDC0 /dev/VolGroup00/LogVol00
.........
Group descriptor checksum is invalid. FIXED.
Adding dirhash hint to filesystem.
 
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 3A: Optimizing directories
Pass 4: Checking reference counts
Pass 5: Checking group summary information
 
/dev/VolGroup00/LogVol00: ***** FILE SYSTEM WAS MODIFIED *****
/dev/VolGroup00/LogVol00: ***** REBOOT LINUX *****
/dev/VolGroup00/LogVol00: 112086/12558336 files (0.7% non-contiguous), 1252590/12558336 blocks

9. Change the /etc/fstab to make sure the system will mount the new ext4 filesystem afterwards:

$ vi /etc/fstab

Change following line:

/dev/VolGroup00/LogVol00 /                       ext4    defaults        1 1

10. Rebuild the initrd to make sure our system will mount /sysroot as ext4 and reboot the server once complete:

$ mkinitrd -v -f initrd-2.6.18-238.19.1.el5.img 2.6.18-238.19.1.el5
$ init 6

11. If we directly reboot after fsck on step 8, then we will have kernel panic, unless the kernel is 2.6.28 and later. Once up, lets check whether is it run on ext4 or not:

mount | grep ext4
/dev/mapper/VolGroup00-LogVol00 on / type ext4 (rw)

5 thoughts on “CentOS 5: Converting Ext3 to Ext4

  1. OK, I finally manage to do this on a /var partition (with /dev/hdb1 as the target file system to convert).

    Only issue I had was with point #10, the mkinitrd passage, which didn’t work / gave me any new file.

    I managed to successfully boot and mount the partition giving the ‘ext4’ parameter at grub boot

    Reply

    1. In this post, I converted “/” partition to ext4, so I need to rebuild initrd by using mkinitrd to make sure the system will boot /sysroot to the new filesystem (ext4). If you are not doing this, you will face ‘kernel panic’ because initrd does not know that you have change the filesystem.

      In your case, it will not generate new initrd because you are not converting any sysroot device, you just converting another disk which can be mounted correctly as defined in /etc/fstab after /sysroot mounted in ext3 during boot process.

      Reply

  2. Does ext4 take longer to format? It seems to be taking forever to finish when 3 would of been done by now.

    But it could also be a bad hard drive.

    Reply

  3. It is safer (albeit with more reboots) to do it in a different sequence:
    1-through-5 -> backups
    6
    10 (without reboot)
    9
    reboot
    11 (albeit that the ext4 feature flags are not yet enabled)
    reboot into single mode
    7 (but do it in single mode)
    reboot (should automatically go into recovery mode)
    8 (no need to manually go into single mode)
    reboot

    The important difference is that if it doesn’t boot when you reach 11, you can easily back out using a rescuecd to undo step 9.

    Reply

Leave a Reply

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