Safely try new kernels in Ubuntu Linux

 Posted by:   Posted on:   Updated on:  2023-01-07T21:24:37Z

Before testing the newest Linux kernel you should write a script than will revert to original configuration. This is because the new kernel may break your installation and graphical interface may be unavailable.

Some while ago, bothered by the ACPI PCC Probe Failed message at every boot, I decided to try the latest Linux kernel, which was at version 4.2. But I ran into troubles. So this tutorial is not focused on installing new kernels, but on the steps you should take to maximize the chances your new kernel will work and how do you prepare to restore your system to the old kernel, before actually installing the new one.

Here is what I recommend doing before trying a new kernel:

  1. Remove kernel modules that load at boot time. These may not be available in the newer kernel and may prevent it from loading. The modules names are in /etc/modules file. By default, in newer Ubuntu versions there is no module there, so you added it if you find anything. Run in a Terminal gksu gedit /etc/modules and comment using # all modules.
  2. Switch to opensource or remove any proprietary device drivers. Proprietary drivers may fail to build modules with dkms on the newer kernel.
  3. See what kernel you are currently using and save this information for later. Run uname -r in a Terminal. The output will look something like: 3.19.0-26-generic.
  4. Decide what kernel version you are going to use and download the deb packages from You will download:
    1. Architecture specific headers: linux-headers-...-i386.deb for a 32 bit system.
    2. Architecture independent headers: linux-headers-...-all.deb.
    3. Architecture specific image: linux-image-...-i386.deb for a 32 bit system.
  5. Create a script that will restore your system. This script must:
    1. Remove the new kernel.
    2. Reinstall the old one.
You will write in that script:

apt-get remove linux-image-4.2.0-* linux-headers-4.2.0*  
apt-get install --reinstall linux-headers-3.19.0-26-generic linux-headers-3.19.0-26 linux-image-3.19.0-26-generic linux-image-extra-3.19.0-26-generic  
Save it as in your user folder. Be sure to replace versions accordingly and the 3.19.0-26-generic string in my command with the output of uname -r. Make it executable by running chmod +x and you're done.

Now go ahead and install the new kernel. Launch a Terminal, go to the folder where you downloaded the deb files and provided there are no extra deb files there, run:
sudo dpkg -i *.deb
sudo update-grub
Go ahead and restart. If you see your desktop just the way it was before the new kernel, you were lucky. You can try to get back the proprietary drivers and modules.

If you can't login or you are thrown to a command line there are two approaches, but before that, do not make any further changes that involve drivers and dkms. If you got errors during kernel install related to building driver modules avoid reinstalling drivers if your system is not working. Running dkms will delete previous built modules thus breaking the old kernel configuration too and making the following approach useless.

I mentioned two approaches. The first one is to reboot your computer and from the GRUB boot menu (hold Shift pressed at start-up until it shows) choose Advanced options of Ubuntu and select the operating system with the previous kernel (not the recovery image or anything else). It should boot and start as usual. All you have to do now is remove the kernel you installed manually. For example:
sudo apt-get remove linux-image-4.2.0-* linux-headers-4.2.0*
It may be necessarily to run update-grub too. Reboot and you're done.

Remember you made a restore script. If the above approach didn't get your system back, go to the command line. If you are not already there press Ctrl+Alt+F1 after your system booted (no matter if you logged in or not). Log in if required (type username, followed by Enter, then password followed by Enter). Now it is time to run the restore script, which should be located in your user folder, so:
sudo ./
Restart. Now your system should get to the previous kernel. If it still doesn't you may also uninstall drivers. For example if you have Nvidia card you can run sudo apt-get remove nvidia*.

If you still haven't fixed your OS, in order to get help on forums like Ubuntu Forums or Ask Ubuntu you must know what causes the problem. When booting press any key to see the boot log. Also, when you arrive at the command line, there should already be an error output there. Yet, there are cases when it doesn't help very much. Like my case. I was getting an error that claimed systemd Failed to start Load Kernel Modules. And it instructed me to run the command systemctl status systemd-modules-load.service -l. Still it wouldn't tell me what causes the problem.

Failed to start Load Kernel Modules
Systemd error
After some googling I found a thread Evo/Lution Linux Forums which helped me find the answer. I looked on my display and saw systemd-modules-load process was started with PID 310.
sudo journalctl -b _PID=310
The output let me know that the kernel couldn't load the bttv module that was present in /etc/modules because I didn't follow step 1.

Do you want to try new kernels on your Linux OS? Then be prepared to get to the command line. It's best that you have a working internet connected device available so in case of errors you can look for answers.

No comments :