Ubuntu: /dev/xvda2 should be checked for errors

Posted on in Categories , , , , , last updated June 16, 2017

When I log in to my Ubuntu Linux 16.04 LTS AWS cloud server, I get the message on screen: /dev/xvda2 should be checked for errors. I can not run fsck command on /dev/xvda1 because it is mounted. How do I check my disk for error without corrupting data?

*** /dev/xvda2 should be checked for errors ***
You can check or run fsck on /dev/xvda1 using the following method on Ubuntu or Debian Linux based cloud server. The fsck command is used check and repair a Linux filesystem

Step 1 – Force fsck

Type the following command to force fsck on reboot:
$ sudo touch /forcefsck

Step 2 – Configure fsck during boot

You must do automatic repair filesystems with inconsistencies during boot. Run command:
$ sudo vi /etc/default/rcS
OR
$ sudo nano /etc/default/rcS
Make sure FSCKFIX set to yes:
FSCKFIX=yes
Save and close the file.

Step 3 – Edit /etc/fstab file

Type the following command:
$ sudo vi /etc/fstab
OR
$ sudo nano /etc/fstab
Find out the record for / or /boot/ and if the last digit is ‘0’ change it to ‘1’. For example:


LABEL=cloudimg-rootfs   /        ext4   defaults,relatime       0 0

Change to 1:


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

Save and close the file. The last field is used by fsck command to determine the order in which filesystem checks are done at boot time. The root (/) filesystem should be specified with avalue of 1. Other filesystems should have a value of 2.

Step 4 – Reboot the system

Type the following command to reboot the Linux server/desktop:
$ sudo reboot
This will run fsck on reboot and fix any problem too.

Step 5 – Revert changes

Once booted, you can change value from ‘1’ to ‘0’ in /etc/fstab file using a text editor such as vi or nano. Make sure you set the line FSCKFIX to no (FSCKFIX=no) in /etc/default/rcS file too. Verify updated setting with grep command:
$ grep 'FSCKFIX' /etc/default/rcS
FSCKFIX=no

$ grep 'LABEL=cloudimg-rootfs' /etc/fstab

LABEL=cloudimg-rootfs   /        ext4   defaults,relatime       0 0


For more information read the following man pages:
$ man fstab
$ man fsck

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin and a trainer for the Linux operating system/Unix shell scripting. He has worked with global clients and in various industries, including IT, education, defense and space research, and the nonprofit sector. Follow him on Twitter, Facebook, Google+.

Share this on (or read 1 comments/add one below):

1 comment

Leave a Comment