Repair EXT4 Filesystem

Most of V3next VPS Servers are pre-build using XFS filesystem. However, sometimes you may find yourself facing EXT4 filesystem, if you created it manually as an example.

Sometimes, EXT4 volumes are damaged for some reason. This is often happening in VPS environments because of virtual IO block devices, which behave not exactly like their more-guaranteed pure hardware equivalents. Lame write caching, alignment problems, partial writes - that's common problems in VPS HDDs, to name a few. That unavoidable feature of value-priced virtualized environments is not a showstopper, but should be treated seriously.

To make clear what is what:

lsblk -o NAME,FSTYPE,SIZE,MOUNTPOINT,LABEL
OR
sudo lsblk -o NAME,FSTYPE,SIZE,MOUNTPOINT,LABEL

How to Repair Damaged EXT4 Filesystem

First step in repairing any filesystem is TO MAKE BACKUP OF ANY DATA CURRENTLY STILL READABLE. It is very important step, because very often repair will make things worse. You may require read-only mount to make things more robust while trying to save your data:

mount -o ro device mountpoint

After all data is in safe place, let's start repair. In order to repair damaged EXT4 volume, fsck.ext4 package is required. It is always present in any modern distro. Actually the commands are very simple.

First, you must attempt to mount and unmount EXT4 normally. This is done via regular read/write mount such as this:

mount device mountpoint
umount mountpoint

Sometimes the system will become unresponsive after mounting broken filesystem. Additional reboot may be required.

It is required to replay transaction log, if it is still present. Sometimes, EXT4 will not mount and that is OK, then, proceed to the real repair. Which is actually very simple -

fsck.ext4 -p device

Repair can crash or stop, or you may want to stop it yourself - that is safe. According to manuals, repair can be started and stopped any time.

Fixing Problems with Boot or Root Filesystem

Fixing boot/root volume can be tricky. The only safe thing come to mind is to remount root as read-only, and then to repair it manually. You MUST NOT attempt to repair filesystem while the system is online.

mount -o ro,remount /

And then proceed with the regular repair. After you mount your root read-only, the system will not function normally, so be prepared to do immediate reboot after this recovery attempt.

If this approach fails, you may also consider booting to rescue ISO, contact V3next Support Team to help you with that.

Success and Failure Outcome Ratio

Sad to say, when EXT4 starts feeling it needs repair, there are some chances that you will lose the data, because key components of the filesystem are badly damaged already. That is especially true for small volumes, where chances are higher that some fault hit important part of the data. Backup may be your first friend here. However, repairing worth a try.

This website uses cookies to ensure you get the best experience on our website.