---

How to migrate and repair the ext2 ext3ext4 file systems in Linux?

Your Linux file systems Ext2 or Ext3 have now gone outdated. It’s the time to convert the crispy old file systems to the latest one, EXT4. The Ext4 is faster, stable and more reliable than the previous versions.

Don’t worry! You need not clean install the system; you can simply convert your existing file system to EXT4 by keeping the stored data unaffected.

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

2. Boot from Ubuntu Live CD

3. Run the following command to convert from ext2 to ext4:

sudo bash
tune2fs -O extents,uninit_bg,dir_index,has_journal /dev/sda1

For converting from ext3 to ext4, run the command:

sudo bash
tune2fs -O extents,uninit_bg,dir_index /dev/sda1

Here, /dev/sda1 is the drive / partition name to be converted.

4. 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. 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. Open the /etc/fstab file.
Search for previous file system reference (ext2 or ext3) and edit it to ext4. Save the changes made to the file and exit.

7. Now run the sudo bash command to refresh grub:

If the boot partition is SEPARATE:

sudo bash
mkdir /mnt/boot
mount /dev/sda1 /mnt/boot
grub-install /dev/sda –root-directory=/mnt –recheck

If the boot partition is NOT separate:

sudo bash
mount /dev/sda1 /mnt
grub-install /dev/sda –root-directory=/mnt –recheck

8. Once all done, reboot the system

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:
# init 1
# umount Fs-Name

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/sda3
or
fsck.ext3 /dev/sda3

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.
Run # mount /dev/sda3

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.

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends, & analysis