In another article I described ext2, ext3, and ext4 filesystems creation on linux

Can they be converted to each other ? answer is yes

Generally speaking, file system is divided into two segments called User Data and Metadata, luckily so far ext filesystems are made backward compatibility, so that they can be converted to each others.

Before start convertion

Convertion between ext2 to ext3, ext2 to ext4 can be done on the fly, however, it is always better to unmount file system and convert. I got into trouble once when converting ext2 to ext4, not a big deal, fixed by fsck.

All conversion can be done by utility tune2fs

Supported convertion:

Ext2 --> Ext3

Ext3 --> Ext2

Ext2 --> Ext4

Ext3 --> Ext4

Note: Ext4 to Ext2/3 convertion is kind of possible, but not supported and recommded.

Create an ext2 file system

# mkfs -L testfs -t ext2 /dev/mapper/vg0-lvol0 
mke2fs 1.41.12 (17-May-2010)
Filesystem label=testfs
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
655360 inodes, 2621440 blocks
131072 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2684354560
80 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
    32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632

Writing inode tables: done                            
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 32 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

And, I saved a filesystem parameter list for this ext2 filesystem

#tune2fs -l /dev/mapper/vg0-lvol0 >ext2.parameters

Convert Ext2 to Ext3

Change an ext2 file system to ext3 by enabling the journal feature

# tune2fs -j /dev/mapper/vg0-lvol0
tune2fs 1.41.12 (17-May-2010)
Creating journal inode: done
This filesystem will be automatically checked every 32 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

What has been change?

# diff ext2.parameters ext3.parameters 
< Filesystem features:      ext_attr resize_inode dir_index filetype sparse_super large_file
> Filesystem features:      has_journal ext_attr resize_inode dir_index filetype sparse_super large_file
< Free blocks:              2574545
> Free blocks:              2541744
> Journal inode:            8
> Journal backup:           inode blocks

Note: I excluded timestamp different

Convert Ext3 to Ext2

Just remove the journal

 # tune2fs -O ^has_journal /dev/mapper/vg0-lvol0
tune2fs 1.41.12 (17-May-2010)

Converting Ext2 to Ext4

Change an ext2 to ext4 file system by enabling the latest journaling feature. Run the following command.

# tune2fs -O dir_index,has_journal,uninit_bg /dev/mapper/vg0-lvol0
tune2fs 1.41.12 (17-May-2010)

Please run e2fsck on the filesystem.

After running this command we MUST run fsck to fix up some on-disk structures that tune2fs has modified.

# e2fsck /dev/mapper/vg0-lvol0
e2fsck 1.41.12 (17-May-2010)
One or more block group descriptor checksums are invalid.  Fix<y>? yes

Group descriptor 0 checksum is invalid.  FIXED.
...
Group descriptor 79 checksum is invalid.  FIXED.
testfs contains a file system with errors, check forced.
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
testfs: 11/655360 files (0.0% non-contiguous), 79696/2621440 blocks

# tune2fs -O dir_index,has_journal,uninit_bg /dev/hdXX

After convertion, see the parameters changes

# diff ext2.parameters ext4.parameters 
< Filesystem features:      ext_attr resize_inode dir_index filetype sparse_super large_file
> Filesystem features:      has_journal ext_attr resize_inode dir_index filetype sparse_super large_file uninit_bg
> Journal inode:            8
> Journal backup:           inode blocks

Convert ext3 to ext4

Convert an ext3 to ext4 filesystem, use the command.

# tune2fs -O extents,uninit_bg,dir_index /dev/mapper/vg0-lvol0
tune2fs 1.41.12 (17-May-2010)

Please run e2fsck on the filesystem.

After running this command we MUST run fsck to fix up some on-disk structures that tune2fs has modified.


# e2fsck /dev/mapper/vg0-lvol0
e2fsck 1.41.12 (17-May-2010)
One or more block group descriptor checksums are invalid.  Fix<y>? yes

Group descriptor 0 checksum is invalid.  FIXED.
...
Group descriptor 79 checksum is invalid.  FIXED.
testfs contains a file system with errors, check forced.
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
testfs: 11/655360 files (0.0% non-contiguous), 79696/2621440 blocks

WARNING: You cannot revert or mount back to ext3 filesystem once you run above command.

Some features explaination:

uninit_bg
   Allow the kernel to initialize bitmaps and inode tables and keep a high  watermark
  for  the  unused  inodes  in  a  filesystem, to reduce e2fsck(8) time.  This first
   e2fsck run after enabling this feature will take the  full  time,  but  subsequent
   e2fsck  runs will take only a fraction of the original time, depending on how full
   the file system is.
dir_index
   Use hashed b-trees to speed up lookups in large directories.
has_journal
   Use  a  journal  to  ensure  filesystem consistency even across unclean shutdowns.
   Setting the filesystem feature is equivalent to using the -j option.
large_file
   Filesystem can contain files that are greater than 2GB.  (Modern kernels set  this
   feature automatically when a file > 2GB is created.)
resize_inode
   Reserve space so the block group descriptor table may grow in the future.  Tune2fs
   only supports clearing this filesystem feature.
sparse_super
   Limit the number of backup superblocks to save space on large filesystems.