From owner-freebsd-questions Thu Mar 8 5:40:25 2001 Delivered-To: freebsd-questions@freebsd.org Received: from wop21.wop.wtb.tue.nl (wop21.wop.wtb.tue.nl [131.155.56.216]) by hub.freebsd.org (Postfix) with ESMTP id 9004237B719; Thu, 8 Mar 2001 05:40:18 -0800 (PST) (envelope-from karelj@wop21.wop.wtb.tue.nl) Received: (from karelj@localhost) by wop21.wop.wtb.tue.nl (8.11.1/8.11.1) id f28Dcju48569; Thu, 8 Mar 2001 14:38:46 +0100 (CET) (envelope-from karelj) Date: Thu, 8 Mar 2001 14:38:39 +0100 From: "Karel J. Bosschaart" To: Kal Torak Cc: FreeBSD-stable , FreeBSD-questions Subject: Re: Oh no... Message-ID: <20010308143839.A48446@wop21.wop.wtb.tue.nl> References: <3AA5EAE0.C9CEF366@quake.com.au> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 1.0.1i In-Reply-To: <3AA5EAE0.C9CEF366@quake.com.au>; from kaltorak@quake.com.au on Wed, Mar 07, 2001 at 07:01:36PM +1100 Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG On Wed, Mar 07, 2001 at 07:01:36PM +1100, Kal Torak wrote: > Hiyas... > > I kinda did a fdisk -BI on my main HDD by accident... It killed > all my partitions... I tried to get them back with sysinstall and > the live file system, but I cant mount them and stuff... > > Is there some way I can get my data back? I dont care so much about > the file systems.. But there are some files I would *LOVE* to get > back... > > Any pointers would be great... > Oops, that's a nasty situation... it remembers me to a similar thing a while back. A colleague screwed his combined Windows/FreeBSD setup, didn't have a backup and asked my assistance as he wanted to have some stuff back. Partition tables and disklabels were gone, and as others already pointed out, recovering the filesystems means recovering/reconstructing these tables. What I did first: rip out the disk, put it in another machine and copied byte by byte with dd to one big 9 GB file, so I had at least this 'backup' before doing more damage. As I knew approximately the sizes and locations of the partitions, I looked into the file, by extracting parts of it, again using dd, hoping to find indications for the start of a partition. I used 'strings' on the files, because strings are more easily to recognize for humans. I guess that if you have more knowledge about the ufs filesystem you can use more sophisticated things to find the beginning, searching for binary patterns. Anyway, with my limited knowledge and some luck I was able to find the beginning of /usr, the most important partition to be retrieved: After doing a dd on the /usr partitions of various FreeBSD machines I found a certain string pattern always on exactly the same spot (the pattern was "/usr" I think). So I looked for the pattern in the disk dump, and then reconstructed the disklabel in such a way that a dd on that partition would result in that pattern on that location. After a few tries I was very happy to notice no error message after the mount command.... everything seemed to be there, so I immediately backed it up in usr.tgz on another drive. As I did not succeed in getting / and /var back (they were possibly corrupted by a Windows installation) I did a newfs on them, and copied the root and /var from another FreeBSD machine to them. Using 'dd' and 'strings' on the original 9 GB dump (or on parts of it), I could retrieve some essential information from the filesystems that I could not recover; the password file and /etc/rc.conf were such things. I inserted them in the newly copied root and rebooted with fingers crossed... it worked. And as there appeared to be a complete object tree on the system (lucky, lucky), I did a 'make installworld', built/installed a new kernel and finally 'mergemaster' to ensure everything to be nicely synced again. So after all, the FreeBSD installation was almost completely recovered; the package database (/var/db/pkg) was missing, but I think that's an acceptable loss in this case. Well, that was roughly what I have done to recover a disk... it took me a day, but the successfull result gave me a good feeling :-). I know there was some luck involved... The Windows partition was lost forever.... I wish you very good luck when you decide to try retrieving your data, Karel. To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message