Next: , Previous:   [Index]


13 Fill mode

When ddrescue is invoked with the option --fill-mode it operates in "fill mode", which is different from the default "rescue mode". That is, in "fill mode" ddrescue does not rescue anything. It only fills with data read from infile the blocks of outfile whose status character from mapfile coincides with one of the type characters specified in the argument to --fill-mode.

If the argument to --fill-mode contains an ‘l’, ddrescue will write location data (position, sector number, and status) into each sector filled. With bad sectors filled in this way, it should be possible to retry the recovery of important files, as the location of the error is known by looking into the unfinished copy of the file.

In fill mode infile does not need to be seekable and it may be of any size. If it is too small, the data will be duplicated as many times as necessary to fill the input buffer. If it is too big, only the data needed to fill the input buffer will be read. Then the same data will be written to every cluster or sector to be filled.

Note that in fill mode infile is always read from position 0. If you specify a --input-position, it refers to the original infile from which mapfile was built, and is only used to calculate the offset between input and output positions.

Note also that when filling the infile of the original rescue run you should not set --output-position, whereas when filling the outfile of the original rescue run you should keep the original offset between --input-position and --output-position.

The option --fill-mode implies --complete-only.

In fill mode mapfile is updated to allow resumability when interrupted or in case of a crash, but as nothing is being rescued mapfile is not destroyed. The status line is the only part of mapfile that is modified.


The fill mode has a number of uses. See the following examples:

Example 1: Mark parts of the rescued copy to allow finding them when examined in an hex editor. For example, the following command line fills all blocks marked as ‘-’ (bad-sector) with copies of the string ‘BAD-SECTOR :

ddrescue --fill-mode=- <(printf "BAD-SECTOR ") outfile mapfile

And the following command line fills all the non-finished areas in the destination file with copies of the string ‘NON-RESCUED-SECTOR :

ddrescue --fill-mode='?*/-' <(printf "NON-RESCUED-SECTOR ") outfile mapfile

Example 2: Wipe only the good sectors, leaving the bad sectors alone. This way, the drive will still test bad (i.e., with unreadable sectors). This is the fastest way of wiping a failing drive, and is especially useful when sending the drive back to the manufacturer for warranty replacement.

ddrescue --fill-mode=+ --force /dev/zero bad_drive mapfile

Example 3: Force the drive to remap the bad sectors, making it usable again. If the drive has only a few bad sectors, and they are not caused by drive age, you can probably just rewrite those sectors, and the drive will reallocate them automatically to new "spare" sectors that it keeps for just this purpose. WARNING! This may not work on your drive.

ddrescue --fill-mode=- -f --synchronous /dev/zero bad_drive mapfile

Fill mode can also help you to figure out, independently of the file system used, what files are partially or entirely in the bad areas of the disc. Just follow these steps:

1) Copy the damaged drive with ddrescue until finished. Don’t use sparse writes. This yields a mapfile containing only finished (‘+’) and bad-sector (‘-’) blocks.

2) Fill the bad-sector blocks of the copied drive or image file with a string not present in any file, for example "DEADBEEF". Use --fill-mode=l- if you want location data.

3) Mount the copied drive (or the image file, via loopback device) read-only.

4) Grep for the fill string in all the files. Those files containing the string reside (at least partially) in damaged disc areas. Note that if all the damaged areas are in unused space, grep will not find the string in any file, which means that no files are damaged.

5) Take note of the location data of any important files that you want to retry.

6) Unmount the copied drive or image file.

7) Retry the sectors belonging to the important files until they are rescued or until it is clear that they can’t be rescued.

8) Optionally fill the bad-sector blocks of the copied drive or image file with zeros to restore the disc image.

Example 4: Figure out what files are in the bad areas of the disc.

ddrescue -b2048 /dev/cdrom cdimage mapfile
printf "DEADBEEF" > tmpfile
ddrescue --fill-mode=l- tmpfile cdimage mapfile
rm tmpfile
mount -t iso9660 -o loop,ro cdimage /mnt/cdimage
find /mnt/cdimage -type f -exec grep -l "DEADBEEF" '{}' ';'
  (note that my_thesis.txt has a bad sector at pos 0x12345000)
umount /mnt/cdimage
ddrescue -b2048 -i0x12345000 -s2048 -dr9 /dev/cdrom cdimage mapfile
ddrescue --fill-mode=- /dev/zero cdimage mapfile
mount -t iso9660 -o loop,ro cdimage /mnt/cdimage
cp -a /mnt/cdimage/my_thesis.txt /safe/place/my_thesis.txt

Next: Generate mode, Previous: Copying parts of the input file on demand   [Index]