Okay, let's break down automatic updates for OpenWrt.
Short Answer: Generally, NO, it is NOT recommended to automatically update the entire OpenWrt system (firmware/sysupgrade). However, automatically updating individual packages is technically possible but comes with its own risks.
Why Automatic System Updates (Sysupgrade) Are NOT Recommended:
- Risk of Bricking: A failed firmware flash (due to power loss, download corruption, insufficient flash space, hardware incompatibility with the new version, etc.) during an unattended update can leave your router unusable ("bricked") and require complex recovery procedures (like serial console access).
- Configuration Issues: While OpenWrt's
sysupgrade process tries hard to preserve your configuration, major version jumps or significant changes between releases can sometimes lead to incompatible settings, broken services, or require manual configuration adjustments. An automatic update might leave your network partially or fully non-functional without you immediately knowing why.
- Hardware Specifics: Different router models have specific firmware images. An automatic process could potentially grab the wrong image (less likely with official tools, but a risk in custom scripts). More importantly, new versions might drop support for older hardware or have regressions specific to certain chipsets.
- Loss of Custom Packages: Standard
sysupgrade doesn't automatically reinstall packages you added manually unless you use specific tools (like Attended Sysupgrade). An unattended basic sysupgrade would revert you to a base image, losing your custom software.
- Lack of Control & Review: You wouldn't have the chance to read release notes, check for known issues affecting your hardware/setup, or perform backups immediately before the update.
What About Automatic Package Updates (opkg upgrade)?
This is updating individual software components (like luci, dnsmasq, openssl, etc.) without flashing the entire firmware.
- Feasibility: Yes, this can be automated using
cron jobs and opkg commands.
- Recommendation: Still use with caution.
- Risks:
- Dependency Issues: Updating one package might break another if there are incompatible dependencies.
- Subtle Breakages: A package update could introduce bugs or change behavior in a way that affects your specific configuration.
- Flash Space: On devices with limited flash storage, upgrading packages can consume valuable space, potentially leading to instability or preventing future system upgrades.
- Kernel Modules: You generally cannot update kernel modules (
kmod-*) via opkg upgrade. They must match the running kernel, which only changes during a full system sysupgrade. Attempting to do so can cause serious instability.
The Easiest and Recommended Way to Update (Manually): Attended Sysupgrade
This is the closest you get to an easy, semi-automated update process while retaining control and minimizing risk.
- What it is: Attended Sysupgrade checks for a new OpenWrt version. If one is available, it builds a custom firmware image on the OpenWrt servers that includes your currently installed packages (excluding kernel modules, which are part of the base system). It then downloads this custom image and performs the sysupgrade, preserving your configuration.
- How to use it:
- Via LuCI (Web Interface): Go to
System -> Attended Sysupgrade. Click "Search for firmware update". If an update is found, review the package list (it shows what will be included) and click "Request firmware image". Once built, click "Flash image..." and follow the prompts.
- Via Command Line: Install the
auc package (opkg update && opkg install auc). Then run auc. It will guide you through the process.
- Why it's better:
- Keeps your custom packages installed across the upgrade.
- Preserves configuration reliably (same mechanism as standard
sysupgrade).
- Requires your explicit action ("attended"), so you control when it happens.
- You can review changes before proceeding.
How to Automate Package Updates (If You Accept the Risks):
If you decide you do want to automate package updates (not system updates):
- Create a script: Create a file, e.g.,
/etc/custom_scripts/auto_opkg_update.sh
- Add commands:
#!/bin/sh
# Update the package list
opkg update
# List upgradable packages (optional, for logging)
# opkg list-upgradable > /var/log/opkg_upgradable.log
# Upgrade specific packages (safer) - replace package1 package2 with actual names
# opkg upgrade package1 package2
# OR Upgrade all possible packages (riskier) - EXCLUDING kernel modules
opkg list-upgradable | cut -f 1 -d ' ' | grep -v '^kmod-' | xargs -r opkg upgrade
# Add a log entry (optional)
echo "Automatic package upgrade check run on $(date)" >> /var/log/auto_opkg.log
exit 0
- Note: The
grep -v '^kmod-' part is crucial to avoid trying to upgrade kernel modules.
- Upgrading only specific, known-safe packages is generally less risky than upgrading everything.
- Make it executable:
chmod +x /etc/custom_scripts/auto_opkg_update.sh
- Schedule with Cron:
Conclusion:
- Do NOT automate full OpenWrt system upgrades (sysupgrades). The risks are too high.
- The recommended way to update the system is manually using the Attended Sysupgrade feature via LuCI or
auc. Always back up your configuration first (System -> Backup / Flash Firmware -> Generate archive).
- Automating package updates is possible via
cron and opkg, but carries risks (flash space, dependencies, breakages) and should be done cautiously, preferably only upgrading specific packages rather than everything.