I have unattended-upgrade
set up on my Ubuntu systems. Occasionally I will log in remotely to one of them and I'll see a message informing me that I need to reboot the system (in order to complete an upgrade). Is there a way to determine the specific package (or set of packages) which is triggering this notice?
4 Answers
Short version:
cat /var/run/reboot-required.pkgs
Explanation:
Looks like there is an easy way to automatically extract the requested information.
Inside .deb
files there are control files for installation, including postinst
(run after installation).
For example, in linux-image-2.6.35-25-generic_2.6.35-25.44_amd64.deb
,
postinst
includes
my $notifier = "/usr/share/update-notifier/notify-reboot-required";
my $warn_reboot = 'Yes'; # Warn that we are installing a version of
# the kernel we are running
and
# Warn of a reboot
if (-x $notifier) {
system($notifier);
}
The shell script
/usr/share/update-notifier/notify-reboot-required
updates
/var/run/reboot-required
and /var/run/reboot-required.pkgs
.
The latter file contains a list of packages requesting a reboot.
-
2On my system the file
/var/run/reboot-required
was created a day before but there is no/var/run/reboot-required.pkgs
file @ Ubuntu 16.04.5 LTS.– LionAug 9, 2018 at 10:51
Reboot is recommended by the unattended-upgrades
when it sees that a /var/run/reboot-required
exists. The file is created by postinst
(post-installation) scripts in some packages, it looks something like this:
[ -x /usr/share/update-notifier/notify-reboot-required ] && \
/usr/share/update-notifier/notify-reboot-required || true
If you want to see which packages triggered this, you can have a look at the contents of the /var/run/reboot-required.pkgs
file.
For more info also see this thread.
Based on Olli's earlier answer, I came up with a method to find all currently installed packages on your system that requires a reboot.
~$ mkdir debs
~$ cd debs
~/debs$ apt-get download $(dpkg -l | tail -n +7 | awk '{print $2}')
Wait for the download to complete, on my system it was around 900 MB so it might take a while depending on your connection. Then:
~/debs$ for x in $(ls); do y=$(dpkg-deb -I "$x" postinst 2>/dev/null | grep 'reboot-required'); if [ -n "$y" ]; then echo "$x" | grep -Poe '^.*?(?=_)'; fi; done
The output may look something like this:
dbus
gconf2
initscripts
libc6
libpam0g
libpam-systemd
libssl1.0.0
linux-image-3.19.0-47-generic
linux-image-3.19.0-49-generic
network-manager
upstart
Of course, this method is not foolproof. There might be packages that notifies about the required reboot through other means than 'notify-reboot-required', and while this shows which currently installed packages require or doesn't require a reboot, it is not certain the same will hold true for later versions of the same package.
-
5You could acomplish the same without any tedious downloading with just
grep -l reboot-required /var/lib/dpkg/info/*.postinst | sed -e 's,^.*/\(.*\)\.postinst,\1,'
. Note however that it will only report which packages might require reboot at some time, not which package did require reboot this time Sep 1, 2017 at 15:40
I don't really know if there are other packages that require rebooting, but kernel updates always do. I'd say almost every time I've been "asked" to reboot, the kernel had been updated.
-
1That's not good enough in my opinion. Bootloader updates also request rebooting, as well as init (upstart).– OlliMar 1, 2011 at 8:59
-
1Well, also some other packages, like DBus: ubuntu.com/usn/USN-799-1 . So compiling list of packages that require restart (DBus do not always require that) is foolish for complete solution.– OlliMar 1, 2011 at 9:01
-
1You're right... Mine is a partial knowledge :(. Thanks for the information. I hadn't realized other packages require restart, too.– luriMar 1, 2011 at 11:19