How NOT to switch from x86 to amd64 Debian

The following script, or any script like it will not work. Do not waste your time and end up hosing your box like I did today:

#!/bin/bash

echo "==> installing cdebootstrap"
apt-get install cdebootstrap

echo "==> reticulating splines"
dpkg -l | cut -f3 -d' ' >> /tmp/packages.installed
pkg=`cat /tmp/packages.installed | xargs`
pkg=`echo $pkg | sed -e 's#bunch of crap elided here##g'`

echo "==> installing libc6-amd64"
apt-get install libc6-amd64

echo "==> installing base system"
cdebootstrap -a amd64 lenny /

for pkg in $pkg; do
echo "==> reinstalling $pkg"
apt-get install --reinstall --force-yes $pkg
done

Don’t let this happen to you. I had the pleasure of discovering that Bacula was not properly backing up my MySQL databases. What an excellent way of finding out.