As promised, a safer version of the script to reorder the /var/lib/dpkg/info directory. If you experience problems with the new directory, just restore the saved backup directory.
Code:#!/bin/sh # Script to reorder the /var/lib/dpkg/info directory to speed up "dpkg -S". # # Original by Peter Cordes, from Ubuntu Forums thread # http://ubuntuforums.org/showthread.php?p=8982470 # # "Safer" modified version by gmargo 2009-03-17 # Original Code: # cd # strace -efile -o dpkg.tr dpkg -S /bin/ls # cd /var/lib/dpkg # mkdir info.new # grep '^open' ~/dpkg.tr | sed -r '/dpkg\/info/sX.*"(.*)".*X\1Xp' -n | xargs sudo cp -a -t info.new # # cmd line length limits prevent info/*. I could have used rsync -au info/ info.new # sudo cp -iau info/[a-k]* info.new/ # sudo cp -iau info/[l]* info.new/ # sudo cp -iau info/[m-z]* info.new/ # diff -ur info info.new/ # sudo rm -rf info # sudo mv info.new info # # sync # echo 3 | sudo tee /proc/sys/vm/drop_caches # time dpkg -S /bin/ls # Modified code: ORIGINAL=/var/lib/dpkg/info NEW=/var/lib/dpkg/info.new BACKUP=/var/lib/dpkg/info.saved.$(date "+%Y%m%d_%H%M%S") #------------------------------ # You must be root or use sudo. #------------------------------ if [ `id -u` -ne 0 ] ; then echo "ERROR: You must be root for this to work!" exit 1 fi if [ -e "$NEW" ]; then echo "Remove $NEW directory first." exit 1 fi mkdir "$NEW" rc=$? ; if [ $rc -ne 0 ] ; then echo "ERROR: mkdir $NEW failed rc=$rc" ; exit 2 ; fi chmod 755 "$NEW" echo "Optimize:" strace -efile -o /tmp/dpkg.tr.$$ dpkg -S /bin/ls >/dev/null grep '^open' /tmp/dpkg.tr.$$ | sed -r '/dpkg\/info/sX.*"(.*)".*X\1Xp' -n | xargs cp -p -t "$NEW" find /var/lib/dpkg/info -type f -print | xargs cp -pu -t "$NEW" rm -f /tmp/dpkg.tr.$$ #-------------------------------------------------- # Rename old info directory. # DO NOT DELETE UNTIL YOU ARE CONVINCED dpkg WORKS. #-------------------------------------------------- echo "Create backup:" if [ -e "$BACKUP" ]; then echo "Backup directory $BACKUP already exists." exit 1 fi mv "$ORIGINAL" "$BACKUP" rc=$? ; if [ $rc -ne 0 ] ; then echo "ERROR: mv $ORIGINAL $BACKUP failed rc=$rc" ; exit 2 ; fi mv "$NEW" "$ORIGINAL" rc=$? ; if [ $rc -ne 0 ] ; then echo "ERROR: mv $NEW $ORIGINAL failed rc=$rc" ; exit 2 ; fi echo "Test:" sync echo 3 > /proc/sys/vm/drop_caches time dpkg -S /bin/ls
Bookmarks