basforge

Search titles, text and the “If it doesn’t work” cases.

    RU

    unattended-upgrades: security updates on their own and a reboot at 4:00

    Ubuntu Server already has automatic updates on, but without reboots: a new kernel gets installed and waits until someone restarts the server by hand. Your own 52unattended-upgrades-local file turns on a 4:00 reboot and old-kernel cleanup, and deliberately keeps the Docker repository out of auto-updates.

    How auto-updates work

    apt-daily.timer           twice a day, up to 12 h jitter        apt update
    apt-daily-upgrade.timer   around 6:00, up to 1 h jitter         unattended-upgrade
                                                                     ├─ installs packages from allowed origins
                                                                     ├─ writes /var/run/reboot-required
                                                                     └─ if allowed — reboots at the set time

    /etc/apt/apt.conf.d/20auto-upgrades turns this on; 50unattended-upgrades says what to install. Both come with the package. Don’t edit 50unattended-upgrades: on a package upgrade apt asks whose version to keep. Your settings go in a separate file with a number above 50.

    apt works the opposite way from sshd: files are read alphabetically and the last value wins. So our file is 52-…: it’s read after 50-… and overrides it. Lists (Allowed-Origins) aren’t overridden but appended to.

    What the package turns on

    /etc/apt/apt.conf.d/20auto-upgrades
    APT::Periodic::Update-Package-Lists "1";
    APT::Periodic::Unattended-Upgrade "1";

    1 means once a day: refresh package lists and run unattended-upgrade. Ubuntu Server creates the file at install time; if it’s missing, run sudo dpkg-reconfigure -plow unattended-upgrades.

    default no file — nothing installs

    /etc/apt/apt.conf.d/50unattended-upgrades — excerpt, don’t edit
    Unattended-Upgrade::Allowed-Origins {
            "${distro_id}:${distro_codename}";
            "${distro_id}:${distro_codename}-security";
            "${distro_id}ESMApps:${distro_codename}-apps-security";
            "${distro_id}ESM:${distro_codename}-infra-security";
    //      "${distro_id}:${distro_codename}-updates";
    };

    What installs itself: the main repository and security updates (noble-security, resolute-security on 26.04), plus ESM if the server is attached to Ubuntu Pro. ${distro_codename} fills itself in, so the file is the same for every release. Regular fixes (-updates) are commented out — install those by hand, with apt full-upgrade.

    Your file, block by block

    /etc/apt/apt.conf.d/52unattended-upgrades-local
    Unattended-Upgrade::Automatic-Reboot "true";
    Unattended-Upgrade::Automatic-Reboot-Time "04:00";
    Key part

    Reboot when an update needs it (/var/run/reboot-required appeared), at 4:00 in the server’s time zone. Without this line a new kernel and patched libraries wait weeks for a manual reboot, and a kernel hole stays open. Sites are down for 1–2 minutes every few weeks.

    default:Automatic-Reboot falseAutomatic-Reboot-Time now

    Unattended-Upgrade::Automatic-Reboot-WithUsers "true";

    Reboot even if someone is logged in over SSH. Otherwise one forgotten tmux session postpones the reboot indefinitely.

    default true

    Unattended-Upgrade::Remove-Unused-Kernel-Packages "true";
    Unattended-Upgrade::Remove-New-Unused-Dependencies "true";
    Unattended-Upgrade::Remove-Unused-Dependencies "true";

    Remove old kernels and packages left orphaned by an upgrade. A kernel takes about 300 MB in /lib/modules and 100 MB in /boot; a separate 1 GB /boot runs out of space within a year without cleanup.

    default:Remove-Unused-Kernel-Packages trueRemove-New-Unused-Dependencies trueRemove-Unused-Dependencies false

    Unattended-Upgrade::AutoFixInterruptedDpkg "true";

    If dpkg was interrupted mid-install on the server, finish that first (dpkg --configure -a) instead of giving up on updates.

    default false

    Unattended-Upgrade::Mail "[email protected]";
    Unattended-Upgrade::MailReport "only-on-error";

    An email report. Works only with a mail agent on the server (msmtp-mta, postfix); without one the line silently does nothing. only-on-error — write only if something failed to install.

    default:Mail no mailMailReport on-change

    Unattended-Upgrade::Origins-Pattern {
            "origin=Docker,label=Docker CE,codename=${distro_codename}";
    };

    Keep Docker out of auto-updates. Upgrading docker-ce restarts dockerd and every container with it — at night, unattended — and a new version can break the proxy, the way Docker 29 broke Traefik before 3.6.1 (Traefik). Upgrade Docker by hand: sudo apt install --only-upgrade docker-ce …, then check the sites.

    default Ubuntu origins only

    Restarting services after an update

    After a library update, the services that loaded it keep running the old copy in memory until restarted. needrestart handles that: after every install it looks for such processes. On Ubuntu 24.04 it restarts services itself, without asking, both in manual apt runs and in auto-updates: that’s how /etc/apt/apt.conf.d/99needrestart calls it. Exclude a service that must not be touched with $nrconf{override_rc} in a file under /etc/needrestart/conf.d/. The kernel and systemd can’t be swapped this way — they need a reboot. /var/run/reboot-required signals it (Is a reboot needed): package scripts create it at install time, and needrestart mentions the new kernel in apt’s output.

    If it doesn’t work

    Updates don’t install, /var/log/unattended-upgrades/ is empty

    Cause
    20auto-upgrades has "0", or the apt-daily* timers are off.
    Fix
    sudo dpkg-reconfigure -plow unattended-upgrades — answering Yes recreates the file; for the timers, systemctl list-timers 'apt-daily*'.

    The server rebooted at 4:00 UTC, not local time

    Cause
    Automatic-Reboot-Time uses the server’s time zone, and it’s still UTC.
    Fix
    timedatectl set-timezone … (First login to a server), or write the time in UTC.

    All containers restarted overnight

    Cause
    Docker itself was updated: docker.io from Ubuntu’s repository is part of security updates, and docker-ce is too if you added its source to Origins-Pattern. On upgrade dockerd restarts along with the containers.
    Fix
    Install Docker from its own repository and keep it out of auto-updates (Docker on Ubuntu); upgrade it by hand at a quiet time.

    apt says The following upgrades have been deferred due to phasing

    Cause
    Ubuntu rolls an update out to a share of machines at a time (phased updates) to catch bugs early. Security updates aren’t held back this way.
    Fix
    Nothing: within a few days the package reaches this server too.

    /boot filled up, the kernel update fails with No space left on device

    Cause
    Old kernels aren’t removed, and /boot is a separate partition of 500 MB–1 GB.
    Fix
    sudo apt autoremove --purge, and Remove-Unused-Kernel-Packages "true" in the file.

    How to check

    A dry run — what would install right now and from which origins, changing nothing:

    sudo unattended-upgrade --dry-run --debug 2>&1 | grep -E 'Allowed origins|Packages that will be upgraded|No packages found'
    # Allowed origins are: o=Ubuntu,a=noble, o=Ubuntu,a=noble-security, o=UbuntuESMApps,a=noble-apps-security, o=UbuntuESM,a=noble-infra-security
    # Packages that will be upgraded: libssl3t64 openssl

    Our file was read and its values are in effect:

    apt-config dump | grep -E 'Automatic-Reboot|Remove-Unused'
    # Unattended-Upgrade::Automatic-Reboot "true";
    # Unattended-Upgrade::Automatic-Reboot-Time "04:00";
    # Unattended-Upgrade::Automatic-Reboot-WithUsers "true";
    # Unattended-Upgrade::Remove-Unused-Kernel-Packages "true";
    # Unattended-Upgrade::Remove-Unused-Dependencies "true";

    The timers run:

    systemctl list-timers 'apt-daily*'
    # NEXT                        LEFT     LAST                        PASSED  UNIT
    # Mon 2026-10-19 06:12:40 CEST 7h left  Sun 2026-10-18 06:31:02 CEST 16h ago apt-daily-upgrade.timer
    # Mon 2026-10-19 09:47:19 CEST 10h left Sun 2026-10-18 18:20:55 CEST 4h ago  apt-daily.timer

    What got installed — the log for the last few days:

    sudo tail -20 /var/log/unattended-upgrades/unattended-upgrades.log