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.

8
  • 26
    You may find it relatively simpler to reinstall Ubuntu Jan 22, 2023 at 18:50
  • 5
    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)
    – Rinzwind
    Jan 22, 2023 at 18:58
  • 5
    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.
    – Rinzwind
    Jan 23, 2023 at 1:58
  • 13
    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.
    – Neinstein
    Jan 23, 2023 at 7:22
  • 9
    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. Jan 25, 2023 at 10:30

2 Answers 2

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.

6
  • have i deleted all the data on the pc Jan 22, 2023 at 18:12
  • 11
    @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.
    – Terrance
    Jan 22, 2023 at 18:21
  • @Terrance i cannot understand the commands above can you guide me a bit. I have created the live usb. Jan 22, 2023 at 18:23
  • 1
    @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 askubuntu.com/questions/813640/… 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.
    – Terrance
    Jan 22, 2023 at 18:30
  • 7
    @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 ubuntuforums.org is.
    – Terrance
    Jan 22, 2023 at 18:50
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!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .