I have my own application packaged using dpkg. The application depends on several .deb files which I'm trying to install from within the preinst script of my application. The preinst script checks if a dependent deb file is installed, if not it goes to install it using the dpkg -i command. This is repeated for all the dependent deb files needed by the main application.

When I try to install the main application using dpkg -i, the commands returns failure when trying to execute the preinst script. Below is that error message:

dpkg: error: dpkg status database is locked by another process

I deleted /var/lib/dpkg/lock file and retried to install the application. But to no avail. If I run the preinst script separately like any other shell script, it runs without any issue. All the deb files will be installed properly. So, the issue is only when this preinst script is being run automatically by the dpkg -i command.

I'm lost trying to determine the root cause. If anyone can shed some light on what the real issue might be, their help will be greatly appreciated.

Thank you, ObsessiveSS0F for your quick response.

I understand the point you are making but that will not help my situation. Let me tell you why.

  1. My main application (let's say mainapp.deb) depends on five other .deb files
    (let's say 1.deb, 2.deb and so on).
  2. The dependent .deb files are my own private packages/libraries. So these are not downloadable from the web. So, I cannot use apt-get to install these automatically.
  3. I would make the "Depends" field in the control file to point to 1.deb, 2.deb..etc, but as you know dpkg -i will not automatically install the dependencies.
  4. I can execute dpkg -i, followed by apt-get -f install, but for apt-get to work, I have to edit the /etc/apt/sources.list file to add a reference to the local directory on the system where the dependent .deb files are stored.
  5. Well, #4 seems to work but is not an option for me because this application will be installed on many servers and the installation program has to be fully automated.

I continued to investigate the reason why preinst was failing to install the .deb files and I think I have found out why.

  1. When I run dpkg -i mainapp.deb,the dpkg process is creating the /var/lib/dpkg/lock
    and some files under /var/lib/dkpg/updates directory.
  2. Now, the preinst script has a series of dpkg -i commands to install the dependent
    .deb files. So, as soon as the first dpkg -i command in the preinst script is executed, it fails because of the locks created by the earlier dpkg command.
  3. It seems that two dpkg commands cannot be executed in parallel because of the locks.

I modified the preinst script to backup the locks created by the dpkg process to a temporary location and deleted the original locks. (the lsof command did report that the locks were deleted). Now that the locks were gone, the dpkg -i commands within the preinst script executed without any issues. I restored the locks back before exiting the preinst script so that the primary dpkg -i command could continue. It worked but I have a feeling that this is not the right approach.

I'm still trying to figure out alternate ways for installing a .deb file along with it's dependencies.


2 Answers 2


It is not needed to use a preinst script to install .deb files. You can simply add dependencies and then package using an archive, and any dependencies and pre-depends will be automatically installed.


The thought of shuffling lock files makes me uncomfortable. If it's guaranteed not to mess with the application install then it doesn't seem like there should be a problem however I believe that the pre-install script is more for things like stopping services that will be affected by the installation.

It seems the root cause of the problem is that the pre-install script is being shelled from the dpkg operation after the lock file has been set. It seems likely that the correct way of doing it is to either separate the installation of the dependencies altogether, or to re-package the application so that it works with a local ppa and installs the dependencies correctly.

I am wondering if it might not be better to set up the dependencies with --set-selection and process them with dpkg either before or after installing the application. The dependencies can be loaded with:

sudo dpkg --set-selections < dependency_files

Where the dependency_files is in the format, for example:

samba                   install
samba-common            install
samba-common-bin        install
samba-ldb-tools         install
samba4                  install
samba4-common-bin       install

I believe the files can then be installed with

dpkg --selected-only

It might even be possible that your pre-install script can be used for the --set-selections part of the operation at least.

As for re-packaging, I can't be of any help there, but there seems to be a community of package maintainers the would be able to help:



You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .