How to recover from 'sudo rm -rf' command?
By mistake, I ended up executing rm -rf /
command from sudo
on my laptop which erased many files before it stopped. Now when I restarted my system , it drops to this prompt:
GRUB rescue>_
I am having dual-boot with Ubuntu 12.04 and Windows 7.
I request help for the following questions:
How do I fix the currently installed Ubuntu without overwriting/erasing the left over files (from
rm -rf
command)?Is using boot-repair safe?
Is there a way to directly go to Windows 7?
Solution 1:
If you need to recover your documents you can try using photorec or testdisk.
However, if you want to recover the operating system and make it functional again, a clean reinstall is by far the easiest and fastest option.
Solution 2:
How do I fix the currently installed Ubuntu without overwriting/erasing the left over files (from rm -rf command)?
If you ran rm -rf
from the root directory and let it run to completion, you will have a blank partition. Any chance to recover files (see Best tool to recover removed files) would have to be done while running from a LiveCD.
I am assuming you are talking about a ext4 partition. The biggest issue you will have is finding the exact files to restore, as the names of the files will be lost (unlike the FAT32 file recovery). Some of the recovery tools can search for patterns that certain files types have. For example, all jpg files have parts of the file that share a common binary pattern. You can tell a recovery tool to recover files with that pattern. You maybe successful at recovering some files that way, but as for restoring you entire system, your best bet is to reinstall, as you will not be able to provide file names for all of the files that were deleted.
Is using boot-repair safe?
I am not familiar with boot-repair, so I can not give you definitive answer here. Since you have deleted your entire Ubuntu install, I would go with the reinstall.
Is there a way to directly go to Windows 7?
Best way to do this quickly is reinstall Ubuntu, it will fix grub so you can boot windows.
Solution 3:
When recursively deleting files starting from the root directory /
as sudo there is no way other to recover the state of your OS as it was before than restoring from a backup.
In case you don't have a recent backup at hand you will have to reinstall Ubuntu.
Personal data files from your $HOME directory can be recovered (e.g. with PhotoRec) but take note of the following:
- Recover these files first. Do not use the drive before you had sucessfully recovered your data to an external storage device.
- You will have to restore permissions, directories, and filenames manually.
See also:
- Ubuntu Wiki on Data Recovery
Solution 4:
To recover deleted files I recommended using foremost .