Packages installed on a Debian/Devuan machine

Finding out which packages are installed on a machine which is currently running is easy. Any of the following commands will tell you:

# dpkg-query -l
# apt list --installed
# aptitude search ~i

Sometimes, however, you have a (pretty complete, I hope) backup of a machine which is no longer running, and you want to find out which packages were installed on it, but it's not a simple matter (or you just don't want to bother) to restore the backup somewhere and restart it.

To find out what was installed without having the machine running, try any of the following:

# cat /pathtobackup/var/lib/dpkg/status
# dpkg --admindir=/pathtobackup/var/lib/dpkg --get-selections "<pattern>"
# dpkg-query --admindir=/pathtobackup/var/lib/dpkg -l

Thanks to my friends at the Devuan mailing list for pointing me in the right direction with this.

If your idea of a backup is simply the user data and none of the system files, then sorry, the above is simply not possible. I recommend you compare the disk space occupied by your system files, and the space occupied by the user files you're backing up, and then decide to back up everything, and rest easy that nothing is now lost to oblivion. I can't remember the last time I saw a machine whose system files took up more space than the user data (unless you include things which get installed by ansible, puppet or similar, and are essentially stateless clones, which need no backups, since they're just replaceable stateless clones).

Packages which were manually installed

It's often helpful to know which packages were installed by the user, rather than being standard system packages, or dependencies for other things (which may in turn have been installed automatically, or by the user).

Here's my best attempt so far at finding out what the user has manually installed:

aptitude search ~i | grep "^i.[^A]" | awk '{ print $2 }' | while read target
do
  [ "`apt-cache rdepends --installed $target | wc -l`" = "2" ] && echo "$target"
done

The above is inspired by something similar but which doesn't exclude the automatically-installed packages.


Go up
Return to main index.