preface

When I used df -h command to check the disk usage, I found that the space of the root directory of the system was too small, so I used the clean command to clean the kernel of the system, and accidentally deleted all the kernel. You may have the same experience as me, very crashed. So, without further ado, let’s see how to fix it.

Repair methods

  • Make an Ubuntu (your current system distribution) boot disk using a USB drive see: https://www.linuxidc.com/Linux/2016-04/130520.htm production means is the use of tools, the use of usb flash drive in a system, often with system must know how to do it, you can use the software in the article, you can also use the soft dish (I typically use this). Note that you only need to make this boot disk, no installation is required.
  • Once done, start the system using a USB flash drive, select Try Ubuntu, and try Ubuntu
  • Press CTRL + Alt + T at the same time to start the terminal, and all our operations are done in the terminal.
  • Use the following command:
sudo fdisk -l
Copy the code

Check the location of your original Linux root directory. If you really don’t know which one is where your root directory is, you can mount them one by one, which I’ll cover in a minute. If you do, record the location of the root directory, such as /dev/sda7

  • If you don’t know the location of your root directory, you can do this, and if you do, you can try it out
mount /dev/sda7 /mnt
Copy the code

Mount /dev/sda7 to/MNT

ls /mnt
Copy the code

If you are familiar with the appearance of the root directory, then mounted by the way, if not, then please follow the above steps to mount There needs to be clear, if you the/boot directory or other directory, such as/var (very important), the original is installed in other partitions, rather than in the root directory partition, Then you also need to record the partition where these directories are located, and use them as well. Test using the same mount method. Ok, once you know the location of all the file partitions on your original system, then we can move on.

  • Mounting instructions using commands: /var /dev/sda9 /dev/sda7 /boot /dev/sda3 /var /dev/sda9 /dev/sda7 That is, prefix each command with sudo
mount /dev/sda7 /mnt
mount /dev/sda3 /mnt/boot
mount /dev/sda7 /mnt/var
mount --bind /dev /mnt/dev
mount --bind /sys /mnt/sys
mount --bind /proc /mnt/proc
Copy the code

All the above commands are mount or link commands, simply speaking, the function of the above commands is to use the content of the previous path.

  • Copy DNS resolution (network profile)
cp /etc/resolv.conf /mnt/etc/resolv.conf
Copy the code

This is very important, otherwise you won’t be able to connect to the Internet

  • Enter the mounted system
chroot /mnt
Copy the code
  • Update the system kernel this step is the most core content, fix depends on this
apt-get install linux-image-generic
Copy the code
  • After the installation is complete, update the GRUB file
update-grub
Copy the code

To be safe, we need to unmount the partition we just mounted

exit
umount /boot
umount /dev
umount /sys
umount /var
umount /proc
umount /mnt
Copy the code
  • Finally, unplug the boot disk, reboot the system, and you’ll see your lovely kernel back

lesson

In the future, if you do not understand the function of the command, do not use sudo command disorderly, very dangerous, data loss is common.

conclusion

Thank you for reading, welcome to correct the problems in the blog, you can also contact me, progress together, exchange together!

Wechat official account: Enter the program dog email: [email protected]

Personal blog: http://roobtyan.cn

If you like my post, support me with your followers! Wechat Official Account: