1.\" Copyright (c) 2006 Ulrich Spoerlein <uspoerlein@gmail.com> 2.\" All rights reserved. 3.\" 4.\" Redistribution and use in source and binary forms, with or without 5.\" modification, are permitted provided that the following conditions 6.\" are met: 7.\" 1. Redistributions of source code must retain the above copyright 8.\" notice, this list of conditions and the following disclaimer. 9.\" 2. Redistributions in binary form must reproduce the above copyright 10.\" notice, this list of conditions and the following disclaimer in the 11.\" documentation and/or other materials provided with the distribution. 12.\" 13.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 14.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 16.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 17.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 18.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 19.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 20.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 21.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 22.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 23.\" SUCH DAMAGE. 24.\" 25.Dd April 3, 2020 26.Dt RECOVERDISK 1 27.Os 28.Sh NAME 29.Nm recoverdisk 30.Nd recover data from disk-like devices. 31.Sh SYNOPSIS 32.Nm 33.Op Fl b Ar bigsize 34.Op Fl i Ar interval 35.Op Fl r Ar readlist 36.Op Fl s Ar interval 37.Op Fl u Ar pattern 38.Op Fl v 39.Op Fl w Ar writelist 40.Ar source 41.Op Ar destination 42.Sh DESCRIPTION 43The 44.Nm 45utility reads all data from the 46.Ar source 47and retries read operations until they succeed. 48If 49.Ar destination 50is specified all data read be written there. 51.Pp 52The internal work-list can be saved and loaded so that 53.Nm 54sessions can be resumed, for instance when a marginal 55source hard-disk shuts down. 56.Pp 57The work-list is initialized with a single item which covers the entire 58.Ar source 59and 60.Nm 61always chips away at the first item on the work-list. 62 63When a read succeeds, that part of the current chunk is eliminated 64from the work-list. 65 66When a read fails, that part of the item is appended to the worklist 67as a separate item, and will be retried in due order. 68If 69.Ar destination 70is specified, the corresponding range is filled with '_UNREAD_'. 71.Pp 72The first pass attempts to read everything in "big-size" chunks, 73the second pass reads in "medium-size" chunks and third and subsequent 74passes read in "small-size" chunks. 75This three stage process is an attempt to optimize the case where only 76a few bad blocks exist on 77.Ar source . 78If too many read-errors are encountered, 79.Nm 80will fall back to smaller sizes sooner. 81.Pp 82The three sizes default to 128kB (or less if the sector size does 83not divide 128kB cleanly, for instance audio CD media), and the 84reported 85.Dv DIOCGSTRIPESIZE 86and 87.Dv DIOCGSECTORSIZE 88respectively. 89.Pp 90The options are as follows: 91.Bl -tag -width indent 92.It Fl b Ar bigsize 93The size of reads attempted in first pass. 94.It Fl m Ar mediumsize 95The size of reads attempted in second pass. 96.It Fl s Ar smallsize 97The size of reads attempted in third and subsequent passes. 98.It Fl r Ar work-list-file 99Read the work-list from a file. 100.It Fl w Ar work-list-file 101Write the work-list to a file when a read succeed, but at most once 102every minute. 103.It Fl l Ar log-file 104Each successful read is logged with timestamp, offset and length. 105.It Fl t Ar totalsize 106How many bytes should be recovered. 107The default is what 108.Dv DIOCGMEDIASIZE 109reports for character and block devices or 110.Dv st_size 111if 112.Ar source 113is a regular file. 114.It Fl i Ar pause 115.Xr sleep 3 116this long between reads. This reduces the load on the 117.Ar source 118device and the system in general. 119.It Fl p Ar pause 120.Xr sleep 3 121this long whenever a read fails. 122This makes the 123.Ar source 124device look less sick to the operating system. 125.It Fl u Ar pattern 126By default blocks which cannot be read are filled with the pattern 127.Ql _UNREAD_ 128in the output file. 129This option can be used to specify a different pattern. 130If the pattern is the empty string, nothing is written. 131.It Fl v 132Produce a detailed progress report with ANSI escapes and UTF-8. 133.El 134.Pp 135.Nm 136can be aborted with 137.Dv SIGINT , 138but with a sick 139.Ar source 140it may take up to several minutes before the current read operation 141returns from the kernel. 142.Pp 143.Sh EXAMPLES 144.Bd -literal 145# check if all sectors can be read on a USB stick: 146recoverdisk /dev/da0 147 148# recover data from failing hard drive ada3 149recoverdisk /dev/ada3 /data/disk.img 150 151# clone a hard disk 152recoverdisk /dev/ada3 /dev/ada4 153 154# read an ISO image from a CD-ROM 155recoverdisk /dev/cd0 /data/cd.iso 156 157# continue reading from a broken CD and update the existing worklist 158recoverdisk -r worklist -w worklist /dev/cd0 /data/cd.iso 159 160# recover a single file from the unreadable media 161recoverdisk /cdrom/file.avi file.avi 162 163.Ed 164.Sh PRACTICAL ADVICE 165In Datamuseum.dk 166.Nm 167has been used to recover all sorts of data-media for two decades, 168here are some things we have learned: 169.Bl -bullet 170.It 171Interacting with failing hardware has a tendency to crash machines, 172so it is always a good idea to use the 173.Fl -w work-list-file 174so that it is possible to continue. 175.It 176When attempting to recover hard to read data from failing hard disks, 177it pays to pamper the drive as much as possible: 178.It 179It is generally best to keep the drive in it's usual physical orientation, 180but it can also help to try other orientations. 181.It 182Insulate the drive from external vibrations. 183.It 184Keep the drive cool with a fan. 185.It 186If possible, power the drive from a laboratory power supply. 187.It 188Do not lose patience: Let 189.Nm 190run as long as possible. 191.It 192(S)ATA controllers do not handle failing disks well, if this 193is a problem, use a USB-(S)ATA adapter instead. 194.It 195The 196.Nm 197source code is deliberately written to be easily portable to 198older versions of 199.Fx 200and to other operating systems. 201.It 202If you need to read ST-506, RLL or ESDI drives 203.Fx 3.5.1 204is a good compromise. 205.It 206Sometimes forcing the disk to step between reads helps. 207Since 208.Nm 209process the work-list in the order it is read, this 210can be accomplished by sorting the work-list with 211something like: 212.Dl % sort +0.5 213.It 214By default the 215.Xr CAM 216layer will retry failing read operations, but that 217will get stuck on the bad sectors for long time 218and delay recovering what actually can be read from 219a rapidly failing drive. 220In that situation, set the appropriate 221.Dl kern.cam.*.retry_count 222sysctl to zero. 223.It 224For floppies and un-zoned hard disks (ST-506 to 225early IDE) set 226.Fl b Ar bigsize 227to the size of a track. 228.El 229.Sh SEE ALSO 230.Xr dd 1 , 231.Xr ada 4 , 232.Xr cam 4 , 233.Xr cd 4 , 234.Xr da 4 235.Sh HISTORY 236The 237.Nm 238utility first appeared in 239.Fx 7.0 240because Somebody™ forgot to make a backup copy. 241.Sh AUTHORS 242.An -nosplit 243The original implementation was done by 244.An Poul-Henning Kamp Aq Mt phk@FreeBSD.org 245with minor improvements from 246.An Ulrich Sp\(:orlein Aq Mt uqs@FreeBSD.org . 247.Pp 248This manual page was originally written by 249.An Ulrich Sp\(:orlein . 250.Sh BUGS 251If a failing device causes the machine to crash, there is 252a risk that a chunk might have been successfully read 253and removed from the work-list, but not yet flushed to 254the 255.Ar destination . 256.Pp 257.Nm 258calls 259.Xr fdatasync 3 260on the destination before writing the work-list to a 261temporary file, and calls it again on the temporary 262file before renaming it to the specified 263.Fl w Ar work-file-list 264filename. 265But even then things dont always work out. 266.Pp 267.Nm 268should have an option for reconstructing the work-list 269from the 270.Ar destination 271by enumerating the 272.Fl u Ar pattern 273filled ranges. 274