How To Restore Pacman's Local Database
From ArchWiki
| i18n |
|---|
| English |
| 简体中文 |
| Español |
Contents |
How To Restore Pacman's Local Database
Introduction
Something is wrong with pacman. 'pacman -Q' gives absolutely no results, and 'pacman -Syu' tells you that your system is up to date, but you know it is not. When you try to install a package using 'pacman -S package', you are presented with a list of dependencies, even though you know that they are already installed.
Your problem is that pacman's database of installed software '/var/lib/pacman/local' has been corrupted or deleted. This is a serious problem, but fortunately you can restore '/var/lib/pacman/local' by following the instructions below.
Disclaimer
Before you begin, I want to stress that although these instructions worked for me, they may not work for you. In fact, your system might never be the same again.
PROCEED AT YOUR OWN RISK!
Command line
The line below indicates a command typed in a terminal by a non-root user:
$ ls
The line below indicates a command typed in a terminal by user 'root', that is, the user with full rights on your system:
# ls
Most of the instructions below assume that you have root access to your system.
Instructions
- Firstly, you have to make sure you have pacman's log file.
$ ls /var/log/pacman.log
If your pacman log file does not exist, you can not continue. The only option you have is to re-install your system from scratch.
Okay, your /var/log/pacman.log file exists. This is what you do:
- Create the pkglist.sh file (this is one long multi-line command - just copy/paste it all):
# cat <<END > pkglist.sh
awk '
$3 == "installed" || $3 == "upgraded" { pkg[$4] = 1 }
$3 == "removed" { pkg[$4] = 0 }
END { for (i in pkg) if ( pkg[i] == 1 ) print i; }
' /var/log/pacman.log
END
Thanks to 'rdt' http://bbs.archlinux.org/viewtopic.php?id=38531 for the idea
# chmod 744 pkglist.sh
- Now you run pklglist.sh and pipe the output to pkglist.
# ./pkglist.sh > pkglist
- pkglist now contains a list of all the software you installed or upgraded. Edit pkglist and remove anything that you do not want to re-install. You might want to do this if you made a custom package and installed it with 'abs' for example.
# vi pkglist
- Once you are satisfied with the contents of pkglist, you can use it to re-install your software, and restore '/var/lib/pacman/local'.
There is no need to check for dependencies, and you have to 'force' the install because the programs already exist:
# pacman -Sdf $(cat pkglist)
Pacman will now present you with a long list of software to be installed. Say 'yes' and wait for pacman to finish.
- Finally, you need to find all the configuration files that have changed. You can do this by first updating the 'locate' database:
# updatedb
- Then you can search for all the configuration files that have changed:
# locate pacorig
This will give you a list of all the configuration files that have been replaced. Your original file will have .pacorig appended to it. Delete the new files, and rename the .pacorig files to restore your original configuration for each software package that may be affected. Some directory permissions may also have been changed. Check this if something refuses to start.
Congratulations, you have successfully restored your pacman local database.