System Maintenance

Regular maintenance keeps an Arch system healthy and prevents issues during updates.

Regular Maintenance Checklist

Weekly

# Update system
sudo pacman -Syu

# Check for failed services
systemctl --failed

# Review journal errors
journalctl -p 3 -xb

Monthly

# Clean package cache
sudo paccache -rk2

# Remove orphaned packages
sudo pacman -Rns $(pacman -Qtdq) 2>/dev/null || echo "No orphans"

# Check for .pacnew/.pacsave files
sudo find /etc -name "*.pacnew" -o -name "*.pacsave" 2>/dev/null

# Update mirrorlist
sudo reflector --country US --age 12 --protocol https --sort rate --save /etc/pacman.d/mirrorlist

Package Cache Management

View Cache Size

du -sh /var/cache/pacman/pkg/

Clean with paccache

Install pacman-contrib for paccache:

sudo pacman -S pacman-contrib

# Keep last 3 versions (default)
sudo paccache -r

# Keep last 2 versions
sudo paccache -rk2

# Remove all uninstalled packages
sudo paccache -ruk0

# Dry run
paccache -d

Automatic Cache Cleaning

Enable weekly cache cleaning:

sudo systemctl enable --now paccache.timer

Orphaned Packages

Find Orphans

# List orphaned packages
pacman -Qtdq

# Count orphans
pacman -Qtdq | wc -l

Remove Orphans

# Remove all orphans
sudo pacman -Rns $(pacman -Qtdq)

# If none exist, the command fails - use this instead
pacman -Qtdq | sudo pacman -Rns - 2>/dev/null || echo "No orphans found"

Configuration File Management

.pacnew and .pacsave Files

When pacman updates a package with modified config: * .pacnew - New default config (your changes preserved) * .pacsave - Your old config (new defaults applied)

# Find all .pacnew files
sudo find /etc -name "*.pacnew" 2>/dev/null

# Compare and merge
sudo diff /etc/somefile /etc/somefile.pacnew
sudo vim /etc/somefile  # Merge changes
sudo rm /etc/somefile.pacnew

Using pacdiff

# Install pacman-contrib
sudo pacman -S pacman-contrib

# Interactive merge tool
sudo pacdiff

# Use vimdiff for comparison
sudo DIFFPROG=vimdiff pacdiff

System Health Checks

Check for Issues

# Failed systemd services
systemctl --failed

# Recent errors in journal
journalctl -p err -b

# Errors since last boot
journalctl -p 3 -xb

# Disk space
df -h

Verify Installed Packages

# Check for corrupted files
sudo pacman -Qk 2>&1 | grep -v "0 missing files"

# Verify specific package
pacman -Qkk package

# Check database consistency
sudo pacman -Dk

Check Disk Usage

# Overall disk usage
df -h

# Largest directories
du -sh /* 2>/dev/null | sort -h | tail -10

# Package cache size
du -sh /var/cache/pacman/pkg/

# Journal size
journalctl --disk-usage

Journal Maintenance

View Journal Size

journalctl --disk-usage

Clean Journal

# Keep only last 2 weeks
sudo journalctl --vacuum-time=2weeks

# Limit to 500MB
sudo journalctl --vacuum-size=500M

# Keep only last 100 entries
sudo journalctl --vacuum-files=100

Persistent Configuration

Edit /etc/systemd/journald.conf:

[Journal]
SystemMaxUse=500M
SystemMaxFileSize=50M
MaxRetentionSec=1month

Then restart:

sudo systemctl restart systemd-journald

Update Troubleshooting

PGP Signature Errors (Marginal Trust)

When system has been offline, keyring becomes stale:

error: package: signature from "Someone" is marginal trust
:: File ... is corrupted (invalid or corrupted package (PGP signature)).
Do you want to delete it? [Y/n]

Fix: Delete corrupted packages (Y), then update keyring first:

sudo pacman -Sy archlinux-keyring && sudo pacman -Syu

Keyring Fully Broken

If keyring update also fails:

# Remove and reinstall keyring
sudo rm -rf /etc/pacman.d/gnupg
sudo pacman-key --init
sudo pacman-key --populate archlinux
sudo pacman -Sy archlinux-keyring
sudo pacman -Syu

nvidia to nvidia-open Migration

Arch now defaults to nvidia-open. When prompted:

:: Replace nvidia with extra/nvidia-open? [Y/n]

Answer: Y - this is expected. nvidia-open is the open-source kernel module variant.

After reboot, verify:

nvidia-smi
lsmod | grep nvidia

nvidia-open Issues After Update

If display issues after nvidia-open migration:

# Check if module loaded
lsmod | grep nvidia

# Check for errors
dmesg | grep -i nvidia
journalctl -b | grep -i nvidia

# Verify kernel and driver match
pacman -Q linux nvidia-open
uname -r

If mismatch, rebuild:

sudo mkinitcpio -P
sudo reboot

Partial Upgrade Recovery

Never do pacman -Sy package without -u. If you did:

# Complete the upgrade
sudo pacman -Syu

Broken System Recovery

Boot from USB

If system won’t boot:

# Boot from Arch USB

# Mount system
mount /dev/sdX2 /mnt
mount /dev/sdX1 /mnt/boot

# Chroot
arch-chroot /mnt

# Fix issues, then
exit
umount -R /mnt
reboot

Reinstall All Packages

# Reinstall all native packages
sudo pacman -Qqn | sudo pacman -S -

# Reinstall specific package
sudo pacman -S package

Downgrade Package

# From cache
sudo pacman -U /var/cache/pacman/pkg/package-oldversion.pkg.tar.zst

# Using downgrade tool
yay -S downgrade
sudo downgrade package

Automation Script

Create a maintenance script at ~/bin/arch-maintenance:

#!/bin/bash
set -e

echo "=== Arch Linux Maintenance ==="

echo -e "\n[1/6] Updating system..."
sudo pacman -Syu

echo -e "\n[2/6] Cleaning package cache..."
sudo paccache -rk2
sudo paccache -ruk0

echo -e "\n[3/6] Removing orphans..."
orphans=$(pacman -Qtdq 2>/dev/null) || true
if [[ -n "$orphans" ]]; then
    echo "$orphans" | sudo pacman -Rns -
else
    echo "No orphans found"
fi

echo -e "\n[4/6] Checking failed services..."
systemctl --failed

echo -e "\n[5/6] Checking for .pacnew files..."
sudo find /etc -name "*.pacnew" 2>/dev/null || echo "None found"

echo -e "\n[6/6] Cleaning journal..."
sudo journalctl --vacuum-time=2weeks

echo -e "\n=== Maintenance Complete ==="

Make executable:

chmod +x ~/bin/arch-maintenance