You are not logged in.

#1 2020-02-05 16:36:21

Registered: 2018-07-16
Posts: 2

Lost pacman, checking its dependencies

I wrote this post just in case the same thing happens to you; my own experience of using Arch suggests that you would be very unlucky if it did ever happen to you.

I had a curious pacman crash. I was doing a normal pacman -Syu but the whole run crashed near the end of upgrading several hundred packages, and in particular it seemed to be upgrading pacman itself when it happened. But I could not resume the run or check for package consistency because pacman itself was now missing.

I tried rebooting, but discovered that vmlinuz-linux and the initramfs files were missing from the boot directory (as was linux.conf, since I use rEFInd). So I booted up a recent installation
DVD and after mounting the relevant partitions and doing arch-chroot /mnt, I tried running mkinitcpio, only to find that I could not because /etc/mkinitcpio.d/linux.preset was also missing.

I am unsure why the crash happened at all: I ran fsck -f on the relevant unmounted partitions but they were all clean; my disk is an SSD but the partitions were nowhere near full. I have been using Arch for years, and have been updating regularly without problems. I don't have any obvious explanation, but I do still trust pacman: it's an outstandingly good piece of work!

Advice on the web suggested that one could re-install pacman without using pacman, by first checking all its dependencies and then using tar with suitable arguments -- see the sticky posting at the top of the 'Pacman and Package Upgrade Issues' section of the Arch forums. Fortunately I have a laptop that also runs Arch and which I had very recently updated, so I could generate a list of pacman's dependencies: ninety of them! So I created the following small perl script to check all these dependencies, after transferring a list of them to my broken system via USB stick:

#!/bin/perl -w
# This reads a file of pkgfiles, each in full-pathname form,
# and for each one, checks that the files in the pkg file exist
# and have the right size -- only a BASIC check. Useful only
# if you have lost pacman. Pkg names typically end with .xz or .zst

use strict;

my $infile = shift or die("need a file that lists pkgs to check\n");
my ( $pkgfile, $fh, $fg, $filename, $pkgsize );
my @fields;
my $realsize;

open($fg, "<", $infile) or die("could not read $infile\n");
while( <$fg> ) {
  next if /^\s*$/; # skip empty/whitespace lines
  $pkgfile = $_;
  printf("==== checking %s\n", $pkgfile);
  open($fh, "-|", "tar -tvf $pkgfile --exclude .BUILDINFO --exclude .MTREE --exclude .PKGINFO --exclude .INSTALL --exclude .Changelog")
     or die("quitting: cannot run tar on $pkgfile\n"); 
  while( <$fh> ) {
    @fields = split;
    $tarsize = $fields[2]; # tar -v: third field is the size
    next if $#fields > 5;  # probably symbolic link: ignore it
    next if /\/$/;         # a directory: ignore it
    $filename = "/$fields[5]"; # put a / in front of the name
    if( ! -e $filename) {
      printf(" .... does not exist: %s\n", $filename);
    $realsize = (stat($filename))[7];
    if($pkgsize != $realsize) {
      printf(" size mismatch: pkg has %d, filesystem has %d for %s\n", $pkgsize, $realsize, $filename);

It turned out that most of the files in the pacman package were missing, and otherwise the only dependency files with unexpected sizes were ones that you might expect, such as /etc/passwd. However, it was disturbing that essential boot files had also gone missing, so rather than check everything on my system I opted to do a full re-install: fortunately, besides a backup I also had /home on a separate partition. It took some time but I'm now back iup and running.


#2 2020-02-05 16:50:54

Forum Moderator
Registered: 2012-10-16
Posts: 8,713

Re: Lost pacman, checking its dependencies

Let me guess, you symlinked your /var/cache/pacman directory? Don't do that, that directory is a part of the pacman package. If you replace this with a symlink, pacman will replace that symlink with the directory it knows about, by consequence your cache directory is empty and it won't find files to continue with anymore.


Board footer

Powered by FluxBB