Sign up ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

If I had a running debian system, the following command could be issued to get list of installed packages:

dpkg --get-selections > packages.lst

But now I have only a full backup of root partition (complete system backup) of the working system and nothing more. How can I generate list of installed packages from these files?

share|improve this question
    
Only the root partition - not the complete system? Which directories are on this partition? –  Thomas Weinbrenner 11 hours ago
    
I meant "complete system backup", edited question accordingly. –  ceremcem 10 hours ago

3 Answers 3

up vote 6 down vote accepted

chroot into it, and run dpkg would be the easiest thing. See http://superuser.com/a/417004/20798 for how to get a working /proc, /sys, and /dev inside the chroot.

Since you have a working debian system outside the backup, you could probably just use

dpkg --admindir=dir --get-selections

The dir defaults to /var/lib/dpkg, so put the path to your backup's /var/lib/dpkg.


Don't forget that dpkg --get-selections doesn't show which packages were manually installed, and which were only installed to satisfy dependencies (and thus should be auto-removed when no longer needed because newer versions of the packages you actually want have different deps, or because you purge a manually installed package.)

I use aptitude, which makes it easy to mark everything as auto-installed, then go through and mark some packages as manually installed until nothing you want to keep is getting auto-removed. Start with big meta-packages, like build-essential, the Debian equivalents of ubuntu-standard and ubuntu-desktop, and stuff like that. In aptitude, hit r to see the reverse-depends of a package (pkgs that depend on it).

share|improve this answer
1  
You can use apt-mark or (far more convenient but not installed by default) apt-clone to clone a set of installed packages including the automatic/manual flag. –  Gilles 8 hours ago

Peter's approach is better but you could also just parse /var/lib/dpkg/status which doesn't require a chroot:

 $ perl -00ne 'if(/: install/){/Package:\s*(\S+)/ && print "$1\n"}' /var/lib/dpkg/status

On my machine, that returned the same list of packages as dpkg --get selections | awk '$NF=="install"{print $1}' (the awk is needed to make it show only installed packages).

share|improve this answer

You can have a listing using of you packages using :

awk '/Package:/ {print $2}' /var/lib/dpkg/status

share|improve this answer
    
That will not only show installed packages. –  terdon 10 hours ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.