6

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.

5 Answers 5

5

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.

5

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.

4
  • shutdown seems to be missing the -F flag in my Fedora 13 and 14 installs. It would probably not use the "-c -c" option in any case.
    – pafcu
    Nov 28, 2010 at 11:52
  • -F seems available on Fedora : see here. Did you do this as root?
    – harrymc
    Nov 28, 2010 at 12:09
  • 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
    Nov 28, 2010 at 12:27
  • 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.
    – pafcu
    Nov 28, 2010 at 12:54
2

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.

1

For unmounted filesystem, I also use:

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

To check is any error while reading.

0

I use

cat /dev/diskdevice >/dev/null

and then check what is in dmesg. If there is a bad block, it will say. The repair is another long story.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .