Logo
  • Ubuntu
  • CentOS
  • Debian
  • Fedora
  • RedHat

Fsck Command in Linux (Repair File System) - DesignLinux

Sep 26 2020
designlinux 0 Comments
Fsck Command in Linux (Repair File System)

The fsck command is used to check perform consistency and repair Linux file systems. It is useful to repair corrupted file systems when system fails to boot, or a partition cannot be mounted. We will discuss about the fsck command in this article.

Make sure you are logged in with root or user with sudo privileges.

How to Use fsck#

Following is the basic syntax of fsck command:

fsck [OPTIONS] [FILESYSTEM]

If you run the fsck command without any options, it will check the devices listed in the fstab file.

It’s recommended to always unmount the mounted partitions before attempting to check or repair file systems. It may damage your mounted file systems.

The fsck command accepts different options depending on the file system’s type. For example, to view the options available for fsck.ext4, type:

man fsck.ext4

Repair Corrupted File System#

It is a common use of the fsck command to repair a non-root corrupted ext3 or ext4 file system.

1. Find the device name using fdisk, df or any other tool to find.

2. Unmount the device:

sudo umount /dev/sdc1

3. Run fsck to repair the file system:

sudo fsck -p /dev/sdc1

Here, -p option is used to repair the problems automatically safely without user intervention.

4. When the file system is repaired, again mount the partition:

sudo mount /dev/sdc1

Repair Root File System#

In the current running system fsck command cannot check the root file system. You can set the fsck to run on boot, or use a live disk.

You also can run fsck command in recovery mode:

  • Go to the boot menu and choose Advanced Options
  • Select the Recovery mode and then “fsck”.
  • Choose “Yes” when it prompt to remount the root file system.
  • Once done, resume the normal boot.

To run fsck from a live distribution:

1. Boot the live distribution.

2. Use fdisk or parted to find the root partition name.

3. Open the terminal and run:

sudo fsck -p /dev/sda1

4. Once done, reboot the live distribution and boot your system.

Check File Systems on Boot#

Generally, all Linux distributions runs fsck at boot time, if a file system is marked as dirty.

Use the tune2fs tool to get the current mount count, check frequency number, check interval, and the time of the last check for a specific partition:

sudo tune2fs -l /dev/sdc1 | grep -i 'last checked|mount count'
Mount count:              392
Maximum mount count:      -1
Last checked:             Tue Oct 01 10:11:08 2019
Check interval:           0 (<none>)

In Maximum mount count shows the number of mounts after which the filesystem will be checked. If the value is 0 or -1 that means fsck will never run.

Check interval is the maximal time between two filesystem checks.

For example, you want to run fsck after every 15 boots or mounts, you would type:

sudo tune2fs -c 15 /dev/sdc1

You also can set the maximal time between two checks. For instance, to set two month run:

sudo tune2fs -i 2m /dev/sdc1

To force fsck to run at boot time on SystemD distributions pass the following kernel boot parameters:

fsck.mode=force
fsck.repair=yes

Conclusion#

The fsck is a command-line tool for checking and repairing Linux file systems. Visit the fsck man page or type man fsck in your terminal, to learn more about the fsck command.

If you have any questions or feedback, feel free to leave a comment.

Related

Tags: fsck, terminal

7 Amazing Linux Distributions For Kids

Prev Post

How to Add or Remove a User from a Group in Linux

Next Post
Archives
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022
  • July 2022
  • June 2022
  • April 2022
  • March 2022
  • February 2022
  • January 2022
  • December 2021
  • November 2021
  • October 2021
  • September 2021
  • August 2021
  • July 2021
  • June 2021
  • May 2021
  • April 2021
  • March 2021
  • February 2021
  • January 2021
  • December 2020
  • November 2020
  • October 2020
  • September 2020
  • August 2020
  • July 2020
  • June 2020
  • May 2020
Categories
  • AlmaLinux
  • Android
  • Ansible
  • Apache
  • Arch Linux
  • AWS
  • Backups
  • Bash Shell
  • Bodhi Linux
  • CentOS
  • CentOS Stream
  • Chef
  • Cloud Software
  • CMS
  • Commandline Tools
  • Control Panels
  • CouchDB
  • Data Recovery Tools
  • Databases
  • Debian
  • Deepin Linux
  • Desktops
  • Development Tools
  • Docker
  • Download Managers
  • Drupal
  • Editors
  • Elementary OS
  • Encryption Tools
  • Fedora
  • Firewalls
  • FreeBSD
  • FTP
  • GIMP
  • Git
  • Hadoop
  • HAProxy
  • Java
  • Jenkins
  • Joomla
  • Kali Linux
  • KDE
  • Kubernetes
  • KVM
  • Laravel
  • Let's Encrypt
  • LFCA
  • Linux Certifications
  • Linux Commands
  • Linux Desktop
  • Linux Distros
  • Linux IDE
  • Linux Mint
  • Linux Talks
  • Lubuntu
  • LXC
  • Mail Server
  • Manjaro
  • MariaDB
  • MongoDB
  • Monitoring Tools
  • MySQL
  • Network
  • Networking Commands
  • NFS
  • Nginx
  • Nodejs
  • NTP
  • Open Source
  • OpenSUSE
  • Oracle Linux
  • Package Managers
  • Pentoo
  • PHP
  • Podman
  • Postfix Mail Server
  • PostgreSQL
  • Python
  • Questions
  • RedHat
  • Redis Server
  • Rocky Linux
  • Security
  • Shell Scripting
  • SQLite
  • SSH
  • Storage
  • Suse
  • Terminals
  • Text Editors
  • Top Tools
  • Torrent Clients
  • Tutorial
  • Ubuntu
  • Udemy Courses
  • Uncategorized
  • VirtualBox
  • Virtualization
  • VMware
  • VPN
  • VSCode Editor
  • Web Browsers
  • Web Design
  • Web Hosting
  • Web Servers
  • Webmin
  • Windows
  • Windows Subsystem
  • WordPress
  • Zabbix
  • Zentyal
  • Zorin OS
Visits
  • 0
  • 40
  • 612,219

DesignLinux.com © All rights reserved

Go to mobile version