ServerHandbook live check: run log ------------------------------------------------------------------------------ Check scripts/live/checks/apt-could-not-get-lock-ubuntu.mjs (sha256 e02218ab21cc84cbc4f0a91ed2bedaedfbc5b031c3430a89a2eaf549d21666dc) Ran at 2026-11-19T17:29:25Z (165 s) Result PASS, all 15 claims held Tested on System Ubuntu 24.04.5 LTS Kernel 6.8.0-147-generic Package apt 2.8.3 Package dpkg 1.22.6ubuntu6.6 Package lsof 4.95.0-1build3 Package procps 2:4.0.4-4ubuntu3.3 Package ncdu 1.19-0.1 Package tree 2.1.1-2ubuntu3.24.04.2 Setup A fresh Ubuntu 24.04 server (a VM from Ubuntu’s cloud image), reached over SSH as the sudo user deploy. Another apt-get install runs in the background and holds the package lock for about 75 seconds while the steps run. Every version above was read from the server at run time. Passwords used on the throwaway test server are shown as [password]. How we test: https://serverhandbook.com/how-we-test ------------------------------------------------------------------------------ What the steps changed on the server (recorded before the first step and after the last) Packages added (2) ncdu 1.19-0.1 tree 2.1.1-2ubuntu3.24.04.2 Packages upgraded (0) Packages removed (0) Services enabled at boot (0) Services disabled (0) Listening sockets opened (0) Listening sockets closed (0) Files added in /etc (0) Files changed in /etc (0) Files removed from /etc (0) Disk used on / (includes logs written during the run): +0.3 MB ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ Claims (15), each with what the run saw ------------------------------------------------------------------------------ 1. ok a bare Ubuntu 24.04 server box (web-server) starts 2. ok (setup) ncdu and tree are not installed yet | 2 3. ok (setup) another apt-get holds /var/lib/dpkg/lock-frontend 4. ok E: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process N (apt-get) | E: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 1966 (apt-get) | N: Be aware that removing the lock file is not a solution and may break your system. | E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), is another process using it? 5. ok E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), is another process using it? | E: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 1966 (apt-get) | N: Be aware that removing the lock file is not a solution and may break your system. | E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), is another process using it? 6. ok apt-get gives up at once with exit code 100 | 100 7. ok lsof: apt-get (root) has the lock file open | COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME | apt-get 1966 root 4uW REG 253,1 0 84122 /var/lib/dpkg/lock-frontend | apt-get 2168 root 4u REG 253,1 0 84122 /var/lib/dpkg/lock-frontend 8. ok ps: the apt-get install that runs, and for how long | PID ELAPSED COMMAND | 1966 00:04 apt-get install -y tree | 2168 00:03 apt-get install -y tree 9. ok …and installs ncdu once the other run is done | 83.768s | ... | Unpacking ncdu (1.19-0.1) ... | Setting up ncdu (1.19-0.1) ... | Processing triggers for man-db (2.12.0-4build2) ... | Scanning processes... | Scanning linux images... | | Running kernel seems to be up-to-date. | | No services need to be restarted. | | No containers need to be restarted. | | No user sessions are running outdated binaries. | | No VM guests are running outdated hypervisor (qemu) binaries on this host. 10. ok it waited for the other run (more than 20 s) | 83.768s 11. ok lsof prints nothing (no one holds it), and the lock file is still there | -rw-r----- 1 root root 0 Oct 17 12:55 /var/lib/dpkg/lock-frontend 12. ok dpkg --audit prints nothing: no package was left half-installed 13. ok tree (the other run) and ncdu are both installed | Package: tree | Status: install ok installed | Package: ncdu | Status: install ok installed 14. ok (dpkg has nothing half-done at the end of the steps) | rc=0 15. ok (tested on) the box reports its OS, kernel and the version of 6 package(s) | PRETTY_NAME="Ubuntu 24.04.5 LTS" | VIRT=none | KERNEL=6.8.0-147-generic | PKG apt 2.8.3 | PKG dpkg 1.22.6ubuntu6.6 | PKG lsof 4.95.0-1build3 | PKG ncdu 1.19-0.1 | PKG procps 2:4.0.4-4ubuntu3.3 | PKG tree 2.1.1-2ubuntu3.24.04.2 ------------------------------------------------------------------------------ Commands and what they printed (7) ------------------------------------------------------------------------------ $ sudo apt-get install -y ncdu E: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 1966 (apt-get) N: Be aware that removing the lock file is not a solution and may break your system. E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), is another process using it? $ sudo lsof /var/lib/dpkg/lock-frontend COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME apt-get 1966 root 4uW REG 253,1 0 84122 /var/lib/dpkg/lock-frontend apt-get 2168 root 4u REG 253,1 0 84122 /var/lib/dpkg/lock-frontend $ ps -C apt-get,apt,dpkg,unattended-upgr -o pid,etime,args PID ELAPSED COMMAND 1966 00:04 apt-get install -y tree 2168 00:03 apt-get install -y tree $ sudo apt-get -o DPkg::Lock::Timeout=300 install -y ncdu Waiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 1966 (apt-get) Waiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 1966 (apt-get) Waiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 1966 (apt-get) Waiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 1966 (apt-get) Waiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 1966 (apt-get) Waiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 1966 (apt-get) Waiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 1966 (apt-get) Waiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 1966 (apt-get) Waiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 1966 (apt-get) Waiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 1966 (apt-get) Waiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 1966 (apt-get) Waiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 1966 (apt-get) Waiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 1966 (apt-get) Waiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 1966 (apt-get) Waiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 1966 (apt-get) Waiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 1966 (apt-get) Waiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 1966 (apt-get) Waiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 1966 (apt-get) Waiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 1966 (apt-get) Waiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 1966 (apt-get) Waiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 1966 (apt-get) Waiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 1966 (apt-get) Waiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 1966 (apt-get) Waiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 1966 (apt-get) Waiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 1966 (apt-get) Waiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 1966 (apt-get) Waiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 1966 (apt-get) Waiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 1966 (apt-get) Waiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 1966 (apt-get) Waiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 1966 (apt-get) Waiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 1966 (apt-get) Waiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 1966 (apt-get) Waiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 1966 (apt-get) Waiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 1966 (apt-get) Waiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 1966 (apt-get) Waiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 1966 (apt-get) Waiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 1966 (apt-get) Waiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 1966 (apt-get) Waiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 1966 (apt-get) Waiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 1966 (apt-get) Waiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 1966 (apt-get) Waiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 1966 (apt-get) Waiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 1966 (apt-get) Waiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 1966 (apt-get) Waiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 1966 (apt-get) Waiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 1966 (apt-get) Waiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 1966 (apt-get) Waiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 1966 (apt-get) Waiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 1966 (apt-get) Waiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 1966 (apt-get) Waiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 1966 (apt-get) Waiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 1966 (apt-get) Waiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 1966 (apt-get) Waiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 1966 (apt-get) Waiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 1966 (apt-get) Waiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 1966 (apt-get) Waiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 1966 (apt-get) Waiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 1966 (apt-get) Waiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 1966 (apt-get) Waiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 1966 (apt-get) Waiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 1966 (apt-get) Waiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 1966 (apt-get) Waiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 1966 (apt-get) Waiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 1966 (apt-get) Waiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 1966 (apt-get) Waiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 1966 (apt-get) Waiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 1966 (apt-get) Waiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 1966 (apt-get) Waiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 1966 (apt-get) Waiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 1966 (apt-get) Waiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 1966 (apt-get) Waiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 1966 (apt-get) Waiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 1966 (apt-get) Waiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 1966 (apt-get) Waiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 1966 (apt-get) Waiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 1966 (apt-get) Waiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 1966 (apt-get) Reading package lists... Done Building dependency tree... Done Reading state information... Done The following NEW packages will be installed: ncdu 0 upgraded, 1 newly installed, 0 to remove and 51 not upgraded. Need to get 50.7 kB of archives. After this operation, 117 kB of additional disk space will be used. Get:1 http://archive.ubuntu.com/ubuntu noble/universe amd64 ncdu amd64 1.19-0.1 [50.7 kB] Fetched 50.7 kB in 1s (90.7 kB/s) Selecting previously unselected package ncdu. (Reading database ... 75079 files and directories currently installed.) Preparing to unpack .../ncdu_1.19-0.1_amd64.deb ... Unpacking ncdu (1.19-0.1) ... Setting up ncdu (1.19-0.1) ... Processing triggers for man-db (2.12.0-4build2) ... Scanning processes... Scanning linux images... Running kernel seems to be up-to-date. No services need to be restarted. No containers need to be restarted. No user sessions are running outdated binaries. No VM guests are running outdated hypervisor (qemu) binaries on this host. $ sudo lsof /var/lib/dpkg/lock-frontend; ls -l /var/lib/dpkg/lock-frontend -rw-r----- 1 root root 0 Oct 17 12:55 /var/lib/dpkg/lock-frontend $ sudo dpkg --audit $ dpkg -s tree ncdu | grep -E "^(Package|Status):" Package: tree Status: install ok installed Package: ncdu Status: install ok installed ------------------------------------------------------------------------------ The check's source (scripts/live/checks/apt-could-not-get-lock-ubuntu.mjs) As it ran. ------------------------------------------------------------------------------ /** * KB fix: apt "Could not get lock /var/lib/dpkg/lock-frontend". Break → see → fix → prove (plan04 §1): * another apt run holds the lock (a real apt-get install started in the background, kept busy by a DPkg::Pre-Invoke * sleep so the window is long and the same every run); apt-get fails at once; find the holder (lsof, ps); the right fix * is to wait: -o DPkg::Lock::Timeout makes apt-get wait and then install; the lock is free again the moment the holder * ends (it is a kernel lock on an open file, so nothing has to be deleted); `dpkg --audit` confirms nothing was left * half-done. * Runs on the local VM. */ import { bareBox, reportBox } from '../lib.mjs' const RELEASE = process.env.LIVE_BOX_RELEASE || '24.04' const FORCE_V4 = `echo 'Acquire::ForceIPv4 "true";' | sudo tee /etc/apt/apt.conf.d/99force-ipv4 >/dev/null` const HOLD = 75 // seconds the background apt-get keeps the lock const check = (ctx) => bareBox(ctx, async ({ sudoUser }) => { const { run, L } = sudoUser() // ── hidden: another apt run is busy, as after a new server's first boot ──────────────── L(`${FORCE_V4} && sudo apt-get update -qq`, 900000) L('sudo systemctl stop unattended-upgrades apt-daily.timer apt-daily-upgrade.timer 2>/dev/null; true') const absent = L('dpkg -s ncdu tree 2>&1 | grep -c "is not installed"') ctx.check('(setup) ncdu and tree are not installed yet', absent.trim() === '2', absent) L(`echo 'DPkg::Pre-Invoke {"sleep ${HOLD}";};' | sudo tee /etc/apt/apt.conf.d/99zz-slow >/dev/null`) L('sudo systemd-run --quiet --unit=other-apt --collect env DEBIAN_FRONTEND=noninteractive apt-get install -y tree') L('for i in $(seq 1 60); do sudo lsof /var/lib/dpkg/lock-frontend >/dev/null 2>&1 && break; sleep 1; done') ctx.check('(setup) another apt-get holds /var/lib/dpkg/lock-frontend', /apt-get/.test(L('sudo lsof /var/lib/dpkg/lock-frontend 2>/dev/null')), '') L('sudo rm /etc/apt/apt.conf.d/99zz-slow') // only the background run sleeps; it read its config already // ── 1. the error ──────────────────────────────────────────────────────────────────────── const e1 = run('sudo apt-get install -y ncdu', { id: 'error' }) ctx.check('E: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process N (apt-get)', /E: Could not get lock \/var\/lib\/dpkg\/lock-frontend\. It is held by process \d+ \(apt-get\)/.test(e1.out), e1.out) ctx.check('E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), is another process using it?', /E: Unable to acquire the dpkg frontend lock \(\/var\/lib\/dpkg\/lock-frontend\), is another process using it\?/.test(e1.out), e1.out) ctx.check('apt-get gives up at once with exit code 100', e1.exit === 100, String(e1.exit)) // ── 2. who holds it ───────────────────────────────────────────────────────────────────── const l1 = run('sudo lsof /var/lib/dpkg/lock-frontend', { id: 'lsof' }) ctx.check('lsof: apt-get (root) has the lock file open', /^apt-get\s+\d+\s+root\s/m.test(l1.out), l1.out) const p1 = run('ps -C apt-get,apt,dpkg,unattended-upgr -o pid,etime,args', { id: 'ps' }) ctx.check('ps: the apt-get install that runs, and for how long', /apt-get install -y tree/.test(p1.out), p1.out) // ── 3. wait for it, the safe fix ──────────────────────────────────────────────────────── const t0 = Date.now() const w1 = run('sudo apt-get -o DPkg::Lock::Timeout=300 install -y ncdu', { id: 'wait', timeout: 900000 }) const waited = (Date.now() - t0) / 1000 // the "Waiting for cache lock" line is a progress line apt erases once it gets the lock: the time proves the wait ctx.check('…and installs ncdu once the other run is done', w1.exit === 0 && /Setting up ncdu/.test(w1.out), `${waited}s\n${w1.out.slice(-400)}`) ctx.check(`it waited for the other run (more than 20 s)`, waited > 20, `${waited}s`) // ── 4. the lock is free without deleting anything ─────────────────────────────────────── const f1 = run('sudo lsof /var/lib/dpkg/lock-frontend; ls -l /var/lib/dpkg/lock-frontend', { id: 'free' }) ctx.check('lsof prints nothing (no one holds it), and the lock file is still there', /^-rw-r-----\s+1\s+root\s+root\s+0\s.*\/var\/lib\/dpkg\/lock-frontend$/m.test(f1.out) && !/apt-get\s+\d+/.test(f1.out), f1.out) const a1 = run('sudo dpkg --audit', { id: 'audit' }) ctx.check('dpkg --audit prints nothing: no package was left half-installed', a1.exit === 0 && a1.out === '', a1.out) const v1 = run('dpkg -s tree ncdu | grep -E "^(Package|Status):"', { id: 'both' }) ctx.check('tree (the other run) and ncdu are both installed', /Package: tree\nStatus: install ok installed/.test(v1.out) && /Package: ncdu\nStatus: install ok installed/.test(v1.out), v1.out) // ── end state ─────────────────────────────────────────────────────────────────────────── const e = L('sudo dpkg --audit; echo "rc=$?"') ctx.check('(dpkg has nothing half-done at the end of the steps)', /^rc=0$/.test(e.trim()), e) ctx.stepsDone() reportBox( ctx, L, `A fresh Ubuntu ${RELEASE} server (${process.env.LIVE_VPS ? 'a rented cloud server, rebuilt to the provider’s stock image' : 'a VM from Ubuntu’s cloud image'}), reached over SSH as the sudo user deploy. Another apt-get install runs in the background and holds the package lock for about ${HOLD} seconds while the steps run.`, ['apt', 'dpkg', 'lsof', 'procps', 'ncdu', 'tree'], ) }) export default check