# Error checking and mkreiserfs: why risk it?

## Sheepdogj15

It's an unfortunate fact of life: occasionally segments of disk space goes bad. A lot of times it's just a few bytes, but occasionally it ends up being a large region of the disk surface. Who knows, you might win the lottery and end up with a b0rked drive! you better have a backup.

really, it's more common than you think. these days, mosts hard disks are made for space quantity, not quality-- unless you get one made for an enterprise environment. and this should be no suprize, think of that 200GB disk you've been drooling over: would you pay twice as much for a high-quality disk with half the capacity? 

why don't we see these errors too often? well, a lot of systems are setup so that when a block, sector, or what have ya goes bad, it is eventually detected and data will not be saved there. but Bob forbid that a system file was saved there when that block goes bad.  :Evil or Very Mad: 

the specific scope of this thread is in regards to checking for bad regions before making a new filesystem on a partition. i won't talk at great length about error checking in an existing partition, for the simple fact that i don't know whether Gentoo/Linux handles that fine on its own.

now, if you are going to use ext2 or 3, this is as simple as setting the "-c" flag (as well as for the command, mkswap). however, mkreiserfs suprizingly doesn't have this functionality built in. this no doubt has led to many cases where one's partitions became pretty much a mine field... let's hope that that system file doesn't land on this bad block. this is more of a risk with older computers (since disks degrade with time), but even with newer computers there is an insurance policy most of us are willing to pay for in terms of time. 

what we will need are three tools: badblocks, your favorite partition tool, and of course mkreiserfs. both badblocks and mkreiserfs are available on the LiveCD.  badblocks is used, as the name implies, to find bad blocks. that is, we will use this to find areas on a partition which are unusable. then, those get fed to mkreiserfs, which silently thanks you for the heads up and makes sure those "blocks" are not used. now, when i say "blocks," i mean a predefined, continuous section on the disk. (the default block size for ReiserFS is 4096 bytes. you can, howerver set it to use any even value between 512-8192.)

The first step, if you haven't already, is create your partition (or partition scheme), using your favorite partitioning tool. I assume you already know how do to that.

Second, we need to create a file which will store a list of bad block locations, which mkreiserfs will later use. my suggestion is using an intuitive name, like:

```
/sbin/badblocks -b 4096 -o ~/hda1-badblocks /dev/hda1
```

relax, grab a drink, because this will take while. 

if you plan to use a block size other than the default for ReiserFS, then change the "-b" setting accordingly. i cannot stress enough that the block size must be the same throughout this process. the example above will create a file in your root folder called "hda1-badblocks." you can actually open it and read it yourself: if it's empty, then that's a good thing as that means your partition is in perfect shape. if you have bad blocks, you will see a series of numbers.

finally, you are ready to create a reiser filesystem. sticking with our example, here this is the command:

```
# mkreiserfs -B ~/hda1-badblocks /dev/hda1
```

assuming you didn't do anything silly, that should take care of it for ya. 

for more information, check the man page for badblocks(8 ). BTW, you can also use this utility to check partitions you are already using. just make sure you don't set the "-w" flag, and it is probably a good idea to avoid the "-n" flag too. also, i don't know much about other filesystems (e.g. XFS), but this might help out with those too. but again, if you are using mke2fs it's "strongly recommended" by the docs to use its built-in checking feature instead of badblocks. 

good luck, stay safe, and eat your vegetables.

----------

## adaptr

 *Quote:*   

> The first step, of course, is to create your partition, if it's not created already. If you don't know how to do that, give me your address so i can send you a mallet to hit yourself over the head with repeatedly  

 

I don't see how this has a place in a tutorial or tip.

Please either explain it or give a link.

----------

## Sheepdogj15

 *adaptr wrote:*   

> 
> 
> I don't see how this has a place in a tutorial or tip.
> 
> Please either explain it or give a link.

 

*shrug* just trying to be funny. i'll change it though.

----------

## Fog_Watch

Here is something you good people might be interested in.  I was installing Gentoo on an old disk.  I came up with the following errors.

```
# tar xjpf stage3-i686-2008.0_beta2.tar.bz2 

bzip2: I/O or other error, bailing out.  Possible reason follows.

bzip2: Input/output error

        Input file = (stdin), output file = (stdout)

tar: Unexpected EOF in archive

tar: Unexpected EOF in archive

tar: Error is not recoverable: exiting now

root@Knoppix:/mnt/hda4# rm -Rf *

root@Knoppix:/mnt/hda4# scp

hostname@hostname:/home/hostname/temp/stage3-i686-2007.0.tar.bz2 .

Password: stage3-i686-2007.0.tar.bz2                    100%  103MB

5.4MB/s 00:19 root@Knoppix:/mnt/hda4# tar xjpf

stage3-i686-2007.0.tar.bz2 bzip2: I/O or other error, bailing out.

Possible reason follows. bzip2: Input/output error

        Input file = (stdin), output file = (stdout)

tar: Unexpected EOF in archive

tar: Unexpected EOF in archive

tar: Error is not recoverable: exiting now

```

The install was going onto a ReiserFS.  I /sbin/badblocks -b 4096 -o ~/hda4-badblocks /dev/hda4 (3-4 hours of "chugging") like Sheepdogj15 suggested.  This listed heaps of badblocks.  Then I mkreiserfs -B ~/hda4-badblocks /dev/hda4.  When I unpacked stage3 I still came up with the same bzip error.

Then I tried mke2fs -c -j /dev/hda4.  This took ages too.  Stage3 then unpacked without error.  

Yes, this proves nothing.  But it adds to the  suggestions.

----------

## Cyker

The problem is badblocks is dangerous - These days, all hard disks are full of spare sectors which get swapped in when the drive firmware detects a damaged sector.

If badblocks finds a bad sector, it will mark it bad but the HD will often remap the sector anyway to one that works.

If it runs out of spare sectors, then the badblocks detected will stay, but by then the disks is probably about to die.

My personal opinion is that if the HD is developing badblocks anyway, it should be replaced/RMA'd.

Using smartmontools to do a surface scan (The long test) will refresh the surface and map out any defects in hardware. If any more develop after this is done, the drive should be replaced.

Unfortunately, there are no Linux tools AFAIK that can do the oem-specific smart diagnostics, just the generic ones.

----------

## Fog_Watch

 *Cyker wrote:*   

> smartmontools

   I think my disk is pre-SMART, ie, stupid.  Yes, the disk is only going to be used in an XTerminal.  If it dies, ah well, too bad.

----------

## Fog_Watch

 *Fog_Watch wrote:*   

> If it dies, ah well, too bad.

 

Ahhh.  Dead.  hda DriveReady SeekComplete Error.

----------

