How to Migrate Ext2/Ext3 File Systems to Ext4 on Linux
On this page
- How to migrate the ext2 or ext3 partition to ext4
- Steps to repair the file system using fsck
The Linux file systems Ext2 and Ext3 have now gone outdated. It is the time to convert the old file systems to the latest one, EXT4. The Ext4 filesystem is faster and more reliable than the previous versions.
Don’t worry! You dont have to reinstall the system; you can simply convert your existing file system to EXT4 by keeping the stored data unaffected.
In this tutorial I will show the steps to be taken on Ubuntu. The same commands will work for other Linux Dustributions as well.
How to migrate the ext2 or ext3 partition to ext4
First backup all your data then follow the given steps.
1. First of all, check for your kernel.
Run uname –r command to know the kernel you are using.
Proceed with the next step if you have kernel 2.6.28-11-generic or higher.
[email protected]:/# uname -r
2. Boot from Ubuntu Live CD
3 Convert the filesystem to ext4
Run the following command to convert from ext2 to ext4:
tune2fs -O extents,uninit_bg,dir_index,has_journal /dev/sda1
For converting from ext3 to ext4, run the command:
tune2fs -O extents,uninit_bg,dir_index /dev/sda1
Here, /dev/sda1 is the drive / partition name to be converted. To get a list of all partitions, use the command:
4. Check the filesystem for errors
After running sudo commands, run fsck command to fix any repair issue that might have occurred during the above steps:
e2fsck -pf /dev/sda1
5. Mount the filesystem
Run sudo mount command to mount the partition:
sudo mount -t ext4 /dev/sda1 /mnt
You can check /mnt directory to ensure that the previous data is present there unaffected.
6. Update the filesystem type in fstab file
Open the /etc/fstab file of your original system. If you mounted it to /mnt, then the path is /mnt/etc/fstab.
Search for previous file system reference (ext2 or ext3) and edit it to ext4. Save the changes made to the file and exit.
7. Update grub
Now run the sudo bash command to refresh grub:
Once all done, unmount /dev/sda and reboot the system.
shutdown -r now
If there is some damage to the Linux file system, you can fix it using fsck utility. It works well for ext2 or ext3 or ext4 File Systems. To Repair Linux ext2 or ext3 or ext4 file system, run the following commands as root user.
Steps to repair the file system using fsck
1. First un-mount the file system:
Replace /dev/sda1 in the above command with the name of the damaged filesystem.
eg. umount /dev/sda3 or umount /home
2. Run fsck Fs-Name
Here, Fs-Name can be a device name, mount point, ext2 label, UUID specifier
For example, Run:
fsck -t ext3 /dev/sda1
3. Here, using (‘-t’ or ’.’ you can specify the file system type)
4. Pass the 'y' or ’N’ option along with the fsck command like this: fsck -y /dev/sda3. Or you can type it every time the system asks yes or no while fsck process.
5. After running the fsck command the system would check for errors in the file system.
6. Remount the system after fsck process has been completed.
Note: If you are cautious about any of the commands given above, I would like to suggest you that instead of trying the above manual tools opt for some automatic file system conversion and repair tool for Linux.
If want to run the manual steps given above ‘don’t forget to backup all you data before proceeding.
Fsck failed to repair the Linux file systems?
No worries, you can try out the Linux recovery tools that allow you to recover the inaccessible data from any Ext4, Ext3, Ext2, exFAT, FAT32, FAT16, and FAT12 file system based LINUX volumes in an easy and safe way as compared to the manual mode.