DEV Community

vast cow
vast cow

Posted on

Keeping Rocky Linux 9 Up to Date with `dnf-automatic`

Keeping your system updated is one of the most important steps for maintaining security, stability, and performance. On Rocky Linux 9.6, the dnf-automatic package can periodically check for available updates and either notify administrators, download packages, or install updates automatically.

This guide covers installation, configuration, automatic updates, and a notification-only configuration that uses MOTD without downloading or installing packages.


1. Install dnf-automatic

The dnf-automatic tool is not installed by default. Install it with:

sudo dnf install -y dnf-automatic
Enter fullscreen mode Exit fullscreen mode

2. Configure dnf-automatic

The main configuration file is:

/etc/dnf/automatic.conf
Enter fullscreen mode Exit fullscreen mode

Open it with your preferred text editor:

sudo nano /etc/dnf/automatic.conf
Enter fullscreen mode Exit fullscreen mode

Key options

Upgrade type

The upgrade_type setting controls which updates are detected:

[commands]
upgrade_type = security
Enter fullscreen mode Exit fullscreen mode

Available values include:

  • default — all available updates
  • security — only updates associated with security advisories

Download updates

To allow automatic package downloads:

download_updates = yes
Enter fullscreen mode Exit fullscreen mode

To prevent automatic package downloads:

download_updates = no
Enter fullscreen mode Exit fullscreen mode

Apply updates automatically

To install available updates automatically:

apply_updates = yes
Enter fullscreen mode Exit fullscreen mode

To prevent automatic installation:

apply_updates = no
Enter fullscreen mode Exit fullscreen mode

When apply_updates = yes is configured, packages must also be downloaded.

Emitters

The [emitters] section controls how results are reported. Available mechanisms include standard output, email, custom commands, and MOTD.

For example, to report results through MOTD:

[emitters]
emit_via = motd
Enter fullscreen mode Exit fullscreen mode

The MOTD emitter writes the update report to /etc/motd, allowing administrators to see it when logging in through SSH or a local console.


3. Enable Automatic Updates

The generic dnf-automatic.timer follows the behavior configured in /etc/dnf/automatic.conf.

For example, to download and install security updates automatically, configure:

[commands]
upgrade_type = security
download_updates = yes
apply_updates = yes
Enter fullscreen mode Exit fullscreen mode

Then enable and start the timer:

sudo systemctl enable --now dnf-automatic.timer
Enter fullscreen mode Exit fullscreen mode

This causes dnf-automatic to check for and process updates according to the configuration file.


4. Notification Only with MOTD

To notify administrators about available updates without downloading or installing any packages, configure dnf-automatic to use the MOTD emitter.

Edit /etc/dnf/automatic.conf:

sudo nano /etc/dnf/automatic.conf
Enter fullscreen mode Exit fullscreen mode

Use the following settings:

[commands]
upgrade_type = security
download_updates = no
apply_updates = no

[emitters]
emit_via = motd
Enter fullscreen mode Exit fullscreen mode

This configuration:

  • Checks repository metadata for available security updates
  • Does not download update packages
  • Does not install update packages
  • Writes the result to /etc/motd

Enable the notification-only timer:

sudo systemctl enable --now dnf-automatic-notifyonly.timer
Enter fullscreen mode Exit fullscreen mode

The dnf-automatic-notifyonly.timer unit overrides the download and installation behavior and performs notification only. The explicit download_updates = no and apply_updates = no settings are retained in the configuration for clarity and as a safe default when the generic timer is used.

Disable download and installation timers

To ensure that no other dnf-automatic timer downloads or installs packages, disable the generic, download, and installation timers:

sudo systemctl disable --now dnf-automatic.timer
sudo systemctl disable --now dnf-automatic-download.timer
sudo systemctl disable --now dnf-automatic-install.timer
Enter fullscreen mode Exit fullscreen mode

Then enable only the notification timer:

sudo systemctl enable --now dnf-automatic-notifyonly.timer
Enter fullscreen mode Exit fullscreen mode

Verify the enabled timers:

systemctl list-timers --all | grep dnf-automatic
Enter fullscreen mode Exit fullscreen mode

