recovery from "rm -rf /var/lib/dpkg/info" ?

Kees Cook kees at
Thu Aug 23 18:52:08 UTC 2007

Hi Kristian,

On Wed, Aug 22, 2007 at 02:17:06PM -0400, Kristian Erik Hermansen wrote:
> On 8/22/07, Ben Collins <ben.collins at> wrote:
> > sudo apt-get --reinstall install `dpkg --get-selections | grep '[[:space:]]install' | cut -f1`
> >
> > This _might_ work. There is no silver bullet to fix your problem other
> > than file backups.
> I like your kung-fu, but how is this any different than...
> $ sudo aptitude reinstall ~i

Perhaps extracting the needed files directly from the .deb archives will
do the trick?  Try this insanity, with sudo.  I have no idea if it will
work, YMMV, etc etc, but I think this is generally what's needed to get
all your dpkg info files back in place....

set -e

# Clean out /var/cache/apt/archives
apt-get clean
# Fill it with all the .debs we need
apt-get --reinstall -dy install $(dpkg --get-selections | grep '[[:space:]]install' | cut -f1)

DIR=$(mktemp -d -t info-XXXXXX)
for deb in /var/cache/apt/archives/*.deb
	# Move to working directory
	cd "$DIR"
	# Create DEBIAN directory
	mkdir -p DEBIAN
	# Extract control files
	dpkg-deb -e "$deb"
	# Extract file list, fixing up the leading ./ and turning / into /.
	dpkg-deb -c "$deb" | awk '{print $NF}' | cut -c2- | sed -e 's/^\/$/\/./' > DEBIAN/list
	# Figure out binary package name
	DEB=$(basename "$deb" | cut -d_ -f1)
	# Copy each control file into place
	for file in *
		cp -a "$file" /var/lib/dpkg/info/"$DEB"."$file"
	# Clean up
	cd ..
	rm -rf DEBIAN
rmdir "$DIR"

Kees Cook
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <>

More information about the ubuntu-server mailing list