Find out how to back up and restore your disk partitions in Linux
Disk errors
Sometimes a filesystem can become damaged or inconsistent, such as when there is
a sudden power loss. These kinds of errors can usually be detected and fixed
with standard filesystem tools, like e2fsck.
Most distributions perform routine scans to check for problems like these. But if there is a hardware error on the disk drive itself (a bad sector), this can go undetected for a long time, and means the filesystem on the affected partition can never be fixed in place.
If you want to recover this data, you might try to extract the raw partition data using dd, in the same way as you would clone the partition. This would be fine for a partition with filesystem errors alone, but it isn’t so simple with hardware errors. The dd command would read as far as it could, and then stop with an error when it could not read the bad sector on the drive. There is an alternative to dd for situations like this, called ddrescue. There are in fact two different tools, each with the same name, but here we are looking at the GNU version of ddrescue.
This tool is very similar to dd, and in the case of there being no hardware errors on the partition, is effectively the same. In the case of an error, ddrescue does not fall over and stop. Instead it tries its best to recover as much data from the partition as possible. It also creates a logfile of its progress, so if it is interrupted, it can be resumed from where it left off. This is especially useful for less predictable hardware errors than unreadable sectors, as ddrescue can be run multiple times on the same partition to try to recover the lost data; it will fill the gaps in the recovery image file as best as it can.
To install ddrescue in Ubuntu, you must select ‘gddrescue’ to specify this particular version:
# apt-get install gddrescue
The standard usage of ddrescue is mostly the same as dd, except there are no ‘if’ and ‘of’ options. To copy or recover all the data from /dev/sda1 and put it into the file/backup/img.bin:
# ddrescue -v /dev/sda1 /backup/img.bin /tmp/reclog
First comes the input file or device, then the output, and then the logfile. The logfile is optional, but it’s always a good idea to create it. We’re specifying the verbose (-v) option here to see additional information.
As above, ddrescue works as a drop-in substitute for dd, as without any errors on this partition a full copy is made. Ddrescue also has the advantage of potentially a small performance increase (due to the way it uses buffers).
Checking for errors
Although ddrescue is designed for copying and recovering data from drives, it
will also draw your attention to any errors on the disk. Duplicating an entire
disk to detect errors does not seem the most sensible way to go about this, and
thankfully Linux’s standard /dev/null device means it is not necessary.
Anything sent to /dev/null is ignored, and so just specify this as the output
device. You can check an entire drive, such as /dev/sda, in this way:
# ddrescue -v /dev/sda /dev/null /tmp/reclog
In this example, ddrescue will read all of the data from the hard drive
without copying any of it. If there are any bad sectors on the drive, they will
show up clearly. In this case, as no data is being backed up or restored, you
may run it on a hard drive which is in use, although wait until there is little
or no disk activity.
I advise running a command like this on a brand new hard drive, as bad sectors
often don’t show themselves until the drive begins to fill, especially with
large drives. It is not necessary to run a check like this frequently; doing so
would add unnecessary wear to the hard drive.
Article tags
Related articles
Q.Why are some of the keys on my keyboard doing strange...
Q.Is my phone’s Bluetooth any use?
Q.Can I switch boot drives so that I can work on older...
Old Street roundabout is being touted by the Government as the UK's answer to Silicon Valley, but it seems our best innovations are coming from all over the UK
|
|
|
|
|
Computeractive Excel (2010) Online tutorialPrice: £19.99 |
Computeractive Word (2010) Online TutorialPrice: £19.99 |
Computeractive Powerpoint (2010) Online TutorialPrice: £19.99 |
Angry BirdsPrice: £9.99 |
Back Issue CD-Rom 14 (2011)Price: £15.99 |