Only dnf-automatic-notifyonly.timer should be enabled for the notification-only configuration.

Check the MOTD output

Run the service manually to test the configuration:

sudo systemctl start dnf-automatic-notifyonly.service
Enter fullscreen mode Exit fullscreen mode

Display the generated MOTD:

cat /etc/motd
Enter fullscreen mode Exit fullscreen mode

The message will also be displayed during the next SSH or console login, provided the system's login configuration displays /etc/motd.

Note: Checking for updates still requires refreshing or reading repository metadata. The notification-only configuration prevents RPM packages from being downloaded; it does not eliminate repository metadata traffic.


5. Other Timer Modes

dnf-automatic provides several systemd timers for different operating modes.

Follow /etc/dnf/automatic.conf

sudo systemctl enable --now dnf-automatic.timer
Enter fullscreen mode Exit fullscreen mode

Notify only

Checks for updates and reports the result without downloading or installing packages:

sudo systemctl enable --now dnf-automatic-notifyonly.timer
Enter fullscreen mode Exit fullscreen mode

Download without installation

Downloads available packages but does not install them:

sudo systemctl enable --now dnf-automatic-download.timer
Enter fullscreen mode Exit fullscreen mode

Download and install

Downloads and installs available updates:

sudo systemctl enable --now dnf-automatic-install.timer
Enter fullscreen mode Exit fullscreen mode

The specialized timer units override the corresponding download and installation settings in /etc/dnf/automatic.conf.


6. Verification and Troubleshooting

Check the notification-only timer:

systemctl status dnf-automatic-notifyonly.timer
Enter fullscreen mode Exit fullscreen mode

Check when it will run next:

systemctl list-timers --all | grep dnf-automatic
Enter fullscreen mode Exit fullscreen mode

Check the service logs:

journalctl -u dnf-automatic-notifyonly.service
Enter fullscreen mode Exit fullscreen mode

Check recent logs for all dnf-automatic units:

journalctl -u 'dnf-automatic*'
Enter fullscreen mode Exit fullscreen mode

Confirm which timers are enabled:

systemctl is-enabled dnf-automatic.timer
systemctl is-enabled dnf-automatic-notifyonly.timer
systemctl is-enabled dnf-automatic-download.timer
systemctl is-enabled dnf-automatic-install.timer
Enter fullscreen mode Exit fullscreen mode

For a notification-only system, the expected result is:

disabled
enabled
disabled
disabled
Enter fullscreen mode Exit fullscreen mode

Conclusion

Rocky Linux 9.6 can use dnf-automatic in several modes:

  • Automatic installation for systems that should remain patched without manual intervention
  • Automatic download for systems where installation is performed separately
  • Notification only for controlled environments where administrators review updates before taking action

For a notification-only configuration with no package downloads, use:

[commands]
upgrade_type = security
download_updates = no
apply_updates = no

[emitters]
emit_via = motd
Enter fullscreen mode Exit fullscreen mode

Enable only:

sudo systemctl enable --now dnf-automatic-notifyonly.timer
Enter fullscreen mode Exit fullscreen mode

This configuration reports available security updates through MOTD while leaving package download and installation under manual control.

dnf-automatic を使用して Rocky Linux 9 を最新の状態に保つ

システムを最新の状態に維持することは、セキュリティ、安定性、およびパフォーマンスを確保するために最も重要な作業の一つです。Rocky Linux 9.6 では、dnf-automatic パッケージを使用することで、利用可能な更新を定期的に確認し、管理者への通知、パッケージのダウンロード、または更新の自動インストールを実行できます。

このガイドでは、インストール、設定、自動更新の構成、およびパッケージのダウンロードやインストールを行わずに MOTD を使用して通知のみを行う構成について説明します。


1. dnf-automatic をインストールする

dnf-automatic はデフォルトではインストールされていません。次のコマンドでインストールします。

sudo dnf install -y dnf-automatic
Enter fullscreen mode Exit fullscreen mode

2. dnf-automatic を設定する

メインの設定ファイルは次の場所にあります。

