How to Reattach to a Disrupted Ubuntu Server ‘do-release-upgrade’ Process and Fix DPKG Lock Issues


2 views

During a critical do-release-upgrade on my Ubuntu 20.04 LTS server, I needed to inspect a configuration file in /etc/. After dropping to a shell, I accidentally terminated the process with Ctrl+C. The system prompted:

Do you want to try to reattach to the upgrade process? [Y/n]

Despite selecting yes, the reattachment failed, leaving me with:

  1. A zombie dpkg process holding /var/lib/dpkg/lock
  2. Incomplete package upgrades
  3. Potential system instability

First, verify the status of package management locks:

sudo lsof /var/lib/dpkg/lock
sudo lsof /var/lib/apt/lists/lock

Check for active dpkg processes:

ps aux | grep -i dpkg

Examine the upgrade logs for recovery clues:

tail -n 50 /var/log/dist-upgrade/*.log

Option 1: Clean Reattachment

Try restarting the upgrade manager:

sudo do-release-upgrade -f DistUpgradeViewText

If this fails with "Could not calculate the upgrade", proceed with manual recovery.

Option 2: Manual Process Recovery

First, clean up the locks (CAUTION: Only do this if no other package operations are running):

sudo rm /var/lib/apt/lists/lock
sudo rm /var/lib/dpkg/lock
sudo dpkg --configure -a

Then fix potentially broken packages:

sudo apt --fix-broken install
sudo apt update
sudo apt full-upgrade

For safer upgrades on headless servers:

# Use screen or tmux for session persistence
sudo apt install screen
screen -S upgrade
sudo do-release-upgrade

# Or use nohup
nohup sudo do-release-upgrade > upgrade.log 2>&1 &

Always create snapshots before major upgrades on virtualized environments:

# For KVM/qemu
virsh snapshot-create-as --domain vm_name --name pre-upgrade

We've all been there - mid-upgrade when you suddenly need to check a configuration file, hit Ctrl+C, and then:

Do you want to try to reattach to the upgrade process? [yN]
y
Failed to reattach - another process is holding the dpkg lock

Now you're left with a partially completed upgrade and a stubborn dpkg process holding the apt lock. Let's fix this properly.

First, check what's holding the lock:

sudo lsof /var/lib/dpkg/lock-frontend
sudo lsof /var/lib/apt/lists/lock

You'll likely see output showing dpkg or apt holding the lock. Common process names:

COMMAND   PID USER   FD   TYPE DEVICE SIZE/OFF   NODE NAME
dpkg    12345 root    3uW  REG  253,1        0 123456 /var/lib/dpkg/lock-frontend

Instead of brutally killing processes, try these in order:

sudo kill -TERM [pid]  # Try SIGTERM first
sudo kill -INT [pid]   # Then SIGINT
sudo kill -QUIT [pid]  # Finally SIGQUIT

Only if absolutely necessary:

sudo kill -9 [pid]  # SIGKILL as last resort

After terminating processes, run:

sudo dpkg --configure -a
sudo apt --fix-broken install

This completes any partially configured packages and fixes broken dependencies.

The magic command to resume your upgrade:

sudo do-release-upgrade -f DistUpgradeViewNonInteractive

This forces the upgrade to continue in non-interactive mode. For LTS to LTS upgrades, add:

sudo do-release-upgrade -d -f DistUpgradeViewNonInteractive

After successful reattachment, verify:

sudo apt update
sudo apt full-upgrade
sudo reboot

Consider using screen or tmux for long-running upgrades:

sudo apt install screen
screen -S upgrade
sudo do-release-upgrade
# Ctrl+A then D to detach
screen -r upgrade  # Reattach later