Undeleteting a file in Ubuntu
Future me, please note that I'm not claiming that the following solution is recommended, but it worked for me this time:
- Pulled the power plug of the computer to prevent further writes to disk. There are more elegant solution, but this machine had lots of demons with disk IO running.
- Tried booting into live system, this failed for unknown reasons
- Took hard-drive out of the computer and moved it to exernal USB drive case
- Plugged USB into another Ubuntu machine. It was (unfortunately) automatically mounted, and I remounted it as read-only
sudo mount --options=remount,ro /dev/sdb1
- Installed extundelete
sudo apt-get install extundelete
- Tried to restore the lost file, then the folder it was in, but unfortunately the following commands failed with an "extundelete could not find correct inode" error.
sudo extundelete --restore-file /home/username/datafolder/importantfile.txt /dev/sdb3
sudo extundelete --restore-directory /home/username/datafolder/ /deb/sdb1
- Note that you have specify the partition file, not the device file
(
/sdb1
instead of/sdb
). - I may have gotten the original path of my lost importantfile.txt wrong, which might explain the inode error.
- What finally worked was:
sudo extundelete --restore-all /dev/sdb1
This restored my file and surprisingly few other files. I guess when you delete something in Ubuntu, you better act fast.