Ubuntu: /dev/xvda2 should be checked for errors

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
$ sudo nano /etc/default/rcS
Make sure FSCKFIX set to yes:
Save and close the file.

Step 3 – Edit /etc/fstab file

Type the following command:
$ sudo vi /etc/fstab
$ 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

$ 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

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 1 comment so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
1 comment… add one
  • Ice Alinutza Jun 17, 2017 @ 8:46

    Interesting and useful! Thank you!

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum