How To Restore Pacman's Local Database
From ArchWiki
| i18n |
|---|
| English |
| 简体中文 |
| Español |
Contents |
[edit] How To Restore Pacman's Local Database
[edit] 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.
[edit] 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!
[edit] Command line
The line below indicates a command typed in a terminal by user 'me', that is, any non-root user.
[me@linuxbox]$ ls
The line below indicates a command typed in a terminal by user 'root', that is, the user with full rights on your system.
[root@linuxbox]# ls
Most of the instructions below assume that you have root access to your system.
[edit] Instructions
- Firstly, you have to make sure you have pacman's log file.
[me@linuxbox]$ ls /var/log/pacman.log /var/log/pacman.log
If your pacman log file does not exist, you need 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.
[root@linuxbox]# touch pkglist.sh
- Copy and paste the following lines into your 'pkglist.sh' file.
#!/bin/bash
#
SEDEXP='s/^\[[^ ]* *[0-9][0-9]:[0-9][0-9]\] \([^ ]*\) *\([^ ]*\) .*/\1 \2/'
GRPEXP='(upgraded)|(installed)'
AWKEXP='{print $2}'
#
sed -e "$SEDEXP" /var/log/pacman.log | grep -E "$GRPEXP" | awk "$AWKEXP" | sort -u
# End
Thanks to 'rdt' http://bbs.archlinux.org/viewtopic.php?id=38531
save and exit.
- Make 'pkglist.sh' executable.
[root@linuxbox]# chmod 744 pkglist.sh
- Now you run 'pklglist.sh' and pipe the output to 'pkglist'.
[root@linuxbox]# ./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.
[root@linuxbox]# 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.
[root@linuxbox]# 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.
[root@linuxbox]# updatedb
- Then you can search for all the configuration files that have changed.
[root@linuxbox]# 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.
Ian K Armstrong
The Island of Bornholm, Denmark.
ika@{REMOVE_THIS}openmail.cc