I run the following command across all OpenVZ containers to update/upgrade:

vzctl exec2 $VM "apt-get update & apt-get upgrade"

In all cases, I get the following error:

dpkg-preconfigure: unable to re-open stdin: No such file or directory

And when there are updates available, the prompt "Do you want to continue" is skipped. Also, dpkg cannot set a lock:

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?

How can I fix this?


Try this:

vzctl enter $VM --exec "apt-get update && apt-get upgrade"

The && means "If the previous command completes successfully, continue to the next."

From http://wiki.openvz.org/Man/vzctl.8:

exec CTID command

Executes command in a container. Environment variables are not set inside the container. Signal handlers may differ from default settings. If command is -, commands are read from stdin.

exec2 CTID command

The same as exec, but return code is that of command.

On the other hand

enter CTID [--exec command [arg ...]]

Enters into a container (giving a container’s root shell).

Option --exec is used to run command with arguments after entering into container. This is useful if command to be run requires a terminal

  • Wow, now that was easy. Thanks! I added a "&& exit" to make it quit the VZ container to match the exec2 command.
    – mo.
    Sep 17 '13 at 23:35
  • Yes, the correct one is using "&&", sorry, it was a typo copied from the original question. Thanks for pointing out.
    – Javi
    Apr 10 '14 at 22:19

Do not use this idiom "apt-get update & apt-get upgrade" as the upgrade will proceed simultaneously with the update which will cause the update to lock the database and the upgrade will fail.

One of the following will be correct:

vzctl enter $VM --exec "apt-get update && apt-get -y upgrade" [note: edited Javix's answer above]


vzctl enter $VM --exec "apt-get update; apt-get -y upgrade"

In the first command, the upgrade will proceed only if the update was successful. In the second, it will be attempted anyway.

For each, I've also added a -y for the upgrade to answer "yes" to any questions, which is useful for unattended upgrades such as this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.