/etc/dnf/automatic.conf
Enter fullscreen mode Exit fullscreen mode

お好みのテキストエディタで開きます。

sudo nano /etc/dnf/automatic.conf
Enter fullscreen mode Exit fullscreen mode

主な設定項目

更新の種類

upgrade_type は、どの種類の更新を検出するかを指定します。

[commands]
upgrade_type = security
Enter fullscreen mode Exit fullscreen mode

指定できる値は次のとおりです。

  • default — 利用可能なすべての更新
  • security — セキュリティアドバイザリに関連付けられた更新のみ

更新パッケージのダウンロード

パッケージを自動的にダウンロードする場合は、次のように設定します。

download_updates = yes
Enter fullscreen mode Exit fullscreen mode

自動ダウンロードを無効にする場合は、次のように設定します。

download_updates = no
Enter fullscreen mode Exit fullscreen mode

更新の自動適用

利用可能な更新を自動的にインストールする場合は、次のように設定します。

apply_updates = yes
Enter fullscreen mode Exit fullscreen mode

自動インストールを無効にする場合は、次のように設定します。

apply_updates = no
Enter fullscreen mode Exit fullscreen mode

apply_updates = yes を設定する場合は、パッケージのダウンロードも有効になっている必要があります。

Emitters(通知方法)

[emitters] セクションでは、結果の通知方法を指定します。利用できる通知方法には、標準出力、メール、カスタムコマンド、および MOTD があります。

たとえば、MOTD を使用して通知する場合は次のように設定します。

[emitters]
emit_via = motd
Enter fullscreen mode Exit fullscreen mode

MOTD エミッターは更新結果を /etc/motd に書き込み、SSH やローカルコンソールでログインした際に管理者が確認できるようにします。


3. 自動更新を有効にする

汎用の dnf-automatic.timer は、/etc/dnf/automatic.conf に設定された内容に従って動作します。

たとえば、セキュリティ更新を自動的にダウンロードしてインストールする場合は、次のように設定します。

[commands]
upgrade_type = security
download_updates = yes
apply_updates = yes
Enter fullscreen mode Exit fullscreen mode

その後、タイマーを有効化して起動します。

sudo systemctl enable --now dnf-automatic.timer
Enter fullscreen mode Exit fullscreen mode

これにより、dnf-automatic は設定ファイルに従って更新を確認し、必要な処理を実行します。


4. MOTD を使用した通知のみの構成

パッケージをダウンロードまたはインストールせず、利用可能な更新だけを管理者へ通知する場合は、dnf-automatic を MOTD エミッターで構成します。

/etc/dnf/automatic.conf を編集します。

sudo nano /etc/dnf/automatic.conf
Enter fullscreen mode Exit fullscreen mode

次のように設定します。

[commands]
upgrade_type = security
download_updates = no
apply_updates = no

[emitters]
emit_via = motd
Enter fullscreen mode Exit fullscreen mode

この構成では次の動作を行います。

  • 利用可能なセキュリティ更新を確認する
  • 更新パッケージはダウンロードしない
  • 更新パッケージはインストールしない
  • 結果を /etc/motd に書き込む

通知専用タイマーを有効にします。

sudo systemctl enable --now dnf-automatic-notifyonly.timer
Enter fullscreen mode Exit fullscreen mode

dnf-automatic-notifyonly.timer は、ダウンロードおよびインストール動作を上書きし、通知のみを実行します。download_updates = no および apply_updates = no を設定ファイルに明示的に記述しておくことで、設定内容が分かりやすくなり、汎用タイマーを使用した場合でも安全なデフォルトとして機能します。

ダウンロードおよびインストール用タイマーを無効にする

他の dnf-automatic タイマーによってパッケージがダウンロードまたはインストールされないようにするため、汎用タイマー、ダウンロードタイマー、およびインストールタイマーを無効にします。

sudo systemctl disable --now dnf-automatic.timer
sudo systemctl disable --now dnf-automatic-download.timer
sudo systemctl disable --now dnf-automatic-install.timer
Enter fullscreen mode Exit fullscreen mode

その後、通知専用タイマーのみを有効にします。

