How to switch the kernel version in ubuntu

Environment: ubuntu 16.04 server

After the server is restarted, the kernel may be automatically updated, which will cause some services of the server to be unusable after booting. E.g:

Check the graphics card status: nvidia-smi will report an error

NVIDIA-SMI has failed because it couldn't communicate with the NVIDIA driver. Make sure that the latest NVIDIA driver is installed and running.

The reason for the error: the kernel version is too high and does not match the NVIDIA driver. Because the NVIDIA driver is installed when the kernel version is low.

The solution at this time is to switch back to the lower version of the kernel.

How to switch the kernel version of ubuntu? Two methods are introduced.

1. If the server is nearby, you can choose this method if you can manually start the server

Boot into

The machine enters the grub boot interface, select Advanced options for Ubuntu::

After selecting Advanced options for Ubuntu, enter its sub-menu, as shown below:

The above picture is from: https://blog.csdn.net/sinat_23619409/article/details/85220561

Choose a lower version of the kernel to enter the system.

Just run nvidia-smi again

 

2. Most of the servers are not around, they are operated by remote connection, and it is impossible to manually restart and set the desktop. The second method can be used at this time.

(1) First check the current kernel version:

uname -r

(2) View the order in which the server starts the kernel

grep menuentry /boot/grub/grub.cfg

The red box is the kernel version and boot sequence currently owned by the ubuntu system. Menuentry is each item. Remember this sequence, and you will use it below.

(3) For example, we want to switch to 4.15.0-54-generic, and its startup sequence in the figure above is the seventh.

Terminal run command: sudo gedit /etc/default/grub

GRUB_DEFAULT=0 in the red box is modified to GRUB_DEFAULT="1> 7".

Note: There is a space between> and 7

Save and exit.

(4) Update grub

sudo update-grub

(5) Restart the server

sudo shutdown -r now

(6) Check that the kernel version (uname -r) has been modified to 4.15.0-54-generic after restarting. Run nvidia-smi again and it will be normal.

Here are the possible problems:

During ubuntu's automatic kernel update process, some old kernel versions will also be deleted automatically. Therefore, you may not be able to switch to the version that matches the NVIDIA driver.

The kernel version that can be switched to can only be the kernel version in the kernel startup sequence in step (2). Other versions cannot be cut.

You can also run the command:

dpkg -l | tail -n +6| grep -E 'linux-image-[0-9]+'| grep -Fv $(uname -r)

List all other kernel versions that do not include the current kernel version:

The output content may include the following three states of the kernel image (red box):

  • rc: means it has been removed
  • ii: Indicates that the removal conditions are met (removable)
  • iU: has entered the apt installation queue, but has not been installed yet (cannot be removed)

If you want to remove the "linux-image-4.15.0-88-generic" kernel with status ii, you can use the following command:

sudo dpkg --purge linux-image-4.15.0-88-generic

As mentioned earlier, if the kernel we need is not available, we need to install the required version of the kernel. The installation command is as follows:

sudo apt-get install linux-image-4.15.0-55-generic

Then you can follow the steps (1)-(6) to switch to the kernel version you need to start.

Reference:

https://blog.csdn.net/zs15yy/article/details/77188030

https://blog.csdn.net/sinat_23619409/article/details/85220561

Guess you like

Origin blog.csdn.net/Thanours/article/details/104834536