BTW simple text recovery from fdisk'd USB

Reece Arnott <[email protected]>
Newsgroups gmane.org.user-groups.linux.dunedin.general
Message-ID <[email protected]>
As I was doing 'interesting' stuff with fdisk and master boot records 
trying to replicate what UNetbootin was doing for the bootable USB 
replication procedure in the last email,  I screwed up which USB disk 
was the source and which was the destination (and didn't notice for half 
an hour and about 10 fdisk committed changes).

Of course I had backups of most of the important files but not the 
documentation files I was writing up procedures in for others (and which 
I liberally copied from in the previous email) and of course the one 
script that I originally set out to create (the a script that copies MAC 
address info to a file.

As they were relatively small text files and I had a fair idea of what 
was in them I did the following:
1. Create a 8GB dd.img file (it was an 8GB USB):  sudo dd if=/dev/sdb 
of=dd.img (Could probably get away with not doing this but thought it 
was worth the extra 5-10 minutes)
2. Created a 160MB allstrings.txt file from the image: strings -ao 
dd.img >allstrings.txt (by default has all printable strings of 4 
characters and over which means it left out end-if statements in code on 
their own line i.e. 'fi' but thats the only thing I noticed was missing).
3. For each of the files I tried to come up with a string that was near 
the start of the file and nearly unique and then used grep on 
allstrings.txt to pull out the appropriate parts: grep -B 50 -A 150 
"string" > reasonablename.txt (finds the string and outputs the last 50 
and next 150 lines as well which ended up creating 3 or 4 1-10MB txt 
files - containing the correct text as probably around 5-10% of the 
bulk. I just pulled those numbers out of the air as definitely going to 
get the entire file)

I then just went and recreated the files from the appropriate portions. 
The strings command leaves a line number which I could have got rid by 
going into LibreOffice Calc and importing it as a space delimited file, 
deleted the first column and resaved. I was only looking for 3 or 4 
files with only a few score of lines in total so it wasn't worth it, I 
just manually went in and deleted extraneous lines and for the 
appropriate columns I deleted the line number as I categorised them.

-- 
"Believing men would act in their own interest was not cynicism, it turned out, but sheerest optimism; in reality men do not meet so high a standard."
-- Harry Potter and the Methods of Rationality (Chapter 84)
http://hpmor.com/

Reece Arnott
Dunedin
New Zealand


_______________________________________________
DunLUG mailing list
[email protected]
http://lists.ethernal.org/listinfo/dunlug
DunLUG Wiki - http://dunlug.kallisti.net.nz/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.