sudo systemctl enable --now dnf-automatic-notifyonly.timer
Enter fullscreen mode Exit fullscreen mode

有効になっているタイマーを確認します。

systemctl list-timers --all | grep dnf-automatic
Enter fullscreen mode Exit fullscreen mode

通知専用構成では、dnf-automatic-notifyonly.timer のみが有効になっていることを確認してください。

MOTD の出力を確認する

設定をテストするためにサービスを手動で実行します。

sudo systemctl start dnf-automatic-notifyonly.service
Enter fullscreen mode Exit fullscreen mode

生成された MOTD を表示します。

cat /etc/motd
Enter fullscreen mode Exit fullscreen mode

システムのログイン設定で /etc/motd が表示されるようになっていれば、次回 SSH またはローカルコンソールでログインした際にも同じ内容が表示されます。

注: 更新の確認では、リポジトリメタデータの更新または読み込みが必要です。通知専用構成では RPM パッケージのダウンロードは行われませんが、リポジトリメタデータの通信自体は発生します。


5. その他のタイマーモード

dnf-automatic には、用途に応じた複数の systemd タイマーが用意されています。

/etc/dnf/automatic.conf の設定に従う

sudo systemctl enable --now dnf-automatic.timer
Enter fullscreen mode Exit fullscreen mode

通知のみ

更新を確認し、ダウンロードやインストールを行わずに結果だけを通知します。

sudo systemctl enable --now dnf-automatic-notifyonly.timer
Enter fullscreen mode Exit fullscreen mode

ダウンロードのみ

利用可能な更新パッケージをダウンロードしますが、インストールは行いません。

sudo systemctl enable --now dnf-automatic-download.timer
Enter fullscreen mode Exit fullscreen mode

ダウンロードとインストール

更新パッケージをダウンロードし、そのままインストールします。

sudo systemctl enable --now dnf-automatic-install.timer
Enter fullscreen mode Exit fullscreen mode

これらの専用タイマーは、/etc/dnf/automatic.conf に設定されたダウンロードおよびインストールに関する項目を必要に応じて上書きして動作します。


6. 動作確認とトラブルシューティング

通知専用タイマーの状態を確認します。

systemctl status dnf-automatic-notifyonly.timer
Enter fullscreen mode Exit fullscreen mode

次回の実行予定を確認します。

systemctl list-timers --all | grep dnf-automatic
Enter fullscreen mode Exit fullscreen mode

サービスログを確認します。

journalctl -u dnf-automatic-notifyonly.service
Enter fullscreen mode Exit fullscreen mode

dnf-automatic に関連するすべてのログを確認します。

journalctl -u 'dnf-automatic*'
Enter fullscreen mode Exit fullscreen mode

各タイマーが有効かどうかを確認します。

systemctl is-enabled dnf-automatic.timer
systemctl is-enabled dnf-automatic-notifyonly.timer
systemctl is-enabled dnf-automatic-download.timer
systemctl is-enabled dnf-automatic-install.timer
Enter fullscreen mode Exit fullscreen mode

通知専用構成では、期待される結果は次のとおりです。

disabled
enabled
disabled
disabled
Enter fullscreen mode Exit fullscreen mode

まとめ

Rocky Linux 9.6 では、dnf-automatic を次のような用途に応じて利用できます。

  • 手動操作なしで常に最新の状態を維持したいシステム向けの自動インストール
  • インストールは別途実施し、事前にパッケージだけを取得したい環境向けの自動ダウンロード
  • 更新内容を管理者が確認したうえで適用する運用向けの通知のみ

パッケージをダウンロードせず、通知のみを行う構成は次のとおりです。

[commands]
upgrade_type = security
download_updates = no
apply_updates = no

[emitters]
emit_via = motd
Enter fullscreen mode Exit fullscreen mode

有効にするタイマーは次のものだけです。

sudo systemctl enable --now dnf-automatic-notifyonly.timer
Enter fullscreen mode Exit fullscreen mode

この構成では、利用可能なセキュリティ更新が MOTD を通じて通知され、パッケージのダウンロードおよびインストールは手動管理のまま維持されます。

Top comments (0)