Technical

How to fix a broken Ubuntu package installation

featured 2

Today I wanted to reinstall an openldap server for which I didn’t have credentials, but where I had root access. Some files were left after I removed the package, so I tried to remove them manually, but doing so I interfered with the apt cleanup process and I ended up with a broken openldap (package is called slapd) installation.

15:59:01-root@mercury:~$ apt-get install -f slapd
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
  slapd
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 0 B/1,317 kB of archives.
After this operation, 4,195 kB of additional disk space will be used.
Preconfiguring packages ...
Selecting previously unselected package slapd.
(Reading database ... 31643 files and directories currently installed.)
Preparing to unpack .../slapd_2.4.31-1+nmu2ubuntu8_amd64.deb ...
Unpacking slapd (2.4.31-1+nmu2ubuntu8) ...
Processing triggers for ureadahead (0.100.0-16) ...
Processing triggers for ufw (0.34~rc-0ubuntu2) ...
Processing triggers for man-db (2.6.7.1-1ubuntu1) ...
Setting up slapd (2.4.31-1+nmu2ubuntu8) ...
  Backing up /etc/ldap/slapd.d in /var/backups/slapd-2.4.31-1+nmu2ubuntu8... done.
 * Starting OpenLDAP slapd                                                                                                                                                                                                             [fail]
invoke-rc.d: initscript slapd, action "start" failed.
dpkg: error processing package slapd (--configure):
 subprocess installed post-installation script returned error exit status 1
Errors were encountered while processing:
 slapd
E: Sub-process /usr/bin/dpkg returned an error code (1)

The solution : manually uninstall the package

$ mv /var/lib/dpkg/info/PACKAGE.* /tmp/
$ dpkg --remove --force-remove-reinstreq PACKAGE
$ dpkg --purge PACKAGE

so, for me it was:

$ mv /var/lib/dpkg/info/slapd.* /tmp/
$ dpkg --remove --force-remove-reinstreq slapd
$ dpkg --purge slapd

and finally re-install slapd:

16:03:08-root@mercury:~$ sudo apt-get install slapd
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
  slapd
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 0 B/1,317 kB of archives.
After this operation, 4,195 kB of additional disk space will be used.
Preconfiguring packages ...
Selecting previously unselected package slapd.
(Reading database ... 31610 files and directories currently installed.)
Preparing to unpack .../slapd_2.4.31-1+nmu2ubuntu8_amd64.deb ...
Unpacking slapd (2.4.31-1+nmu2ubuntu8) ...
Processing triggers for ureadahead (0.100.0-16) ...
Processing triggers for ufw (0.34~rc-0ubuntu2) ...
Processing triggers for man-db (2.6.7.1-1ubuntu1) ...
Setting up slapd (2.4.31-1+nmu2ubuntu8) ...
  Creating initial configuration... done.
  Creating LDAP directory... done.
 * Starting OpenLDAP slapd                                                                                                                                                                                                             [ OK ]
Processing triggers for libc-bin (2.19-0ubuntu6.3) ...

via Développeur PHP/Zend/Typo3 – Administrateur Linux | PIPRIME.FR : Manually remove a broken package on Debian/Ubuntu.