You are here

Migrate/Upgrade Debian 7 Wheezy GNU/Linux from 32 bit to 64 bit HowTo

1. Introduction

This HowTo converts a working 32 bit installation into a 64 bit system. You keep all programs, settings and data. You start with a 32 bit system that can run 64 bit programs, and finish with a 64 bit system that can run 32 bit programs. We firstly demonstrate an upgrade from 6.0 Squeeze 32 bit to 7 Wheezy because Debian 7 is a pre-requisite.

With the recent release of Debian GNU/Linux 7.0 Wheezy, a new feature called multiarch has been introduced. The facility permits the installation of executable files (such as libraries and programs) from multiple architectures simultaneously on the same system. The primary use of this is to allow 32 bit programs to be run on a 64 bit system, but there are more interesting possibilities. We can turn this on its head, allowing 64 bit programs to run on a 32 bit system, then ultimately replace all 32 bit programs with their 64 bit equivalents. No other operating system can provide this flexible feature.

Read this guide through in its entirety before starting, and keep plenty of tested backups to hand. Run these steps in an ssh session or on the console.

Updated 2013-09-30: This HowTo has been significantly simplified and no longer unpacks packages manually.

2. Debian 6.0 32 bit installation

Download the ISO file image, burn it to CD, then start the installation.

wget http://cdimage.debian.org/debian-cd/6.0.7-live/i386/iso-hybrid/debian-live-6.0.7-i386-standard.iso

Install some extra packages as you see fit, e.g. openssh-server and gnome-desktop-environment. I have performed the installation on a spare machine with 6G of RAM and a 10G disk. I utilised LVM and used the whole hard disk for Debian.

3. Debian 7 32 bit upgrade

Now upgrade from Squeeze to Wheezy as we need to have the new Debian 7 release in order to change the architecture (i.e. change from 32 bit to 64 bit later on).

sed -i -e"s/squeeze/wheezy/g" /etc/apt/sources.list
apt-get update
apt-get dist-upgrade

Now reboot to pick up the latest Linux kernel.

Now purge old uninstalled but configured packages from Debian 6.0, e.g.

aptitude
l~c [return]
_gg

Finally move down to Obsolete and Locally Created Packages and again do something like _g_g to purge them. Perform this step multiple times if necessary.

4. Backups

Backup everything before starting this process. Run tests to ensure that you can recover your backups successfully. There are some packages whose data will not function under the different architecture. One example is the controlfile format for PostgreSQL. Therefore we would need to create an architecture-independent backup that can be restored after the migration.

5. Boot into a 64 bit kernel

The 32 bit kernel does not allow the execution of 64 bit programs. However the 64 bit kernel allows the execution of both 32 bit and 64 bit programs, so this kernel is the first thing needed. Run the following in turn to allow 64 bit programs to be installed as an additional architecture, then install the 64 bit kernel. We will also install debootstrap as we will use it later.

dpkg --add-architecture amd64
apt-get update
apt-get install linux-image-amd64:amd64 debootstrap

Now reboot with the newly installed 64 bit amd64 kernel before continuing. You will probably wish to purge all the old 32 bit i386 kernels at this point. This will also ensure that the 64 bit kernel will be chosen automatically at each boot.

6. Pre-prepare files

Save a checkpoint of the packages we have installed at the start. The aim is to have the same packages installed at the end, just in the 64 bit architecture.

dpkg --get-selections "*:i386"|grep -v deinstall >dpkg-get-selections.cp.00.i386
dpkg --get-selections "*:amd64"|grep -v deinstall >dpkg-get-selections.cp.00.amd64
dpkg --get-selections "*:all"|grep -v deinstall >dpkg-get-selections.cp.00.all

Create a list of, and download, the packages for the base system. We can get away with including ssh in the base system, but most additional packages will break the migration process.

