21

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,278
  • 1
  • 13
  • 22

4 Answers4

22

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
  • 321
  • 2
  • 2
6

A workaround is to remove needrestart:

sudo apt -y remove needrestart
Error404
  • 8,278
  • 3
  • 35
  • 60
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.

0

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