Skip to content

Instantly share code, notes, and snippets.

@Earnestly
Last active October 17, 2016 18:49
Show Gist options
  • Save Earnestly/33512034001ab666168b to your computer and use it in GitHub Desktop.
Save Earnestly/33512034001ab666168b to your computer and use it in GitHub Desktop.
Dealing with Installation Interruptions with Pacman

A Method to Correct Interrupted Installations with Pacman

An upgrade via pacman could be broken down into three phases:

1) Sync

Updates the sync databases with, if any, new packages. These are downloaded from the mirrors usually as gzip files located in /var/lib/pacman/sync such as core.db and extra.db.

2) Download

Deals with dependency resolution and downloads any new package tarballs to /var/cache/pacman/pkg by default.

3) Installation

Pacman now essentually untars the downloaded package tarballs over the / directory by default.

It also updates the database in /var/lib/pacman/local after each package is untarred to reflect the changed state of the filesystem.

Problems

If the first two phases fail it is usually enough to just start again using the same command-line used to invoke pacman.

If the installation phase fails due to interruptions, errors or power failure then recovery becomes a bit more complicated.

Essentially what has occured is a mismatch between what is contained in the real filesystem and what the /var/lib/pacman/local database knows.

Attempting to install packages again will often result in file conflicts as pacman wishes to extract files that already exist in the filesystem but without it knowing about their ownership.

Solution

First, try to avoid running -Syu (or -Sy) after the installation failure. This will only complicate matters as the /var/lib/pacman/sync databases will potentially now also be out of sync with /var/lib/pacman/local along with it being out of sync with the filesystem contents.

If you have not run -Syu since failure

Gather a list of all packages which are conflicting (or just issue the same command innvocation without -y), then pass them to pacman -S --dbonly <packages> to bring the database back into alignment with the filesystem. Then install the packages using pacman -S <packages> to bring the filesystem back into alignment with the database.

If you have run -Syu since failure

Again collect the conflicting packages but this time we'll use -U --dbonly to install them from the cache which is located at /var/cache/pacman/pkg by default. Once this is complete run the same command again without --dbonly to bring the filesystem back inline with the /var/lib/pacman/local database. E.g.:

  1. pacman -U --dbonly /var/cache/pacman/pkg/{package-1.tar.xz,package-2.tar.xz,package-3.tar.xz}
  2. pacman -U /var/cache/pacman/pkg/{package-1.tar.xz,package-2.tar.xz,package-3.tar.xz}

After this it would likely be a good idea to run pacman -Syu again to make sure everything is in sync once more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment