6

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.

5
  • possible duplicate of Recovering deleted files on fedora Commented Sep 25, 2012 at 10:50
  • @Mat That duplicate is for an individual file and won't help much for a directory situation. Commented Sep 25, 2012 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. Commented Sep 25, 2012 at 11:29
  • Hopefully you have learned your lesson - watch what you type and make frequent backups! Commented Sep 25, 2012 at 15:19
  • yep i just threw vmplayer away since it does not have a backupfunction while virtualbox has it. everything has been fixed. Commented Sep 26, 2012 at 13:57

2 Answers 2

7

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!

5
  • 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. Commented Sep 25, 2012 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. Commented Sep 25, 2012 at 12:07
  • ro /home/ wont work because he cannot find home. am i supposed to set it read only after the remount? Commented Sep 25, 2012 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 /' Commented Sep 25, 2012 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 / Commented Sep 25, 2012 at 13:12
0

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.

1
  • You're expected to have backups regardless of the operating system. Commented Jan 29, 2022 at 4:00

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.