14

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.

2 Answers2

32

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.

terdon
  • 104,119
ubfan1
  • 19,049
15

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!

Criggie
  • 719