2

In my system I have the following kernel versions installed:

Found linux image: /boot/vmlinuz-5.4.0-107-generic
Found initrd image: /boot/initrd.img-5.4.0-107-generic

Found linux image: /boot/vmlinuz-5.4.0-105-generic Found initrd image: /boot/initrd.img-5.4.0-105-generic

Found linux image: /boot/vmlinuz-5.4.0-104-generic Found initrd image: /boot/initrd.img-5.4.0-104-generic

I always use the latest version, but for the last few days I have had to use the 5.4.0-104-generic version, because if I let my system use 5.4.0-105-generic or 5.4.0-107-generic my system freezes after login and I need to shut down with the power off button.

I never saw this behavior before. What can I do? Is it possible to keep the 5.4.0-104-generic version (only that works) forever? I am afraid that version could disappear from my system, I don't know.

Zanna
  • 70,465

4 Answers4

4

Another useful technique is to have grub default to the last kernel booted. Edit the /etc/default/grub file to contain the lines:

GRUB_DEFAULT=saved
GRUB_SAVEDEFAULT=true

then run

sudo update-grub

This change will make the kernel you last booted the default, so until you boot another, that's what will be run. Still, instead of relying on the package manager to be smart enough not to purge the running kernel, you might want to backup/make copies of the 104 packages -- probably just paranoid, but unless you turn off/avoid kernel/header updates, the autoremove may mess up.

ubfan1
  • 17,838
  • I like (and totally forgot) about SAVEDEFAULT... it's WAY easier than providing detail on how to get the menu entry names/numbers... This is going to be the easier option all-around, unless you already understand the grub menu structure or want to make in-session changes... – WU-TANG Apr 02 '22 at 22:05
3

First thing is you should be trying to discern what the problem is with the new kernels.

To persistently boot into the kernel of your choice:

Numerous ways to go about this. Some are mentioned in other answers, essentially setting grub to boot into the desired kernel by default.

If I am in the same situation, and I am going to want to switch effortlessly while testing. In /etc/default/grub, you can edit:

GRUB_DEFAULT=saved

and then update-grub

Then from that point, anytime you want to test or set a default kernel you can just use sudo grub-set-default <your menuentry selection> and reboot.

<your menuentry selection> is going to be your grub menuentry or entry list number...

If your Grub menu looks like:

Ubuntu
Advanced options for Ubuntu
System Setup

Then Ubuntu=0, Advanced options for Ubuntu=1, System Setup=3
Because you are dealing with a submenu of 1, you have to note that too.

Under 'Advanced options for Ubuntu' you MIGHT have something like:

Ubuntu, with Linux 5.4.0-107-generic
Ubuntu, with Linux 5.4.0-107-generic (recovery mode)
Ubuntu, with Linux 5.4.0-105-generic
Ubuntu, with Linux 5.4.0-105-generic (recovery mode)
Ubuntu, with Linux 5.4.0-104-generic
Ubuntu, with Linux 5.4.0-104-generic (recovery mode)

in the 0-based enumeration, the 104 kernel would be number 4

You can then set your new default like: sudo grub-set-default "1>4" and reboot

or

sudo grub-set-default "Advanced options for Ubuntu>Ubuntu, with Linux 5.4.0-104-generic and reboot.

There are easily searched way to pull the menuentry's from /boot/grub/grub.cfg so you can get the correct names and numbers without opening the file and looking... Most are grep-ing or awk-ing the file and returning menuentry results as it finds them in the file and assigns them sequential numbers.

A quick and dirty way to get a (out of order) listing, is to just type grub-set-default and then the TAB key a couple of times until the auto-complete kicks the output. (This command does not give the correct numbers)

This stays permanent until you changed the saved default.

You can view the saved_entry with:
cat /boot/grub/grubenv

To prevent any further updates in the meantime:

You would, just NOT install the updates... simply uncheck the boxes with anything related to those updates.."5.4.0-1XX" ... linux image and header files... (unrelated system pictured here) enter image description here

On my system, I ran sudo apt update and then sudo apt list --upgradable.
Then I searched through the "upgradable list" for anything that resembled the next kernel upgrade... 4.15.0.175 in my case... I found linux-generic, linux-headers-generic, and linux-image-generic.

I could simply uncheck those in the GUI, but I know I don't pay attention to what's going on there. So instead I'll permanently set those packages to "hold".
sudo apt-mark hold linux-generic linux-headers-generic linux-image-generic

apt-mark showhold verifies...

Don't screw this up at this point... DO NOT go up to that box and hit "Install Now" without unchecking those boxes. The hold stops the install of those packages on the command line if you use apt upgrade (and to be honest I rebooted before I attempted the upgrade, so I'm not even 100% confident in that assessment), but I don't know if there is something in the background that is going to prevent from that box, that was already open, from doing what it knows to do, which is install all the "checked" packages. So CLOSE THE Software Updater and reopen it if you want to see your changes work. The apt-mark hold basically unchecks those boxes for you(and doesn't let you check them anymore) until you unhold them. [I had failed results the first time i tried this, but that could have been because I tried to hold a SPECIFIC kernel... don't do that, just hold the package without version]

When I upgraded with either method, the next kernel did not get installed.

Now if those are the only packages that need upgrading, Software Updater says my system is current. If I do sudo apt list --upgradable I see the latest versions of those 3 packages.

...and in addressing the OP's "concern"... you can always reinstall a kernel from the repository. Your system may be able to stay accessible in a console to do so.

WU-TANG
  • 3,071
  • 1
    But OP has already installed these non-working kernels. While holding the packages will prevent next kernel versions from installation, the question was how to make the version 104 boot as default instead of the last one installed (107). Just holding the packages will not provide that. – raj Apr 02 '22 at 18:39
  • @raj you are correct... i got fixated on the last paragraph and forgot about the rest of the question... EDITED..... but I am liking ubfan1's option more, if the OP plan's to just sit on 104 without any future tinkering – WU-TANG Apr 02 '22 at 22:08
1

You can use Ubuntu mainline kernel installer to (un)install kernels. It is grafical (GUI), so you don't have to use the terminal. You can uninstall 107 and 105 and install a kernel older than 104. (It is wise to have at least 2 kernels installed, just to have one to fall back on when needed).

See screenshotenter image description here

Then use the 'mark hold' in apt & apt-get as suggested before by WU-TANG

To get mainline:

sudo add-apt-repository ppa:cappelikan/ppa
sudo apt update
sudo apt install mainline
Joepie Es
  • 1,460
0

For starters you could use the answer provided here: https://askubuntu.com/a/110738/1282766 to set GRUB to boot into 104 kernel so that you can make sure this issue does not happen in that version.

Then, a similar process is mentioned here: https://unix.stackexchange.com/a/465220 That should let you restore the kernel version permanently.

If you want to stop the kernel from auto updating just remove these two packages:

apt-get remove linux-image linux-image-generic
givonz
  • 611