Learn how to upgrade the ext filesystem in Linux like RHEL, Centos, Ubuntu, etc. Steps for upgrading ext2 to ext3, ext3 to ext4, and ext2 to ext4.
In our last article we saw the difference between ext2, ext3, and ext4 file systems in Linux. In this article we will walk through how to upgrade ext2 to ext3 or ext4 on RHEL, CentOS, or Ubuntu.
How to upgrade ext2 to ext3
To upgrade ext2 volume lets first format volume with ext2 filesystem.
# mke2fs /dev/vg01/lvol0
mke2fs 1.42.13 (17-May-2015)
Creating filesystem with 53248 1k blocks and 13328 inodes
Filesystem UUID: b3c39dcf-e00f-414c-8306-46d985674b6e
Superblock backups stored on blocks:
8193, 24577, 40961
Allocating group tables: done
Writing inode tables: done
Writing superblocks and filesystem accounting information: done
Lets confirm file system type which we just formatted.
# df -T /mydata
Filesystem Type 1K-blocks Used Available Use% Mounted on
/dev/mapper/vg01-lvol0 ext2 51559 842 48055 2% /mydata
You can see its ext2 type in above output under second column.
Now to upgrade it to ext3 you need to unmount it, so there is downtime involved. After un-mount use tune2fs
command to upgrade and mount it.
# umount /mydata
# tune2fs -j /dev/vg01/lvol0
tune2fs 1.42.13 (17-May-2015)
Creating journal inode: done
# mount /dev/vg01/lvol0 /mydata
# df -T /mydata
Filesystem Type 1K-blocks Used Available Use% Mounted on
/dev/mapper/vg01-lvol0 ext3 47463 859 43942 2% /mydata
Observe above outputs carefully. We did –
- Un-mount filesystem
- Run
tune2fs
command with-j
switch - Mount file system
ext2 has been upgraded to ext3 which can be confirmed in last output.
Make sure you make changes in /etc/fstab to reflect proper file system type for your related mount point.
How to upgrade ext3 to ext4
To upgrade to ext4 filesystem you need to enable file system features on the file system with tune2fs
command. Those are – dir_index
(Speed up directory lookups), extents
(Stores locations in inodes), uninit_bg
(reduce e2fsck
time).
After successful setting features of file system you need to run e2fsck
to fix file system data structures on disk for new modified features. To run e2fsck
you have to unmount the file system.
# tune2fs -O extents,uninit_bg,dir_index /dev/vg01/lvol0
tune2fs 1.42.13 (17-May-2015)
# e2fsck -pf /dev/vg01/lvol0
/dev/vg01/lvol0 is mounted.
e2fsck: Cannot continue, aborting.
# umount /mydata
# e2fsck -pf /dev/vg01/lvol0
/dev/vg01/lvol0: 11/13328 files (0.0% non-contiguous), 6644/53248 blocks
# mount /dev/vg01/lvol0 /mydata
# df -T /mydata
Filesystem Type 1K-blocks Used Available Use% Mounted on
/dev/mapper/vg01-lvol0 ext4 47463 859 42878 2% /mydata
In the above output, we tried to run FS check while volume is mounted and it gave us an error. Finally, the file system upgraded to ext4 which can be verified in the last output. Make a note that this is irreversible change and you can not go back to ext3 once you did this upgrade.
There is another way as well to have a file system of ext4 as below –
ext4 file system is backward compatible with ext2 and ext3. This means you can directly mount any ext2 or ext3 filesystem as ext4 without upgrading. You just simply un-mount filesystem and mount it as ext4 by supplying -t
switch with mount
command.
# umount /mydata
# mount -t ext4 /dev/vg01/lvol0 /mydata
# df -T /mydata
Filesystem Type 1K-blocks Used Available Use% Mounted on
/dev/mapper/vg01-lvol0 ext4 47463 859 43942 2% /mydata
In the above output, we un-mount out ext3 mount point and remounted it as ext4! This process is reversible means you can un-mount the ext4 file system and re-mount it as ext3 again.
How to upgrade ext2 to ext4
As we saw above you need to enable file system features to upgrade to ext4. While upgrading from ext2 to ext4 you need to enable has_journal
extra features than the above list. Since you know ext2 doesn’t have journaling available.
# umount /mydata
# tune2fs -O extents,uninit_bg,dir_index,has_journal /dev/vg01/lvol0
tune2fs 1.42.13 (17-May-2015)
Creating journal inode: done
# e2fsck -pf /dev/vg01/lvol0
/dev/vg01/lvol0: 11/13328 files (0.0% non-contiguous), 6627/53248 blocks
# mount /dev/vg01/lvol0 /mydata
# df -T /mydata
Filesystem Type 1K-blocks Used Available Use% Mounted on
/dev/mapper/vg01-lvol0 ext4 47463 842 42895 2% /mydata
Make a note that this is irreversible change and you can not go back to ext3 once you did this upgrade.
Another method would be directly mounting FS as ext4 as below –
As stated earlier, the ext4 file system is backward compatible with ext2 and ext3, means you can directly mount any ext2 or ext3 filesystem as ext4 without upgrading
# df -T /mydata
Filesystem Type 1K-blocks Used Available Use% Mounted on
/dev/mapper/vg01-lvol0 ext2 51559 842 48055 2% /mydata
# umount /mydata
# mount -t ext4 /dev/vg01/lvol0 /mydata
# df -T /mydata
Filesystem Type 1K-blocks Used Available Use% Mounted on
/dev/mapper/vg01-lvol0 ext4 51559 842 48055 2% /mydata
Previously ext2 file system is mounted as ext4 in the above output without upgrading!
Share Your Comments & Feedback: