自在工坊

走在代码边缘

Linux命令-FSCK磁盘修复

Debian服务器磁盘有问题,fsck/e2fsck是Linux常用的命令行文件系统修复工具,使用以上工具尝试修复,记录下操作过程;

首页,要Umount文件系统

$ umount /dev/sdc1

-p option为自动修复选项,无需人工干预

$ fsck -p /dev/sdc1

Repair Root file system

fsck cannot check the root file system on a running machine because it cannot be unmounted.

If you want to check or repair the root file system, you have several options at your disposal. You can set the fsck to run on boot, boot the system in recovery mode, or use a live CD.

To run fsck in recovery mode:

Enter the boot menu and choose Advanced Options
Select the Recovery mode and then “fsck”.
When prompted to remount the root file system choose “Yes”.
Once done, resume the normal boot.
To run fsck from a live distribution:

Boot the live distribution.

Use fdisk or parted to find the root partition name.

Open the terminal and run:

sudo fsck -p /dev/sda1
Copy
Once done, reboot the live distribution and boot your system.

Check File Systems on Boot
On most Linux distributions, fsck runs at boot time if a file system is marked as dirty or after a certain number of boots or time.

To see the current mount count, check frequency number, check interval, and the time of the last check for a specific partition, use the tune2fs tool:



sudo tune2fs -l /dev/sdc1 | grep -i 'last checked\|mount count'
Copy
Mount count:              292
Maximum mount count:      -1
Last checked:             Tue Jul 24 11:10:07 2018
Check interval:           0 (<none>)
Copy
“Maximum mount count” is the number of mounts after which the filesystem will be checked. The value of 0 or -1 means that fsck will never run.
“Check interval” is the maximal time between two filesystem checks.
If for example, you want to run fsck after every 25 boots (mounts), type:

sudo tune2fs -c 25 /dev/sdc1
Copy
You can also set the maximal time between two checks. For example, to set it one month you would run:

sudo tune2fs -i 1m /dev/sdc1
Copy
To force fsck to run at boot time on SystemD distributions pass the following kernel boot parameters:

fsck.mode=force
fsck.repair=yes
Copy
On older distributions fsck will run on boot if the /forcefsck file is present:

sudo touch /forcefsck

Links:

  • https://linuxize.com/post/fsck-command-in-linux/
  • https://www.smartmontools.org/wiki/BadBlockHowto

Pelican Image

Comments