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