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
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
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
Journal Maintenance
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
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