Could not get lock /var/lib/dpkg/lock-frontend


I’m trying to create an image in GCP, but I’m getting the next error:

==> googlecompute: Provisioning with shell script: /var/folders/c6/t49g6krj66ld0wq8q13x9rg80000gn/T/packer-shell399635902
    googlecompute: Hit:1 bionic InRelease
    googlecompute: Get:2 bionic-updates InRelease [88.7 kB]
    googlecompute: Get:3 bionic-backports InRelease [74.6 kB]
    googlecompute: Get:4 bionic-security InRelease [88.7 kB]
    googlecompute: Get:5 bionic InRelease [10.2 kB]
    googlecompute: Get:6 bionic InRelease [64.4 kB]
    googlecompute: Get:7 bionic InRelease [85.3 kB]
    googlecompute: Get:8 bionic-updates/main amd64 Packages [859 kB]
    googlecompute: Get:9 bionic-updates/main Translation-en [300 kB]
    googlecompute: Get:10 bionic-updates/restricted amd64 Packages [31.2 kB]
    googlecompute: Get:11 bionic-updates/restricted Translation-en [8128 B]
    googlecompute: Get:12 bionic-updates/universe amd64 Packages [1051 kB]
    googlecompute: Get:13 bionic-updates/universe Translation-en [325 kB]
    googlecompute: Get:14 bionic-updates/multiverse amd64 Packages [9700 B]
    googlecompute: Get:15 bionic-updates/multiverse Translation-en [4576 B]
    googlecompute: Get:16 bionic-backports/universe amd64 Packages [4028 B]
    googlecompute: Get:17 bionic-backports/universe Translation-en [1900 B]
    googlecompute: Get:18 bionic-security/main amd64 Packages [636 kB]
    googlecompute: Get:19 bionic-security/main Translation-en [208 kB]
    googlecompute: Get:20 bionic-security/restricted amd64 Packages [21.2 kB]
    googlecompute: Get:21 bionic-security/restricted Translation-en [5984 B]
    googlecompute: Get:22 bionic-security/universe amd64 Packages [645 kB]
    googlecompute: Get:23 bionic-security/universe Translation-en [217 kB]
    googlecompute: Get:24 bionic-security/multiverse amd64 Packages [6340 B]
    googlecompute: Get:25 bionic-security/multiverse Translation-en [2640 B]
    googlecompute: Get:26 bionic/partner amd64 Packages [2292 B]
    googlecompute: Get:27 bionic/partner Translation-en [1332 B]
    googlecompute: Get:28 bionic/stable amd64 Packages [10.3 kB]
    googlecompute: Get:29 bionic/puppet all Packages [16.4 kB]
    googlecompute: Get:30 bionic/puppet amd64 Packages [39.9 kB]
    googlecompute: Fetched 4818 kB in 7s (661 kB/s)
    googlecompute: Reading package lists...
==> googlecompute: E: Could not get lock /var/lib/dpkg/lock-frontend - open (11: Resource temporarily unavailable)
==> googlecompute: E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), is another process using it?
==> googlecompute: Provisioning step had errors: Running the cleanup provisioner, if present...
==> googlecompute: Deleting instance...
    googlecompute: Instance has been deleted!
==> googlecompute: Deleting disk...
    googlecompute: Disk has been deleted!
Build 'googlecompute' errored: Script exited with non-zero exit status: 100.Allowed exit codes are: [0]

==> Some builds didn't complete successfully and had errors:
--> googlecompute: Script exited with non-zero exit status: 100.Allowed exit codes are: [0]

==> Builds finished but no artifacts were created.

Do you have any clue to solve this? I try to put and sleep on .json and run with PACKER_LOG=1 but, I’don’t get enough information.


what is your ssh username, possibly you need to use sudo ???


if the message is real, then it could be that the unattended-upgrades is running as soon as the machine starts.

Hi shantanugadgil,

thank for your answer, I put and wait before launch the provisioning, I enter to the machine and I check that was the unattended-upgrades. I solved it putting enough wait time.


Cool. instead of a hard wait, you could also try a “while 1 … pgrep unattended …” Maybe?