Fixing APT Corruption

Wed 15 November 2006 by pj Tagged as ancient debian
A debian machine at work had some RAM go bad... in service. Which ended up corrupting something in /var/cache/apt, (I think pkgcache.bin). Which caused apt-get to segfault repeatedly. I had traces like
gettimeofday({1163625872, 123448}, NULL) = 0
gettimeofday({1163625872, 123572}, NULL) = 0
--- SIGSEGV (Segmentation fault) @ 0 (0) ---
+++ killed by SIGSEGV +++
and gdb traces like:
Reading Package Lists... Done
Building Dependency Tree... 50%
Program received signal SIGSEGV, Segmentation fault.
0xb7ec84d7 in pkgDepCache::CheckDep ()
   from /usr/lib/libapt-pkg-libc6.3-5.so.3.3
(gdb) bt
#0  0xb7ec84d7 in pkgDepCache::CheckDep ()
   from /usr/lib/libapt-pkg-libc6.3-5.so.3.3
#1  0xb7ec918c in pkgDepCache::DependencyState ()
   from /usr/lib/libapt-pkg-libc6.3-5.so.3.3
#2  0xb7ec95c7 in pkgDepCache::Update ()
   from /usr/lib/libapt-pkg-libc6.3-5.so.3.3
#3  0xb7ec825f in pkgDepCache::Init ()
   from /usr/lib/libapt-pkg-libc6.3-5.so.3.3
#4  0xb7eea054 in pkgCacheFile::Open ()
   from /usr/lib/libapt-pkg-libc6.3-5.so.3.3
#5  0x0805e277 in std::vector >::_M_insert_aux ()
#6  0x08055069 in ?? ()
#7  0xb7ebcf3c in CommandLine::DispatchArg ()
   from /usr/lib/libapt-pkg-libc6.3-5.so.3.3
#8  0x0805d706 in ?? ()
#9  0xb7c8f974 in __libc_start_main () from /lib/tls/libc.so.6
#10 0x0804c5b1 in ?? ()
so if you run into this, just:
mv /var/cache/apt/ /var/cache/apt-
mkdir -p /var/cache/apt/archives/partial
and then 'apt-get update' and things will be fixed.