Skip to content

OS patching (VMs): Amazon Linux 2

Amazon Linux 2 commands from the OS patching (VMs) folder.

Index
16 items

Amazon Linux 2: List pending updates

Safe

What would be upgraded. Exit code 100 = updates exist, 0 = none.

sudo yum check-update
What each part does
  1. yum check-updaterefresh metadata and list newer packages
  • #amazon-linux-2
  • #packages

Also known as: check-update · pending updates

Amazon Linux 2: List pending security updates

Safe

ALAS2 advisories that apply to this VM.

sudo yum updateinfo list security
What each part does
  1. yum updateinfo listadvisories for available updates
  2. securitysecurity only (use cves to list by CVE)
  • #amazon-linux-2
  • #security-updates

Also known as: ALAS2 · security advisories · updateinfo

Amazon Linux 2: Apply all updates

Caution

Installs every pending update including a new kernel.

Dry run first
sudo yum update --assumeno
sudo yum update -y
What each part does
  1. yum updateupgrade all packages
  2. -yanswer yes
  • #amazon-linux-2
  • #packages
  • #kernel

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

Amazon Linux 2: Apply security updates only

Caution

Installs only updates that have a security advisory.

Dry run first
sudo yum update --security --assumeno
sudo yum update --security -y
What each part does
  1. yum update --securitysecurity updates only
  2. -yanswer yes
  • #amazon-linux-2
  • #security-updates

Also known as: security only · security patch

Amazon Linux 2: Fix one advisory

Caution

Install only the packages from one advisory.

Dry run first
sudo yum update --advisory=<advisory-id> --assumeno
sudo yum update --advisory=<advisory-id>
What each part does
  1. --advisory=<advisory-id>e.g. ALAS2-2026-1234
  • #amazon-linux-2
  • #cve

Also known as: ALAS2 · apply advisory

Amazon Linux 2: Fix one CVE

Caution

Install only the update that fixes one CVE.

Dry run first
sudo yum update --cve <CVE-ID> --assumeno
sudo yum update --cve <CVE-ID>
What each part does
  1. --cve <CVE-ID>packages whose advisory lists this CVE
  • #amazon-linux-2
  • #cve

Also known as: fix cve · patch cve

Amazon Linux 2: Update the kernel

Caution

Installs the newest kernel in your current kernel line (4.14, 5.10 or 5.15). Used after a reboot.

Dry run first
sudo yum update kernel --assumeno
sudo yum update kernel -y
What each part does
  1. yum update kernelnewest kernel package

My note Move to the 5.15 line: sudo amazon-linux-extras install kernel-5.15 (check with amazon-linux-extras | grep kernel)

  • #amazon-linux-2
  • #kernel

Also known as: kernel update · kernel-5.15 · amazon-linux-extras

Amazon Linux 2: Upgrade one package

Caution

Upgrade a single package (and only what it needs).

Dry run first
sudo yum update <package> --assumeno
sudo yum update <package>
What each part does
  1. yum update <package>e.g. java-11-amazon-corretto-headless
  • #amazon-linux-2
  • #packages

Also known as: single package · update one package

Amazon Linux 2: Install an exact package version

Caution

Install the exact "Fixed In" version from the scanner report.

Dry run first
sudo yum install <package>-<version> --assumeno
sudo yum install <package>-<version>
What each part does
  1. <package>-<version>list versions with yum list --showduplicates <package>
  • #amazon-linux-2
  • #packages

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

Amazon Linux 2: Lock a package version

Safe

Keep yum update from changing a package.

sudo yum versionlock add <package>
What each part does
  1. yum versionlock addlock the installed version (package yum-plugin-versionlock)

My note List: yum versionlock list. Remove: sudo yum versionlock delete <package>

  • #amazon-linux-2
  • #packages

Also known as: freeze package · versionlock

Amazon Linux 2: Check if a reboot is needed

Safe

Exit code 1 and the reason when a reboot is needed.

sudo needs-restarting -r
What each part does
  1. needs-restarting -ris a reboot needed? (package yum-utils)

My note Then: sudo reboot

  • #amazon-linux-2
  • #reboot

Also known as: reboot required · needs-restarting

Amazon Linux 2: Confirm the new kernel after reboot

Safe

The running kernel should be the newest installed one.

uname -r && rpm -q kernel
What each part does
  1. uname -rrunning kernel
  2. rpm -q kernelinstalled kernels
  • #amazon-linux-2
  • #kernel

Also known as: verify kernel · installed kernels

Amazon Linux 2: Set the default boot kernel

Caution

Choose which installed kernel boots next, e.g. go back to the previous one after a bad update.

Dry run first
sudo grubby --info /boot/vmlinuz-<version>
sudo grubby --set-default /boot/vmlinuz-<version>
What each part does
  1. grubby --set-defaultchange the default boot entry
  2. /boot/vmlinuz-<version>list them with ls /boot/vmlinuz-*

My note Current default: sudo grubby --default-kernel

  • #amazon-linux-2
  • #kernel

Also known as: default kernel · kernel rollback · grubby

Amazon Linux 2: Remove old kernels

Caution

Keeps the two newest kernels and removes the rest.

Dry run first
rpm -q kernel --last && uname -r
sudo package-cleanup --oldkernels --count=2 -y
What each part does
  1. package-cleanup --oldkernelsremove old kernels (package yum-utils)
  2. --count=2how many to keep
  • #amazon-linux-2
  • #kernel

Also known as: old kernels · /boot full

Amazon Linux 2: Check a package changelog for a CVE fix

Safe

A match means the installed package contains the fix.

rpm -q --changelog <package> | grep -i <CVE-ID>
What each part does
  1. rpm -q --changelog <package>changelog of the installed package
  2. grep -i <CVE-ID>any match = fixed
  • #amazon-linux-2
  • #cve

Also known as: verify cve fixed · backport

Amazon Linux 2: Undo the last update

Caution

Roll back the most recent yum transaction.

Dry run first
sudo yum history info last
sudo yum history undo last
What each part does
  1. yum historylist transactions
  2. undo lastrevert the newest one
  • #amazon-linux-2
  • #packages

Also known as: rollback update · yum history

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/…