I was playing around with zip and accidentally deleted my /home/ folder (I wanted to delete home/ which got created by unzipping an archive).

I used rm -r /home/instead of rm -r home/ as root. Is there anything I can do to restore my /home/ dir?

I am using Debian 6 as a VM on VMware Player. Unfortunately I have no backups.

  • possible duplicate of Recovering deleted files on fedora – Mat Sep 25 '12 at 10:50
  • @Mat That duplicate is for an individual file and won't help much for a directory situation. – Caleb Sep 25 '12 at 11:27
  • @Caleb: yeah, maybe not the best but the answers do list quite a few tools that could do the job. There are quite a few duplicates for this type of question, all in a rats nest of duplicate links. – Mat Sep 25 '12 at 11:29
  • Hopefully you have learned your lesson - watch what you type and make frequent backups! – jw013 Sep 25 '12 at 15:19
  • yep i just threw vmplayer away since it does not have a backupfunction while virtualbox has it. everything has been fixed. – Wandang Sep 26 '12 at 13:57

First off - stop the VM or remount the volume as read only:

 mount -o remount,ro /home/

Presuming you are using ext[3,4], you are not lost, but it's not an easy task. The data blocks themselves are not cleared, but the pointers (inodes) are. Most files can be recovered using tools such as photorec . It will identify a file based on it's magic number. ASCII and obscure file formats are thus harder.

Similar software exists, but I haven't tested them:

If you are successful, this link might help you to get files back into order.

Good luck!

  • 3
    Also, be very careful with installing new software inside the VM. Anything that writes to the (logical) partition that held the now deleted files is extremely risky, even if it only creates temporary files which are subsequently deleted. – a CVn Sep 25 '12 at 11:28
  • thank you very much. i found an old backup (1 month old) on an external hdd which i may be able to use. i will try to backup my actual VM and then recover the work i did in this month. after that i will backup the recovered parts and add them with the old /home/ to get everything mashed together. – Wandang Sep 25 '12 at 12:07
  • ro /home/ wont work because he cannot find home. am i supposed to set it read only after the remount? – Wandang Sep 25 '12 at 12:17
  • It might be a different partition setup. Do a 'mount' to see which partitions are in use. You might have to remount root as read only. 'mount -o remount,ro /' – Tommy Sep 25 '12 at 13:04
  • mount: / is busy maybe i am too dumb. i used it just as you wrote it down with the comma : mount -o remount,ro / – Wandang Sep 25 '12 at 13:12

By and large I'm afraid the unix paradigm is that you're expected not to make mistakes like that, or to have backups in place.

You can try recovering some of the files with foremost but I've never had cause to work with it so I don't know how much help it'll be.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.