How can I install VM operating system patches automatically?

Chris Dakin

Introduction

When running a LogonBox Virtual Machine, it is recommend to periodically check for any OS patches to keep your system as up to date and secure as possible.

This is usually a manual process either from VMCentre on the console, or using apt upgrade.

 

It is possible though to easily configure automatic updates for any OS packages. This article shows how you can do this.

 

Automatic OS updates

From a terminal or SSH session, run:

apt update
apt install unattended-upgrades apt-listchanges

...and that's it, the system will now automatically check for updates twice per day at 06:00 and 18:00 and will apply any that it finds at 06:00.

 

Changing the Download and Upgrade times

If you want to change the times for the downloads, you can create an override file:

mkdir /etc/systemd/system/apt-daily.timer.d
nano /etc/systemd/system/apt-daily.timer.d/override.conf

In that file, paste in the following, replacing the time you want in the second OnCalendar line. If you want it to check more than once, you can use commas (eg. 7,15,23:00)

[Timer]
OnCalendar=
OnCalendar=23:00
RandomizedDelaySec=0

Save the file with CTRL-X then Y and reinitialize it with:

systemctl restart apt-daily.timer
systemctl daemon-reload

 

If you want to change the time for the actual updates, you create another override file:

mkdir /etc/systemd/system/apt-daily-upgrade.timer.d
nano /etc/systemd/system/apt-daily-upgrade.timer.d/override.conf

In that file, paste in the following, replacing the time you want in the second OnCalendar line. If you want it to check more than once, you can use commas (eg. 7,15,23:00)

[Timer]
OnCalendar=
OnCalendar=23:00
RandomizedDelaySec=0

Save the file with CTRL-X then Y and reinitialize it with:

systemctl restart apt-daily-upgrade.timer
systemctl daemon-reload