Technorama

An omnibus of tech posts by a Futurologist on software development primarily.

Monday, 12 November 2007

 

Check (fsck) your GNU-Linux filesystems! (ext2/ext3 & FAT)

I've had so many hard drives fail over the years that I'm sadly accustomed to running these checks on my drives to test them, and I even now run on new/replacement drives because I get faulty drives that have probably been dropped by the courier a couple of times a year as well. My longest serving drive is only around 3 years old ! Just purchased a 4GB M2 card for my Sony Ericsson K800i, that had errors straight out of the box! New drives For a new drive, it's fine to run a destructive test, which writes patterns of data and does a through "soak" test (this may take over 24hrs on a 350GB drive though): # badblocks -b 4096 -c 512 -s -v -w /dev/sdxx ^ This tests 512 blocks (4096 bytes each) at a time, which means the process takes an order of magnitude less time than the defaults. The -w flag makes it write the pattters 0xaa, 0x55, 0xff, 0x00 over every block of the drive, read it back and compare. -s and -v gets the program to display information while it is running so we know where it is up to. Drives with valid data If you're like me, and you need to also check filesystems with valid data that you can't overwrite you need to do a safe read-only check of each block. Unfortunately no distros come with a a ram root disc which includes the utils necessary to do these checks, so you'll need to boot up from a Live disc, either Knoppix, or a standard Ubuntu disc will do. Run these commands on the drive:

# badblocks -b 4096 -c 512 -s -v -n /dev/sdxx
Also, you can display the blocks which are reserved as bad on an ext2/ext3 filesystem with the command:
dumpe2fs -b /dev/sda3

Memory cards Old style DOS filesystems are still around on some memory cards (they've not reached the hard-coded limits of FAT32 yet!). So if like me, you've got a Sony Ericsson K800i, plug in the USB cable and run these commands to do an interactive check, which also scans for bad sectors:

# umount /dev/sdd1 # fsck.vfat -rtvV /dev/sdd1

Mount count checks Make sure your mount-counts are set to something reasonable, if you reboot 3 times a day set it higher, but if you only boot twice a month it might be worth having the max-mount-counts set to 1 with the -c option. Stagger your different drives with different counts (primes eh!?) to avoid overlap. So 2,3,7,11,13,17,19,23,29 etc Set a time interval with the tune2fs -i command. 

Recover a problematic partition with dd_rescue Got a failed drive that you want to recover files from? Sometimes it's not possible to mount them, so the trick is to copy it to a new drive with dd_rescue. I would have said use "dd", with a line like:

dd if=/dev/sda of=/dev/sdb bs=512, but even with conv=noerror it actually skips sectors in the output it can't read, so your new partition will have all the remaining sectors bunched up, and thus the file inode chains won't work! dd can be used with conv=noerror, sync but you also need to get the ibs set correctly and the man page is poor. So simplest is to use dd_rescue (or GNU ddrescue, or myrescue): # dd_rescue /dev/sdxx_in /dev/sdxx_out It just uses zero for sectors it can't read. Then you can run recovery tools on the new copy you made, without damaging the faulty drive further. There are various tricks like actually writing the data back to the same drive, which will cause the drive to remap the sectors (you all understand engineering tracks and that all drives ship with a certain number of mapped out bad sectors using spare sector pool right?).. which may allow you to mount the faulty drive directly. Feature wish list fsck.vfat should include a % complete indicator which updates as it progresses, so we know its still working! When your drives reach the mount count they have a display in that mode, so could go the same, like this:
|====================............|*
fsck.vfat provide a way to view the bad blocks on a drive. fsck.ext3 should provide a way to get the list of bad blocks out of the drive. (Currently we have to run dumpe2fs) dumpe2fs is actually a very useful util, for developers mostly though. (and bad blocks check as above) tune2fs lets us set the mount count, which forces a check when the system reboots (why can't distros also run other checks in this read-only mounted state?) Set the mount count with -C 4096 to force a check on the next boot (as that number is higher than the max-mount-counts) e2image useful for dumping the filesystem to a file for analysis purposes. debugfs is an interactive filesystem debugger. Tips Give your partitions a name with the tune2fs -L command, to make it simpler to identify your drives. You can also do this when creating your partitions by passing the name to: mke2fs -L (GNU+Linux distributions still aren't setting meaningful names like "boot", "root" and "home" as partition labels, doh!). The e2label /dev/sda1 Root_FS command achieves the same result as using tune2fs. Check the name of your partition by calling: dumpe2fs -h /dev/sdxx You can also name your Swap partition, first disable swap, then setup a new swap file in it with the name: # swapoff /dev/sdb1 # mkswap -L SWAP_DRV /dev/sdb1 You can list the labels of your partitions by using the "blkid" shell command too! As fdisk -l only gives the partition types. Never had success reading S.M.A.R.T. from GNU+Linux, always didn't support my drives. smartctrl is part of that live disc, so you may be lucky if you try. (I'm informed the atausb driver mgiht support S.M.A.R.T. although my drive uses ata_piix driver) Finally, be really careful when using these commands, as you could destroy your data! If you ever need it, you can force the kernel to sync and remount all filesystems read-only by pressing Ctrl + Alt + SysRq + s, followed by Ctrl + Alt + SysRq + u. Then do Ctrl + Alt + SysRq + b to reboot the system.

Labels: ,


Comments: Post a Comment

Subscribe to Post Comments [Atom]





<< Home

Archives

February 2003   March 2003   April 2003   August 2004   September 2004   December 2004   May 2005   June 2005   December 2006   January 2007   February 2007   March 2007   April 2007   July 2007   August 2007   September 2007   October 2007   November 2007   December 2007   January 2008   February 2008   March 2008   April 2008   May 2008   June 2008   July 2008   August 2008   September 2008   October 2008   November 2008   December 2008   January 2009   February 2009   March 2009   April 2009   September 2009   November 2009   December 2009   January 2010   April 2010   September 2010   October 2010   November 2010   December 2010   January 2011   February 2011   March 2011   April 2011   May 2011   June 2011   July 2011   August 2011   September 2011   October 2011   November 2011   December 2011   January 2012   February 2012   March 2012   April 2012   May 2012   June 2012   July 2012   October 2012   December 2012   March 2013   May 2013   August 2013   September 2013   October 2013   November 2013   March 2014   May 2014   June 2014   July 2014   September 2014   October 2014   December 2014   January 2015   February 2015   March 2015   April 2015   May 2015   June 2015   July 2015   August 2015   September 2015   October 2015   November 2015   December 2015   March 2016   April 2016   May 2016   July 2016   August 2016   September 2016   October 2016   November 2016   December 2016   January 2017   February 2017   March 2017   April 2017   May 2017   June 2017   July 2017   August 2017   September 2017   November 2017   March 2018   April 2018   May 2018   June 2018   August 2018   October 2018   December 2018   January 2019   March 2019   May 2019   August 2019   September 2019   March 2020   April 2020   May 2020   September 2020   October 2020   February 2022   June 2022   July 2022   October 2022   December 2022   February 2023   April 2023   September 2023   October 2023   May 2024   June 2024   July 2024  

This page is powered by Blogger. Isn't yours?

Subscribe to Posts [Atom]