|
|
We describe an attempt of recovering data unadvertedly deleted on a ext2 filesystem. Aware that the course of events was far from desirable, we are committed that our readers will not make the same mistakes and, in order to illustrate the bunch of things that one can learn during a crisis, we detail the whole story. Prelude: the disaster spellsThe arenaHardwareTwo boxes, called Fish and Bell. Fish is a Sun E250. Bell is a Pentium 3 (450 MHz). They are in the same Ethernet subnetwork. SoftwareBell runs Debian GNU/Linux 3.0r0 after a painless upgrade from 2.2r7. Kernel is Linux 2.4.18.
Fish also runs a Debian 3.0r0, port Sparc64. A recent upgrade from 2.2r7
led to a unique problem: XFree does not work for normal users (it does for
All filesystems are How we buggered it up
On Fish, Xfree works for root@fish# adduser judas Enter new UNIX password: Retype new UNIX password: root@fish# cp --recursive /root/.[a-zA-Z]* /home/judas root@fish# chown --recursive judas:judas /home/judas/.*
[Did you spot the difference between regexp arguments for
After enough trail & error, the X problem is finally solved; it is
about time to remove the user. root@fish# deluser --remove-all-files judas
Cha-ching! Enters disaster! The unfortunate option makes
Contents of Back-upFirst attempt
First cares involve taking a copy of the raw bytes inside the doomed
device. root@fish# ftp bell ftp> put '|dd if=/dev/sda8' fishbackup
In fact, this step was not so easy due to a problem with the net:
transmission of big files is interrupted after a while. The file must
be split. Partition root@fish# factor 10142 10142: 2 11 461 This led us to an appropriate size for each chunk of device. Secure tunnelling
Instead FTP, we used the OpenSSL suite for the next step. root@fish# ssh-keygen artime@bell$ ssh-keygen root@fish# scp /root/.ssh/identity.pub artime@bell:/home/artime/.ssh/authorized.keys root@fish# scp artime@bell:~/.ssh/identity.pub ~/.ssh/authorized.keys Let us execute this script in Fish: #!/bin/sh for i in $(seq 0 460) do dd if=/dev/sda8 bs=$((2*11*1024)) skip=$i of=fula scp --batch fula artime@bell:~/fiback.$i done Just join the pieces in Bell: for i in $(seq 0 460) do cat fiback.$i >> fiback.raw done Equivalently we could do the same in one step by executing in Fish: #!/bin/sh for i in $(seq 0 460) do dd if=/dev/sda8 bs=$((2*11*1024)) skip=$i | ssh artime@bell "cat >> fiback.raw" done Seeking lost dataWe can resort to the Linux Ext2fs undeletion mini-HOWTO, by Aaron Crane; the Ext2fs undeletion of directory structures mini-HOWTO, by Tomas Ericsson; the recover program by Tom Pycke; Torsten Werner's patch for debugfs working on i386. Lazy attempt
artime@bell$ ./debugfs fishback.raw debugfs> restore debugfs> quit artime@bell$ mkdir mnt artime@bell$ mount -t ext2 -o loop fishback.raw mnt artime@bell$ ls -l mnt
We find no files there! It seems we unmounted It pays readingCrane's undeletion howto
This tool we pick in The Linux
Documentation Project taught us how to find the inodes (more or
less, the locations) of lost files and how to recover them with the
Ericsson's directory undeletion howto
Here we learnt how to tell between deleted files from directories. We
followed the indications.
#!/bin/sh
awk '{ print "mi <" $1 ">\n"\
"\n\n\n\n\n\n\n"\
"0\n"\
"1\n"\
"\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" }'
Anyway, we fail to find the directory names and proceed to section 8. So we must look elsewhere. Man pagesA last chance was $ man debugfs
where we found the command
#!/bin/sh
awk '{ print "rdump <" $1 "> folders\n" }'
most directories are recovered into the directory $ strings fishback.raw | grep -B1 -A99 "To: lisistrata" > lisistrata.mbox EpilogueFurther things we would like to outline. RTFMAnd never use a new option asroot for the first time.
Magnetic tapesFish has a magnetic tape unit. GNUmt and tar are
useful tools for a backup schedule. Aaron Crane's howto includes interesting
links regarding this issue.
Regexps
The use of regular expressions in shell commands is very dangerous, especially
when dealing with dot-files. Perhaps the superuser PDAThis article was mostly written with an Agenda VR3, a rather unique free software PDA, in a beach of Gran Canaria.
Published in Issue 86 of Linux Gazette, January 2003 |
C.E.C. Artime is a GNU fan and a free software advocator since 2000.