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. This three stage process is 75an attempt to optimize the case where only a few bad blocks exist 76on 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. The default is what 107.Dv DIOCGMEDIASIZE 108reports for character and block devices or 109.Dv st_size 110if 111.Ar source 112is a regular file. 113.It Fl i Ar pause 114.Xr sleep 3 115this long between reads. This reduces the load on the 116.Ar source 117device and the system in general. 118.It Fl p Ar pause 119.Xr sleep 3 120this long whenever a read fails. This makes the 121.Ar source 122device look less sick to the operating system. 123.It Fl u Ar pattern 124By default blocks which cannot be read are filled with the pattern 125.Ql _UNREAD_ 126in the output file. This option can be used to specify a different 127pattern. If the pattern is the empty string, nothing is written. 128.It Fl v 129Produce a detailed progress report with ANSI escapes and UTF-8. 130.El 131.Pp 132.Nm 133can be aborted with 134.Dv SIGINT , 135but with a sick 136.Ar source 137it may take up to several minutes before the current read operation 138returns from the kernel. 139.Pp 140.Sh EXAMPLES 141.Bd -literal 142# check if all sectors can be read on a USB stick: 143recoverdisk /dev/da0 144 145# recover data from failing hard drive ada3 146recoverdisk /dev/ada3 /data/disk.img 147 148# clone a hard disk 149recoverdisk /dev/ada3 /dev/ada4 150 151# read an ISO image from a CD-ROM 152recoverdisk /dev/cd0 /data/cd.iso 153 154# continue reading from a broken CD and update the existing worklist 155recoverdisk -r worklist -w worklist /dev/cd0 /data/cd.iso 156 157# recover a single file from the unreadable media 158recoverdisk /cdrom/file.avi file.avi 159 160.Ed 161.Sh PRACTICAL ADVICE 162In Datamuseum.dk 163.Nm 164has been used to recover all sorts of data-media for two decades, 165here are some things we have learned: 166.Bl -bullet 167.It 168Interacting with failing hardware has a tendency to crash machines, 169so it is always a good idea to use the 170.Fl -w work-list-file 171so that it is possible to continue. 172.It 173When attempting to recover hard to read data from failing hard disks, 174it pays to pamper the drive as much as possible: 175.It 176It is generally best to keep the drive in it's usual physical orientation, 177but it can also help to try other orientations. 178.It 179Insulate the drive from external vibrations. 180.It 181Keep the drive cool with a fan. 182.It 183If possible, power the drive from a laboratory power supply. 184.It 185Do not loose patience: Let 186.Nm 187run as long as possible. 188.It 189(S)ATA controllers do not handle failing disks well, if this 190is a problem, use a USB-(S)ATA adapter instead. 191.It 192The 193.Nm 194source code is deliberately written to be easily portable to 195older versions of 196.Fx 197and to other operating systems. 198.It 199If you need to read ST-506, RLL or ESDI drives 200.Fx 3.5.1 201is a good compromise. 202.It 203Sometimes forcing the disk to step between reads helps. 204Since 205.Nm 206process the work-list in the order it is read, this 207can be accomplished by sorting the work-list with 208something like: 209.Dl % sort +0.5 210.It 211By default the 212.Xr CAM 213layer will retry failing read operations, but that 214will get stuck on the bad sectors for long time 215and delay recovering what actually can be read from 216a rapidly failing drive. 217In that situation, set the appropriate 218.Dl kern.cam.*.retry_count 219sysctl to zero. 220.It 221For floppies and un-zoned hard disks (ST-506 to 222early IDE) set 223.Fl b Ar bigsize 224to the size of a track. 225.El 226.Sh SEE ALSO 227.Xr dd 1 , 228.Xr ada 4 , 229.Xr cam 4 , 230.Xr cd 4 , 231.Xr da 4 232.Sh HISTORY 233The 234.Nm 235utility first appeared in 236.Fx 7.0 237because Somebody™ forgot to make a backup copy. 238.Sh AUTHORS 239.An -nosplit 240The original implementation was done by 241.An Poul-Henning Kamp Aq Mt phk@FreeBSD.org 242with minor improvements from 243.An Ulrich Sp\(:orlein Aq Mt uqs@FreeBSD.org . 244.Pp 245This manual page was originally written by 246.An Ulrich Sp\(:orlein . 247.Sh BUGS 248If a failing device causes the machine to crash, there is 249a risk that a chunk might have been successfully read 250and removed from the work-list, but not yet flushed to 251the 252.Ar destination . 253.Pp 254.Nm 255calls 256.Xr fdatasync 3 257on the destination before writing the work-list to a 258temporary file, and calls it again on the temporary 259file before renaming it to the specified 260.Fl w Ar work-file-list 261filename. 262But even then things dont always work out. 263.Pp 264.Nm 265should have an option for reconstructing the work-list 266from the 267.Ar destination 268by enumerating the 269.Fl u Ar pattern 270filled ranges. 271