Perform bad blocks scan on root partition in Linux

8,821

Solution 1

If your init scripts support it (Fedora IIRC), you can add -c -c to /fsckoptions (then create /forcefsck and reboot). Unfortunately, this feature isn't available everywhere. You probably have to reboot to a LiveCD/LiveUSB instead.

Solution 2

See Can I run fsck or e2fsck when Linux file system is mounted?, which notes that running any fsck on a mounted filesystem can result in disk or data corruption.

It suggests the following solutions:

A. Take down system to single user mode, unmount system, then run e2fsck

init 1
umount /dev/sda
e2fsck -y /dev/sda3

B. Boot from the installation CD into rescue mode

boot: linux rescue nomount<br/>
mknod /dev/sda
mknod /dev/sda3
fsck /dev/sda3

Another solution would be to use fsck to check the entire disk (except swap) on boot time, as root:

shutdown -Fr now

where -F stands for force fsck check and -r for reboot.

Solution 3

You can boot the system and specify init=/bin/bash as boot parameter. This will run bash at boot and not the regular startup scripts. As a result no filesystems are processed and you are left with a read-only root.

Now you have a read-only root and you can fsck it.

Solution 4

For unmounted filesystem, I also use:

dd if=/dev/diskdevice of=/dev/null

To check is any error while reading.

Share:
8,821

Related videos on Youtube

pafcu
Author by

pafcu

Updated on September 17, 2022

Comments

  • pafcu
    pafcu over 1 year

    My root partition is formatted as ext3 and I would like to perform a bad blocks scan on it. Normally e2fsck -c -c does this, but you can not run it on a mounted partition. I know it is possible to force a fsck to run at boot by creating the file /forcefsck but is it possible to specify that it should also check for bad blocks? If not, what is the recommended way to check for bad blocks on the root partition? I would like to avoid having to create a rescue disk and boot off of it.

  • harrymc
    harrymc over 13 years
    -F seems available on Fedora : see here. Did you do this as root?
  • pafcu
    pafcu over 13 years
    Actually I only checked the man page and the output of shutdown --help neither which list -F. I should file a bug about that.
  • pafcu
    pafcu over 13 years
    The reason for not documenting the -F option seems to be that the option does nothing. Possibly the command does not complain about the invalid switch to be backwards compatible with old scripts.