Score:14

How do I repair Ubuntu after running the command: sudo rm /*

bv flag

While I was trying to remove files from a SD card from the same directory, I ran sudo rm /* and now Ubuntu isn't working. When I restarted I get the error: kernel panic attempted to kill init.

I'm new to Linux. What should I do now? I don't want to loose my data.

us flag
You may find it relatively simpler to reinstall Ubuntu
cn flag
if no of the answers work boot from a LIVE SESSION and install Ubuntuusing "something else" and only mounting the partitions as you have them now. So ---without---- formatting. It will replace all the system files, keep configs intact and also keep your personal files.You will need to reinstall software you installed yourself though (these will also keep settings you changed)
Jag Mohan Ray avatar
bv flag
But all the root file system is in one partition only.
cn flag
does not matter You can reinstall using the "something else" option and not pick "format". Only mount your partitions, It will keep your personal files and configuration as is and only replace system files.
Neinstein avatar
cn flag
Daily reminder that `sudo` doesn't mean *obey me, I'm your Master*, it means *yeah, I seriously mean it, I checked it twice so there should be no problem*.
U. Windl avatar
gf flag
If you are relatively new to Linux, then don't work as root (use `sudo`) unless needed (A normal user cannot damage the OS). Next thing is whenever you run commands as `root` "think before hitting enter". You told the system to remove the files in the root directory, and the system did it. What you would to to undo that is called "desaster recovery".
preferred_anon avatar
in flag
I don't know why nobody has mentioned explicitly: The exact command you ran will only delete *files* in the root directory, and will not look inside any folders. That means the majority of your data is intact. On my ubuntu system, the only *files* in `/` are the initramfs, the kernel image and the swapfile, none of which are hard to restore.
cn flag
One relatively safe way of handling: Take the drive from your PC, put it aside safely, get another drive and install fresh on it, THEN connect the old drive and salvage any data from the comfort of a fully installed system. Rescue environments can be tricky for a relative beginner.
Score:32
cc flag

That command would have deleted all the links in / (and any files if you happened to have any). Boot an install USB, mount the damaged root (change the sdxy to match your system) at /mnt:

sudo mount -t ext4 /dev/sdxy /mnt

Replace the links with the following:

cd /mnt
sudo ln -s usr/bin bin
sudo ln -s usr/sbin sbin
sudo ln -s usr/lib lib
sudo ln -s usr/lib32 lib32
sudo ln -s usr/lib64 lib64
sudo ln -s usr/libx32 libx32

The only other possible file that might cause problems eventually is a /swapfile if one were present. I don't, but that may be another thing to fix after you can boot normally.

Jag Mohan Ray avatar
bv flag
have i deleted all the data on the pc
Terrance avatar
id flag
@JagMohanRay Running that command without the `-rf` will only delete what is in the `/` directory, but will leave the other directories out of it. All your stuff should still be there. Follow what is written above by booting to a live USB.
Jag Mohan Ray avatar
bv flag
@Terrance i cannot understand the commands above can you guide me a bit. I have created the live usb.
Terrance avatar
id flag
@JagMohanRay There isn't a lot of space here to tell you, and I also don't have time to sit down and teach you. You will have to learn a lot on your own about Linux and Ubuntu, but the information is out there. If you see https://askubuntu.com/questions/813640/how-to-mount-a-partition-from-live-usb there OP listed the drive info from a terminal window and running `fdisk -l` that gave what the drives and partitions are. The first command in this answer here you replace `sdxy` with what is listed from `fdisk -l` like `sda1`.
Jag Mohan Ray avatar
bv flag
@Terrance I followed all the steps but i'm still getting the error -kernel panic- not syncing:Attempted to kill init
Terrance avatar
id flag
@JagMohanRay You need to edit your question then and add as much detail as you can. You might have also removed or broke the actual boot files needed for it to start. But, there is a possibility that you will need to actually reinstall the OS. When you come here to ask questions, please be as detailed as you can so it can help us help you! One thing to remember as well, AskUbuntu is a Q&A site and not a forum like https://ubuntuforums.org/ is.
Score:15
za flag

I suggest you boot a "Live CD" to get a running host.

Then find your data. If you find it, copy it to an external disk or another host. Finally, do a completely fresh install, and set up a backup solution.

If you can't find your data, (and presuming you don't have a backup) make a decision now about how important it was and whether it's worth trying to recover it. Undelete may be possible as long as you don't keep writing to the disk. Something like ddrescue might find some more data too. Or if it is business critical then you might have to pay for professional data recovery.

The other option is to pull the old disk and do a fresh OS install onto a different disk. Put the old one aside for data recovery purposes later, and work on getting a live system up.

Then set up your backups so that in the future you have better options, should something like this happen again.

Good luck!

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.