Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question

5 Answers 5

up vote 2 down vote accepted

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.

share|improve this answer

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.

share|improve this answer
    
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 '10 at 11:52
    
-F seems available on Fedora : see here. Did you do this as root? –  harrymc Nov 28 '10 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 '10 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 '10 at 12:54

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.

share|improve this answer

For unmounted filesystem, I also use:

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

To check is any error while reading.

share|improve this answer

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.