Skip to content

OS patching (VMs): Ubuntu

Ubuntu commands from the OS patching (VMs) folder.

Index
13 items

Ubuntu: List pending updates

Safe

What would be upgraded, without installing anything. This is the apt version of dnf check-update.

sudo apt update && apt list --upgradable
What each part does
  1. sudo apt updaterefresh the package lists (installs nothing)
  2. apt list --upgradablename, new version, [upgradable from: old]

My note apt check-update does not exist (E: Invalid operation check-update).

  • #ubuntu
  • #packages

Also known as: check-update · apt check-update · pending updates · updates can be applied immediately

Ubuntu: List pending security updates

Safe

Only the pending updates from the security pocket (the "standard security updates" in the login banner).

sudo apt update && apt list --upgradable 2>/dev/null | grep -- -security
What each part does
  1. apt list --upgradable 2>/dev/nullall pending updates, without the CLI warning
  2. grep -- -securitykeep lines from jammy-security, noble-security ...
  • #ubuntu
  • #security-updates

Also known as: security updates list · standard security updates · apt security

Ubuntu: Apply all pending updates

Caution

Installs every pending update including a new kernel. Clears the most scanner findings.

Dry run first
sudo apt update && sudo apt upgrade --dry-run
sudo apt update && sudo NEEDRESTART_MODE=a apt upgrade -y
What each part does
  1. sudo apt updaterefresh the package lists
  2. NEEDRESTART_MODE=arestart affected services automatically (no purple needrestart dialog)
  3. apt upgrade -yupgrade all packages, answer yes

My note "deferred due to phasing" = Ubuntu rolls that update out gradually; run it again in a few days. Do NOT run do-release-upgrade for patching (that moves you to the next Ubuntu release).

  • #ubuntu
  • #packages
  • #kernel

Also known as: apt upgrade · update everything · patch vm · full update

Ubuntu: Apply security updates only

Caution

Installs only updates from the security pocket (the default unattended-upgrades setting).

Dry run first
sudo unattended-upgrade --dry-run -d
sudo unattended-upgrade -d
What each part does
  1. unattended-upgradeinstall allowed updates (security by default)
  2. -ddebug output: shows each package

My note Missing? sudo apt install unattended-upgrades

  • #ubuntu
  • #security-updates

Also known as: security only · unattended-upgrades · apt security only

Ubuntu: Fix one CVE

Caution

Checks whether the CVE affects this VM and installs the fix. Works for CVE-… and USN-… IDs.

Dry run first
sudo pro fix <CVE-ID> --dry-run
sudo pro fix <CVE-ID>
What each part does
  1. pro fixfind and apply the update for a CVE or USN
  2. <CVE-ID>e.g. CVE-2026-109518 or USN-9011-1
  • #ubuntu
  • #cve

Also known as: fix cve · USN · ubuntu pro

Ubuntu: Update the kernel

Caution

Upgrades the kernel meta-package, which installs the newest kernel. Used after a reboot.

Dry run first
sudo apt update && sudo apt install --dry-run --only-upgrade linux-aws
sudo apt update && sudo apt install --only-upgrade linux-aws
What each part does
  1. apt install --only-upgradeupgrade, never install fresh
  2. linux-awskernel meta-package on EC2 (linux-generic on other servers, linux-azure on Azure)

My note Which meta-package do you have? dpkg -l | grep -E '^ii +linux-(aws|generic|azure) '

  • #ubuntu
  • #kernel

Also known as: kernel update · linux-aws · linux-generic · upgrade kernel

Ubuntu: Upgrade one package

Caution

Upgrade a single package without touching the rest.

Dry run first
sudo apt update && sudo apt install --dry-run --only-upgrade <package>
sudo apt update && sudo apt install --only-upgrade <package>
What each part does
  1. sudo apt updaterefresh the package lists
  2. apt install --only-upgrade <package>upgrade it if installed; never installs it fresh
  • #ubuntu
  • #packages

Also known as: single package · update one package · only-upgrade

Ubuntu: Install an exact package version

Caution

Install the exact "Fixed In" version from the scanner report (or go back to an older one).

Dry run first
sudo apt install --dry-run <package>=<version>
sudo apt install <package>=<version>
What each part does
  1. apt installinstall or change version
  2. <package>=<version>list versions with apt list -a <package>
  • #ubuntu
  • #packages

Also known as: specific version · fixed in version · downgrade

Ubuntu: Hold a package at its version

Safe

Keep apt upgrade from changing a package you want to patch on your own schedule.

sudo apt-mark hold <package>
What each part does
  1. apt-mark holdexclude from upgrades
  2. <package>the package

My note List: apt-mark showhold. Release: sudo apt-mark unhold <package>

  • #ubuntu
  • #packages

Also known as: freeze package · exclude package · apt hold

Ubuntu: Check if a reboot is needed

Safe

A new kernel or libc only takes effect after a reboot; scanners flag the old kernel until then.

[ -f /var/run/reboot-required ] && cat /var/run/reboot-required.pkgs || echo "No reboot needed"
What each part does
  1. /var/run/reboot-requiredcreated by apt when a reboot is needed
  2. reboot-required.pkgswhich packages asked for it

My note Then: sudo reboot (drops every SSH session; do it in a quiet window).

  • #ubuntu
  • #reboot

Also known as: reboot required · needs reboot · pending reboot

Ubuntu: Confirm the new kernel after reboot

Safe

The running kernel should now be the newest installed one (the scanner "Fixed In" version or newer).

uname -r && dpkg -l 'linux-image-*' | grep ^ii
What each part does
  1. uname -rrunning kernel
  2. dpkg -l 'linux-image-*' | grep ^iiinstalled kernel images
  • #ubuntu
  • #kernel

Also known as: verify kernel · installed kernels · kernel version after reboot

Ubuntu: Remove old kernels

Caution

Removes kernels and packages nothing needs anymore. Frees /boot and stops scanners flagging unused kernels.

Dry run first
sudo apt autoremove --purge --dry-run
sudo apt autoremove --purge
What each part does
  1. apt autoremoveremove automatically installed packages no longer needed
  2. --purgealso delete their config files
  • #ubuntu
  • #kernel

Also known as: old kernels · /boot full · autoremove

Ubuntu: Check a package changelog for a CVE fix

Safe

Ubuntu backports fixes, so the version can look old. A match here means the fix is in.

apt changelog <package> 2>/dev/null | grep -i <CVE-ID>
What each part does
  1. apt changelog <package>changelog of the candidate version
  2. grep -i <CVE-ID>any match = fixed

My note Installed version only: zgrep -i <CVE-ID> /usr/share/doc/<package>/changelog.Debian.gz

  • #ubuntu
  • #cve

Also known as: verify cve fixed · backport · debian changelog

My DevOps Playbook by Angelo John Calleja

New runbook

GitHub not connected

Saving is handled by the site: the GitHub token is stored in Cloudflare, not in your browser. Enter the editor password (the EDITOR_PASSWORD secret) to unlock saving in this browser.

Saving commits to gelogrammer/My_DevOps_Playbook. Create a fine-grained token with access to only this repo andContents: Read and write, then paste it here. It is stored only in this browser.

src/content/docs/…