14

Since I upgraded to Ubuntu 21.04 hirsute, I get this very annoying message whenever I perform some upgrades.

Pending kernel upgrade

How to disable it? It's breaking my upgrade scripts.


System information :

OS: Ubuntu 21.04 x86_64
Host: HP G62 Notebook PC 0598120000202710010020100
Kernel: 5.11.0-24-generic
Uptime: 17 mins
Packages: 1289 (dpkg), 11 (snap)
Shell: bash 5.1.4
Resolution: 1366x768
Terminal: /dev/pts/0
CPU: Intel i3 M 370 (4) @ 2.399GHz
GPU: Intel Core Processor
Memory: 424MiB / 3726MiB

Upgrade script :

sudo apt update
sudo apt full-upgrade -y --auto-remove
sudo reboot now
Nato Boram
  • 1,099
  • 10
  • 19
  • 2
    What upgrades and how are you performing them? Please edit your question with the output of `sudo apt update`. What happens when you reboot? – Nmath Jul 04 '21 at 01:58
  • I'm performing the upgrades available via `sudo apt full-upgrade -y --auto-remove` and performing them via `sudo apt full-upgrade -y --auto-remove`. When I reboot, the computer reboots. The results of `sudo apt update` depends on the upgrades available at the time. Example : *1 package can be upgraded. Run `apt list --upgradable` to see it.* – Nato Boram Jul 04 '21 at 02:02
  • 2
    when you run apt commands with the `-y` flag you might be missing important information that could help explain the error. Can you add the entire output of `sudo apt update` and `sudo apt upgrade` into the body of your question. If you put three backticks (`) before and after each block, it will retain monospace formatting and line breaks. – Nmath Jul 04 '21 at 02:05
  • I think it would be better if you directly tell me what you're getting at. This is the normal upgrade process of Ubuntu Server and I would've included anything out of the ordinary to help you help me. Regardless, here's the logs of these commands : https://pastebin.com/BYsKWdr7 I would've put it in the question but `
    ` doesn't seem to be supported here.
    – Nato Boram Jul 04 '21 at 02:19
  • *"what you're getting at"* - problem solving which requires information gathering. The error suggests that there is a problem somewhere with the package management and `apt` will usually throw errors or messages giving you more information. I'm asking questions that might shed light on the problem, which could reveal a solution. Have you already rebooted the system? Also, do you generally, or have you ever manually installed kernel versions outside of the typical updates from the package manager or `apt`? – Nmath Jul 04 '21 at 02:25
  • Also, why do you use a *script* for updates, and is there any reason you are using `sudo apt full-upgrade -y --auto-remove` instead of `sudo apt upgrade`? – Nmath Jul 04 '21 at 02:25
  • Your output shows that you have the `-proposed` pocket of the Ubuntu Repositories enabled. That's generally a bad idea, and is one possible cause of your problem. Disable `-proposed`, run apt updates again, and see if the problem goes away over the next week or two. – user535733 Jul 04 '21 at 02:35
  • Aight. I don't see any errors right now. The way I see it, it really looks like an intended notification suggesting that I reboot after the upgrade. I've dismissed this notification during many different upgrades before and I've already rebooted. This notification will likely appear during the next upgrade when a new kernel version will be available. I've never installed another kernel outside of what's available via upgrades. I also have this message on my Raspberry Pi running Ubuntu Server. – Nato Boram Jul 04 '21 at 02:36
  • I've disabled `hirsute-proposed`, I'll see what happens next week. While it's nice if that solves it, it would be better to know how to disable only the prompt so it doesn't happen even if I use `-proposed` in the future, at least to actually answer the question. – Nato Boram Jul 04 '21 at 02:54
  • 2
    To those that are pointlessly questioning the need for this rather than just answering the question it's not uncommon to need to create servers in an automated process such as virtual private servers and use a standard initializing script for each new server and the script will automatically restart anyway. – JohnC Sep 09 '22 at 22:43

4 Answers4

10

This dialog is from 'autoremove'

To disable "Pending kernel upgrade" via command line:

vim /etc/needrestart/needrestart.conf

then uncomment this line

#$nrconf{kernelhints} = -1;

Or just replace them in one line:

sed -i "s/#\$nrconf{kernelhints} = -1;/\$nrconf{kernelhints} = -1;/g" /etc/needrestart/needrestart.conf
Benny Leung
  • 101
  • 1
  • 2
5

A workaround is to remove needrestart:

sudo apt -y remove needrestart
Error404
  • 6,920
  • 1
  • 26
  • 50
Ndsipa Pomu
  • 59
  • 1
  • 2
  • 1
    While this may work, it also removes a useful program and is likely not what most users want. Benny's answer below is less invasive. – Kevin Cooper Dec 16 '22 at 00:32
1

Having encountered this myself, I think the actual best way to do ths would be to remove needrestart from the scripts run after apt. On Ubuntu, this would be /etc/apt/apt.conf.d/99needrestart.

Depending on what you want to do exactly, either deleting /etc/apt/apt.conf.d/99needrestart permanently or temporarily moving it in the upgrade script would be the best way of sorting this out. needrestart has some uses, after all, so removing it entirely may not be the best idea.

-1

Instead of removing system package, better approach would be to disable system upgrade.
To disable auto-upgrade via command line:

  • Open and edit the /etc/apt/apt.conf.d/20auto-upgrades using the bellow command:
    sudoedit /etc/apt/apt.conf.d/20auto-upgrades

  • Change content FROM:
    APT::Periodic::Update-Package-Lists "1"; APT::Periodic::Unattended-Upgrade "1";

  • TO:
    APT::Periodic::Update-Package-Lists "0"; APT::Periodic::Download-Upgradeable-Packages "0"; APT::Periodic::AutocleanInterval "0"; APT::Periodic::Unattended-Upgrade "1";

    Save File
  • Pulkit Lall
    • 139
    • 1
    • 10