Difference between revisions of "Fsck"

From ArchWiki
Jump to: navigation, search
(Repair damaged blocks interactively)
(replaced external links (https://github.com/lahwaacz/wiki-scripts/blob/master/link-checker.py (interactive)))
 
(29 intermediate revisions by 13 users not shown)
Line 1: Line 1:
 
{{Lowercase title}}
 
{{Lowercase title}}
 
[[Category:File systems]]
 
[[Category:File systems]]
 +
[[fr:Fsck]]
 +
[[ja:Fsck]]
 
[[ru:Fsck]]
 
[[ru:Fsck]]
{{Article summary start}}
+
{{Related articles start}}
{{Article summary text|Information on how to use fsck.}}
+
{{Related|Ext4}}
{{Article summary heading|Related}}
+
{{Related|Btrfs}}
{{Article summary wiki|Ext4}}
+
{{Related|fstab}}
{{Article summary wiki|Btrfs}}
+
{{Related articles end}}
{{Article summary wiki|fstab}}
+
{{Article summary end}}
+
 
+
 
[[Wikipedia:Fsck|fsck]] stands for ''"file system check"'' and it is used to check and optionally repair one or more Linux file systems. Normally, the fsck program will try to handle filesystems on different physical disk drives in parallel to reduce the total amount of time needed to check all of the filesystems (see: {{ic|man fsck}}).
 
[[Wikipedia:Fsck|fsck]] stands for ''"file system check"'' and it is used to check and optionally repair one or more Linux file systems. Normally, the fsck program will try to handle filesystems on different physical disk drives in parallel to reduce the total amount of time needed to check all of the filesystems (see: {{ic|man fsck}}).
  
The [[Arch Boot Process|Arch Linux boot process]] conveniently takes care of the fsck procedure for you and will check all relevant partitions on your drive(s) automatically on every boot. Hence, there is usually no need to resort to the command-line unless necessary.
+
The [[Arch boot process|Arch Linux boot process]] conveniently takes care of the fsck procedure for you and will check all relevant partitions on your drive(s) automatically on every boot. Hence, there is usually no need to resort to the command-line unless necessary.
  
== Checking ==
+
== Boot time checking ==
  
The filesystem can be checked by creating a {{ic|forcefsck}} file on the partition you wish to check later. For example, for the root partition it would be:
+
=== Mechanism ===
  
# touch /forcefsck
+
There are two players involved:
  
When you're ready, reboot and fsck will do the rest. And don't worry, this file will be removed automatically when the process is finished.
+
# mkinitcpio offers you the option to fsck your root filesystem before mounting it via the fsck hook. If you do this, you should mount root read-write via the appropriate {{ic|rw}} kernel parameter.[https://projects.archlinux.org/mkinitcpio.git/commit/?id=449b3e543c]
 +
# systemd will fsck all filesystems having a fsck pass number greater than 0 (either from {{ic|/etc/fstab}} or a user-supplied unit file). For the root filesystem, it also has to be mounted read-only initially with the kernel parameter {{ic|ro}} and only then remounted read-write from [[fstab]] (note that the {{ic|defaults}} mount option implies {{ic|rw}}).
  
== Tips and tricks ==
+
The first option is the recommended default, and what you will end up with if you follow the [[Installation guide]]. If you want to go with option 2 instead, you should remove the fsck hook from {{ic|mkinitcpio.conf}} and use {{ic|ro}} on the kernel commandline. The kernel parameter {{ic|1=fsck.mode=skip}} can be used to make sure fsck is disabled entirely for both options.
  
=== Cancelling the process ===
+
=== Forcing the check ===
{{Accuracy|Doesn't work. Tried adding {{ic|1=FILES="/etc/e2fsck.conf"}} to [[mkinitcpio.conf]] and rebuilding the initramfs images, but still nothing. ''--DSpider, 12 January 2013''}}
+
  
To cancel a running fsck check during boot time, create the following file:
+
You can also force fsck at boot time by passing {{ic|1=fsck.mode=force}}, as a [[kernel parameter]]. This will check every filesystem you have on the machine.
  
{{hc|/etc/e2fsck.conf|2=
+
{{Note|For those accustomed to use other GNU/Linux distributions, the old tricks consisting in writing a file with the name {{ic|forcefsck}} to the root of each filesystem or using the command {{ic|shutdown}} with the {{ic|-F}} flag were only working for the old [[SysVinit]] and early versions of [[wikipedia:Upstart|Upstart]] and are not working with [[systemd]]. The aforementioned solution is thus the only one working for Arch Linux.}}
[options]
+
allow_cancellation = true
+
}}
+
  
Now you should be able to cancel it with {{Keypress|Ctrl+C}}.
+
== Tips and tricks ==
  
 
=== Attempt to repair damaged blocks ===
 
=== Attempt to repair damaged blocks ===
Line 85: Line 81:
 
=== Can't run fsck on a separate /usr partition ===
 
=== Can't run fsck on a separate /usr partition ===
  
# Make sure you have the required [https://wiki.archlinux.org/index.php/Mkinitcpio#.2Fusr_as_a_separate_partition hooks] in {{ic|/etc/mkinitcpio.conf}} and that you remembered to re-generate your initramfs image after editing this file.
+
# Make sure you have the required [[Mkinitcpio#.2Fusr_as_a_separate_partition|hooks]] in {{ic|/etc/mkinitcpio.conf}} and that you remembered to re-generate your initramfs image after editing this file.  
# Make sure that the bootloader has {{ic|ro}} on the "APPEND" line in {{ic|/boot/syslinux/syslinux.cfg}} (for Syslinux). GRUB doesn't need one; it is added automatically when you generate a .cfg. For an explanation as to why you ''need'' "ro", see [https://bbs.archlinux.org/viewtopic.php?pid=1114554#p1114554 this] post.  
+
 
# Check your [[fstab]]! Only the root partition needs "1" at the end, everything else should have either "2" or "0". Carefully inspect it for other typos, as well.
 
# Check your [[fstab]]! Only the root partition needs "1" at the end, everything else should have either "2" or "0". Carefully inspect it for other typos, as well.
  
Line 93: Line 88:
 
There are times (due to power failure) in which an ext(3/4) file system can corrupt beyond normal repair. Normally, there will be a prompt from fsck indicating that it cannot find an external journal. In this case, run the following commands:
 
There are times (due to power failure) in which an ext(3/4) file system can corrupt beyond normal repair. Normally, there will be a prompt from fsck indicating that it cannot find an external journal. In this case, run the following commands:
  
{{bc|<nowiki>
+
Unmount the partition based on its directory
# umount <directory>;  ## unmount the partition based on its directory
+
# umount <directory>
# tune2fs -j /dev/<partition>;  ## write a new journal to the partition
+
Write a new journal to the partition
# fsck -p /dev/<partition>;  ## run an fsck to repair the partition
+
# tune2fs -j /dev/<partition>
</nowiki>
+
Run an fsck to repair the partition
}}
+
# fsck -p /dev/<partition>

Latest revision as of 21:54, 27 February 2016

Related articles

fsck stands for "file system check" and it is used to check and optionally repair one or more Linux file systems. Normally, the fsck program will try to handle filesystems on different physical disk drives in parallel to reduce the total amount of time needed to check all of the filesystems (see: man fsck).

The Arch Linux boot process conveniently takes care of the fsck procedure for you and will check all relevant partitions on your drive(s) automatically on every boot. Hence, there is usually no need to resort to the command-line unless necessary.

Boot time checking

Mechanism

There are two players involved:

  1. mkinitcpio offers you the option to fsck your root filesystem before mounting it via the fsck hook. If you do this, you should mount root read-write via the appropriate rw kernel parameter.[1]
  2. systemd will fsck all filesystems having a fsck pass number greater than 0 (either from /etc/fstab or a user-supplied unit file). For the root filesystem, it also has to be mounted read-only initially with the kernel parameter ro and only then remounted read-write from fstab (note that the defaults mount option implies rw).

The first option is the recommended default, and what you will end up with if you follow the Installation guide. If you want to go with option 2 instead, you should remove the fsck hook from mkinitcpio.conf and use ro on the kernel commandline. The kernel parameter fsck.mode=skip can be used to make sure fsck is disabled entirely for both options.

Forcing the check

You can also force fsck at boot time by passing fsck.mode=force, as a kernel parameter. This will check every filesystem you have on the machine.

Note: For those accustomed to use other GNU/Linux distributions, the old tricks consisting in writing a file with the name forcefsck to the root of each filesystem or using the command shutdown with the -F flag were only working for the old SysVinit and early versions of Upstart and are not working with systemd. The aforementioned solution is thus the only one working for Arch Linux.

Tips and tricks

Attempt to repair damaged blocks

To automatically repair damaged portions, run:

Warning: This will not ask if you want to repair it, as the answer is Yes when you run it.
# fsck -a

Repair damaged blocks interactively

Tip: This is useful for when file on the boot partition have changed, and the journal failed to properly update. In this case, unmount the boot partition, and run the following code:

To repair damaged portions, run :

# fsck -r <drive>

Changing the check frequency

By default, fsck checks a filesystem every 30 boots (counted individually for each partition). To change the frequency of checking, run:

# tune2fs -c 20 /dev/sda1

In this example, 20 is the number of boots between two checks.

Note that 1 would make it scan at every boot, while 0 would stop scanning altogether.

Tip: If you wish to see the frequency number and the current mount count for a specific partition, use:
# dumpe2fs -h /dev/sda1 | grep -i 'mount count'

fstab options

fstab is a system configuration file and is used to tell the Linux kernel which partitions (file systems) to mount and where on the file system tree.

A typical /etc/fstab entry may look like this:

/dev/sda1   /         ext4      defaults       0  1
/dev/sda2   /other    ext4      defaults       0  2
/dev/sda3   /win      ntfs-3g   defaults       0  0

The 6th column (in bold) is the fsck option.

  • 0 = Do not check.
  • 1 = First file system (partition) to check; / (root partition) should be set to 1.
  • 2 = All other filesystems to be checked.

Troubleshooting

Can't run fsck on a separate /usr partition

  1. Make sure you have the required hooks in /etc/mkinitcpio.conf and that you remembered to re-generate your initramfs image after editing this file.
  2. Check your fstab! Only the root partition needs "1" at the end, everything else should have either "2" or "0". Carefully inspect it for other typos, as well.

ext2fs : no external journal

There are times (due to power failure) in which an ext(3/4) file system can corrupt beyond normal repair. Normally, there will be a prompt from fsck indicating that it cannot find an external journal. In this case, run the following commands:

Unmount the partition based on its directory

# umount <directory>

Write a new journal to the partition

# tune2fs -j /dev/<partition>

Run an fsck to repair the partition

# fsck -p /dev/<partition>