g8gkq
Posts: 28
Joined: Thu Mar 30, 2017 10:25 am
Location: Southampton

Stretch Lite dist-upgrade fails

Fri Mar 01, 2019 10:11 am

I build 2 or 3 SD Cards a week for a system based on the 13 November 2018 Stretch Lite release. I use an install script that starts:

Code: Select all

#!/bin/bash

# Update the package manager
sudo dpkg --configure -a
sudo apt-get update

# Uninstall the apt-listchanges package to allow silent install of ca certificates
sudo apt-get -y remove apt-listchanges

# Update the distribution
sudo apt-get -y dist-upgrade

# Another 200 lines of install follow
During the last week, I have been getting occasional dpkg errors during the dist-upgrade. Needless to say, the subsequent application install fails. The error message is:

Code: Select all

Preparing to unpack .../libapt-inst2.0_1.4.9_armhf.deb ...
Unpacking libapt-inst2.0:armhf (1.4.9) over (1.4.8) ...
Preparing to unpack .../archives/apt_1.4.9_armhf.deb ...
Unpacking apt (1.4.9) over (1.4.8) ...
Setting up apt (1.4.9) ...
dpkg: error: dpkg status database is locked by another process
E: Sub-process /usr/bin/dpkg returned an error code (2)
E: Could not get lock /var/lib/dpkg/lock - open (11: Resource temporarily unavailable)
E: Unable to lock the administration directory (/var/lib/dpkg/), is another process using it?
At this point I would have expected to see:

Code: Select all

Preparing to unpack .../libapt-inst2.0_1.4.9_armhf.deb ...
Unpacking libapt-inst2.0:armhf (1.4.9) over (1.4.8) ...
Preparing to unpack .../archives/apt_1.4.9_armhf.deb ...
Unpacking apt (1.4.9) over (1.4.8) ...
Setting up apt (1.4.9) ...
(Reading database ... 34568 files and directories currently installed.)
I am using the same RPi 3B and install script as I have used without problem for the last 3 months. It happens with different cards (all SanDisk Ultra). It can happen on one build and then not happen when I try again 30 minutes later. I am not getting any other problems (for example power warnings) when a successful build has occurred.

Looking for ideas. I have compared a failed install with a successful install and they both used the same mirror servers.

Thanks

Dave

andrum99
Posts: 1207
Joined: Fri Jul 20, 2012 2:41 pm

Re: Stretch Lite dist-upgrade fails

Fri Mar 01, 2019 8:24 pm

Are you running anything else that would touch the packaging database at the same time? That is the most likely cause of the error you are seeing. Both command line and graphical software management tools on Raspbian use the same packaging database - you need to close them all before running the dist-upgrade.

Failing that, you can just reboot the Pi and delete the file /var/lib/dpkg/lock, since you can then be sure that no other process is actually using it.

g8gkq
Posts: 28
Joined: Thu Mar 30, 2017 10:25 am
Location: Southampton

Re: Stretch Lite dist-upgrade fails

Fri Mar 01, 2019 8:32 pm

Thanks @andrum99

No, not running anything else. Fresh image of Raspbian stretch Lite (ssh enabled) on first boot. No peripherals except a Waveshare 3.5 inch touchscreen which connects by GPIO, but no drivers loaded for that - they get loaded later in the script.

Dave

User avatar
scruss
Posts: 3155
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: Stretch Lite dist-upgrade fails

Fri Mar 01, 2019 9:06 pm

You tend to only get the dpkg: error: dpkg status database is locked by another process message if there's another dpkg script that was running before that. It could be that the SD card is glitching: do they pass fsck after they fail like this? (They might be branded Sandisk cards, but I've had legit ones do odd things.)

You might have to consider putting more error handling in your scripts. Check /var/lib/dpkg/lock before the script runs, make sure the filesystem is clean, etc. Networking and upgrades are hard to do automatically when there are so many variables.
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.
Pronouns: he/him

Return to “Troubleshooting”