Check an AWS EC2 Volume `/dev/xvda1` for errors

When logging in an EC2 (VM) instance may notify you that the mounted volume should be checked for errors:

*** /dev/xvda1 should be checked for errors ***

Doing so requires some manual work beyond just starting fsck.

The device /dev/xvda1 is mounted, so fsck can not reasonably be run online.

And given that we instruct fsck to repair any faulty sections you should create a volume snapshot as a backup before proceeding.

Edit rcS file sudo vim /etc/default/rcS

#FSCKFIX=no -> FSCKFIX=yes

Edit fstab file sudo vi /etc/fstab

LABEL=cloudimg-rootfs / ext4 defaults,discard 0 0 LABEL=cloudimg-rootfs / ext4 defaults,discard 0 1

Look for the the record for / and if the last digit is ‘0’ change it to ‘1’. The last field is fsckorder and is used by fsck to decide the order of checking disks. If the value is ‘0’ that disk is skipped.

Create /forcefsck file sudo touch /forcefsck

Reboot shutdown -r 0

Once the machine is back online the should-be-checked-notice should not be displayed anymore.

The file /forcefsck is removed automatically. It was a trigger for the fsck on boot.

The other two settings have to be reverted manually.

https://serverfault.com/a/679051/58840