mkdir -p bootstrap-i386
rm -Rf bootstrap-i386/*
debootstrap --arch=i386 --download-only --include=openssh-client,openssh-server wheezy ./bootstrap-i386

mkdir -p bootstrap-amd64
rm -Rf bootstrap-amd64/*
debootstrap --arch=amd64 --download-only --include=openssh-client,openssh-server wheezy ./bootstrap-amd64

ls -1 bootstrap-amd64/var/cache/apt/archives/|egrep "\.deb$"|cut -d "_" -f1|awk '{print $1 " install"}' >dpkg-get-selections.base

7. Strip to 32 bit base system

Strip down the current selection of installed packages on the current 32 bit system to the base system of essential packages only. Do not abort the kernel removal when prompted, but note that the system will not be bootable until this is re-installed later with any required LVM tools, etc.

dpkg --clear-selections
cat dpkg-get-selections.base | dpkg --set-selections
apt-get dselect-upgrade

Downgrade the 32 bit base system to the base release (i.e. no updates or security patches). This step is needed because dpkg in Wheezy cannot cross-grade different versions of a package, and debootstrap does not include updates.

dpkg -i bootstrap-i386/var/cache/apt/archives/*.deb

8. Upgrade base system to 64 bit

Note you may skip the explicit cross-grade of dpkg and apt if you desire. Even if skipped, these packages will be cross-graded later (eventually).

Firstly prepare the files to cross-grade apt, but do not install.

mkdir -p archives-apt/partial
rm -f archives-apt/*.deb
apt-get install -d -y -o Dir::Cache::Archives=./archives-apt apt:amd64

Cross-grade dpkg from 32 bit to 64 bit first.

mkdir -p archives-dpkg/partial
rm -f archives-dpkg/*.deb
apt-get install -d -y -o Dir::Cache::Archives=./archives-dpkg dpkg:amd64
mv -i archives-dpkg/dpkg_*.deb .
dpkg -i archives-dpkg/*.deb
dpkg -i dpkg_*.deb
mv -i dpkg_*.deb archives-dpkg

Now complete the cross-grade of apt.

dpkg -i archives-apt/*.deb

Clear the package cache (to de-select 32 bit packages) and install the remaining base packages. Execute dpkg -i multiple times until no errors are encountered. This is a trade-off as it is simpler to re-run dpkg until all package dependencies succeed, rather than pre-calculate all the dependencies.

dpkg --clear-selections
dpkg --abort-after=1000 -i bootstrap-amd64/var/cache/apt/archives/*.deb
dpkg --abort-after=1000 -i bootstrap-amd64/var/cache/apt/archives/*.deb
dpkg --abort-after=1000 -i bootstrap-amd64/var/cache/apt/archives/*.deb

Save another checkpoint to document the state of the architecture migration.

dpkg --get-selections "*:i386"|grep -v deinstall >dpkg-get-selections.cp.01.i386
dpkg --get-selections "*:amd64"|grep -v deinstall >dpkg-get-selections.cp.01.amd64
dpkg --get-selections "*:all"|grep -v deinstall >dpkg-get-selections.cp.01.all

The base system is now running on the 64 bit architecture, so now we can clean up. The dselect-upgrade will remove the 32 bit base system and apply updates and security patches to the 64 bit base system.

apt-get autoremove
apt-get dselect-upgrade

Now we can finally re-install our kernel. After this we can take a breath as it will again be safe to reboot.

apt-get install locales linux-image-amd64 lvm2 grub-pc

Take another look at the packages we have installed. There should not be any i386 architecture packages installed at this point. The base system now comprises entirely amd64 and all packages. If any i386 packages remain at this point, go back over the previous steps, or remove them using dpkg, until they are all gone.

dpkg --get-selections "*:i386"|grep -v deinstall >dpkg-get-selections.cp.02.i386
dpkg --get-selections "*:amd64"|grep -v deinstall >dpkg-get-selections.cp.02.amd64
dpkg --get-selections "*:all"|grep -v deinstall >dpkg-get-selections.cp.02.all

9. Re-install packages

Now that the base system has been migrated to 64 bit, we can begin the process of re-installing the packages that were previously installed as 32 bit software. It may be necessary to run the installs and configures multiple times until all dependencies are met. Start with the most important software and any standard meta-packages.

I use the Gnome desktop environment, so I will pre-install those packages now. But first, manually purge some libraries that have their files in non-architecture-independent places. It is better to purge their 32 bit installation configurations rather than use --force-overwrite as this would only be a temporary work-around. If the install fails there may be other packages that need to be purged in a similar fashion using dpkg --purge pkgname:i386. If so, and once purged, re-install the conflicting package(s) using dpkg -i /var/cache/apt/archives/pkgname_*.deb and finish with dpkg --configure -a.

dpkg --purge libldap-2.4-2:i386 libpython2.7-minimal:i386 libpulse0:i386 libpython3.3-minimal:i386 libnl-3-200:i386 libatk-wrapper-java-jni:i386 libmagic1:i386 libgl1-mesa-dri:i386 libsane:i386 libxvmc1:i386 openjdk-7-jre-headless:i386 libsane-extras:i386 openjdk-6-jre-headless:i386 libpam-cap:i386 freeglut3:i386
apt-get install gnome-desktop-environment
dpkg --configure -a

Now we are ready to install all the software packages that were previously installed. Install dselect and use aptitude to bulk purge all the configuration files for the i386 libraries.

apt-get install dselect
dselect update

aptitude keep-all
aptitude forget-new
aptitude
l~clib
_gg

Now quit aptitude. Our --set-selections will now be successful once all remaining conflicting i386 packages have been purged.

cat dpkg-get-selections.cp.00.all|grep -v deinstall >dpkg-get-selections.final
cat dpkg-get-selections.cp.00.i386|grep -v ":i386"|grep -v deinstall|cut -f1|awk '{print $1 " install"}' >>dpkg-get-selections.final
cat dpkg-get-selections.cp.00.i386|grep ":i386"|grep -v deinstall|cut -d: -f1|awk '{print $1 " install"}' >>dpkg-get-selections.final
cat dpkg-get-selections.cp.00.amd64|grep ^linux-image|grep -v deinstall|cut -d: -f1|awk '{print $1 " install"}' >>dpkg-get-selections.final

dpkg --clear-selections
dpkg --remove-architecture i386
dselect update
cat dpkg-get-selections.final|dpkg --set-selections

Let's proceed. Be prepared to purge some 32 bit package configurations that still clash with the 64 bit package files.

apt-get dselect-upgrade
apt-get install `dpkg --get-selections "*:i386"|grep -v deinstall|cut -f1|cut -d: -f1|sed ':a;N;$!ba;s/\n/ /g'`
apt-get install `dpkg --get-selections "*:all"|grep -v deinstall|cut -f1|cut -d: -f1|sed ':a;N;$!ba;s/\n/ /g'`
apt-get install `dpkg --get-selections "*:amd64"|grep -v deinstall|cut -f1|cut -d: -f1|sed ':a;N;$!ba;s/\n/ /g'`

aptitude keep-all
/etc/init.d/gdm3 restart

10. Restore backups

Restore any backups that you took for data affected by the architecture migration, e.g. for PostgreSQL.

11. Allow 32 bit packages (optional)

We can now re-enable the installation of 32 bit packages. In other words we have a multiarch system that runs 64 bit but allows the installation of 32 bit programs and libraries.

dpkg --add-architecture i386
apt-get update

Take one final look at which packages are now installed.

dpkg --get-selections "*:i386"|grep -v deinstall >dpkg-get-selections.cp.03.i386
dpkg --get-selections "*:amd64"|grep -v deinstall >dpkg-get-selections.cp.03.amd64
dpkg --get-selections "*:all"|grep -v deinstall >dpkg-get-selections.cp.03.all
sdiff -s dpkg-get-selections.cp.00.i386 dpkg-get-selections.cp.03.amd64

12. Re-install 32 bit-only programs (optional)

Re-install any packages that are 32 bit only, for example:

apt-get install googleearth

See also

Classifications: 

Comments

Excellent work! Followed step by step. It worked great!

Hi Johannes,

I don't have a problem with that. Could you retain the link to my page from the wiki?

Kind regards,
Ewan.

After I added the link to the Debian Wiki, someone else wrote: "note that the guide on that link also performs dangerous and unnecessary steps, like unpacking raw .deb packages because it removes essential packages, instead of simply letting dpkg cross-grade them." which sounds link the process could be simplified even further. What is your take on that?

I agree. My original method was to use apt (higher level) where possible, then fall back to dpkg (lower level) when necessary. I have reversed that. I have already updated this page accordingly. DEB files are no longer unpacked but cross-graded from i386 to amd64. This removed quite a few awkward steps. There is a limitation (currently) in that dpkg cannot cross-grade and up/downgrade at the same time. The cross-graded package must be the same version in both architectures. There is an additional step to ensure this limitation does not cause the base system cross-grade to fail.

Did it after your last changes. 2,5h (most time waiting) to change jessie (not wheezy) from i386 to amd64 and no need to reinstall the machine. Thanks.

Worked perfect! Thank you very much, I even learned something about how the package management works! Two thumbs up!

First: big hug for your script, works perfect!

Relating to the subject, I had problems on a (soft)-raid1 within step 8.:
"Now we can finally re-install our kernel. After this we can take a breath as it will again be safe to reboot.
apt-get install locales linux-image-amd64 lvm2 grub-pc "

Installing grub-pc leaves the system unbootable.
see -> http://bugs.debian.org/cgi-bin/bugreport.cgi?archive=no&bug=707831

Because of this bug I installed grub-legacy as a temporary solution and it works.

Thanks again.

Sorry, I just read my comment and there is an important hint missing (thankx for correct it)

Because of this bug [change] I removed/purged at the very end(!) of your script grub-pc and [change end] installed grub-legacy as a temporary solution and it works.

Thanks again.

grub-pc on wheezy 64bit raid/lvm leaves system unbootable