Vagrant: dpkg lock fails on ubuntu 16.04

Created on 22 Jun 2016  ยท  8Comments  ยท  Source: hashicorp/vagrant

Vagrant version

Vagrant 1.8.4

VirtualBox version

VirtualBox 5.0.22

Host operating system

Windows 8.1

Guest operating system

Ubuntu 16.04 (bento/ubuntu-16.04)

Vagrantfile

$script = <<-SCRIPT
sudo apt-get install -y ruby
gem install puppet -v 4.5
SCRIPT
Vagrant.configure(2) do |config|
  config.vm.box = 'bento/ubuntu-16.04'
  config.vm.provision :shell, inline: $script
end

Debug output

# vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: vagrant-r10k not configured; skipping
==> default: Importing base box 'bento/ubuntu-16.04'...
==> default: Matching MAC address for NAT networking...
==> default: Checking if box 'bento/ubuntu-16.04' is up to date...
==> default: Setting the name of the VM: vagranttest_default_1466630414878_11805
==> default: vagrant-r10k not configured; skipping
==> default: vagrant-r10k not configured; skipping
==> default: Fixed port collision for 22 => 2222. Now on port 2200.
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
==> default: Forwarding ports...
    default: 22 (guest) => 2200 (host) (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2200
    default: SSH username: vagrant
    default: SSH auth method: private key
    default:
    default: Vagrant insecure key detected. Vagrant will automatically replace
    default: this with a newly generated keypair for better security.
    default:
    default: Inserting generated public key within guest...
    default: Removing insecure key from the guest if it's present...
    default: Key inserted! Disconnecting and reconnecting using new SSH key...
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
==> default: Mounting shared folders...
    default: /vagrant => C:/Users/Ma27/PhpstormProjects/vagranttest
==> default: Running provisioner: shell...
    default: Running: inline script
==> default: mesg:
==> default: ttyname failed
==> default: :
==> default: Inappropriate ioctl for device
==> default: E
==> default: :
==> default: Could not get lock /var/lib/dpkg/lock - open (11: Resource temporarily unavailable)
==> default: E
==> default: :
==> default: Unable to lock the administration directory (/var/lib/dpkg/), is another process using it?
==> default: /tmp/vagrant-shell: line 2: gem: command not found
The SSH command responded with a non-zero exit status. Vagrant
assumes that this means the command failed. The output for this command
should be in the log above. Please read the output to determine what
went wrong.

Expected behavior

the provisioner should install ruby and puppet.

Actual behavior

As you can see, during the shell provisioner fails due to a failed lock and as ruby is not installed due to this, the gem command can't be found.

Steps to reproduce

  1. use this vagrantfile with the given data
  2. run vagrant up

    References

  • #7155
  • #6871
  • #6616

Most helpful comment

Here is a fix for the ioctl error:

  config.vm.provision "fix-no-tty", type: "shell" do |s|
    s.privileged = true
    s.inline = "sed -i '/tty/!s/mesg n/tty -s \\&\\& mesg n \\|\\| true/' /root/.profile"
  end

and here is a fix for the apt lock error:

config.vm.provision "disable-apt-periodic-updates", type: "shell" do |s|
    s.privileged = true
    s.inline = "echo 'APT::Periodic::Enable \"0\";' > /etc/apt/apt.conf.d/02periodic"
  end

I'm using bento/debian images, but I'm sure it'll be the same for Ubuntu.
Run these two provision items before anything else.

All 8 comments

a last note: someone recommended to do an apt-get update before the apt-get install {pkg} command, but this causes the same issues.

Hi there,

There is a bento issue for this (https://github.com/chef/bento/issues/609). It should be fixed soon.

thanks for the link @sethvargo .

But I don't think that the Inappropriate ioctl for device message is caused by this, right?
It appears during puppet provisionings, too (before facter execution, so no apt stuff is done at this time)

That's a warning, not an error

Had the same issue the other day. After a restart all worked fine...

Here is a fix for the ioctl error:

  config.vm.provision "fix-no-tty", type: "shell" do |s|
    s.privileged = true
    s.inline = "sed -i '/tty/!s/mesg n/tty -s \\&\\& mesg n \\|\\| true/' /root/.profile"
  end

and here is a fix for the apt lock error:

config.vm.provision "disable-apt-periodic-updates", type: "shell" do |s|
    s.privileged = true
    s.inline = "echo 'APT::Periodic::Enable \"0\";' > /etc/apt/apt.conf.d/02periodic"
  end

I'm using bento/debian images, but I'm sure it'll be the same for Ubuntu.
Run these two provision items before anything else.

Why was this issue closed? You don't mentioned if it was fixed in some vagrant version, it's not mentioned in https://github.com/chef/bento/issues/609 either... @sethvargo

The expected vagrant workflow can't be (based on Richard's answer above):

# place his fix before mounting in the Vagrantfile
vagrant up --provision

The above doesn't help either because it always tries to mount first..

?? I have the same issue on MacOs Catalina using vagrant v.2.2.2 & Virtualbox 6.0.2 - this was the only versions I could get my vagrant box to work at all after updating MacOs from High Sierra. Don't know if I could update vagrant and if it's only Virtualbox that causes issues and where I need exactly 6.0.2. Everything was working fine at first when I picked these but after a reboot of my Mac (without terminating vagrant first) I have had these issues.

    ==> default: Mounting NFS shared folders...
^C/opt/vagrant/embedded/gems/2.2.2/gems/concurrent-ruby-1.1.3/lib/concurrent/collection/map/mri_map_backend.rb:18:in `synchronize': can't be called from trap context (ThreadError)

I'm going to lock this issue because it has been closed for _30 days_ โณ. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

barkingfoodog picture barkingfoodog  ยท  3Comments

StefanScherer picture StefanScherer  ยท  3Comments

OtezVikentiy picture OtezVikentiy  ยท  3Comments

tomhking picture tomhking  ยท  3Comments

janw-me picture janw-me  ยท  3Comments