Skip to main content

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

unalias ls
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

Johannes (not verified) Mon, 16/09/2013 - 11:34

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

Ewan Mon, 16/09/2013 - 15:09

In reply to by Johannes (not verified)

Hi Johannes,

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

Kind regards,
Ewan.

Johannes (not verified) Tue, 01/10/2013 - 19:19

In reply to by 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?

Ewan Tue, 01/10/2013 - 20:29

In reply to by Johannes (not verified)

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.

Holger (not verified) Sat, 25/01/2014 - 18:46

In reply to by Ewan

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.

Imagiro (not verified) Sat, 22/03/2014 - 18:03

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

Olaf (not verified) Tue, 01/04/2014 - 09:23

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.

Anonymous (not verified) Tue, 01/04/2014 - 10:37

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

THANKS a bunch. Just got 3 wheezy iSCSI servers from 32 to 64 using your instructions (due to brain malfunctioning I had mistakenly set them up with 32bits).
Here are some minor extra steps I needed to make it work on my systems:
1 - after multiple "dpkg --abort-after=1000 -i bootstrap-amd64/var/cache/apt/archives/*.deb " I was still left with some errors which wouldn't go away. I had to:
dpkg -P libapt-pkg4.12:i386 libapt-inst1.5:i386
then one more
dpkg --abort-after=1000 -i bootstrap-amd64/var/cache/apt/archives/*.deb
to clear all errors.

2 - my resulting "dpkg-get-selections.final" still had three "686" packages, libc6, and 2 related to linux-image (although I had purged them before), which resulted in errors later, so I manually removed them from dpkg-get-selections.final after the
cat dpkg-get-selections.cp.00.amd64|grep ^linux-image|grep -v deinstall|cut -d: -f1|awk '{print $1 " install"}' >>dpkg-get-selections.final

All the rest was like magic.

Thanks again.
Joao

Daniel Lundqvist (not verified) Tue, 29/07/2014 - 16:27

I just followed your instructions to upgrade an old server I had, worked great! Thanks for the detailed guide!

Ben (not verified) Tue, 06/01/2015 - 21:41

My desktop was originally installed as Woody circa 2003 and has been upgraded through each new Debian release (on multiple generations of hardware) to Wheezy. 

Over this time it has accumulated a serious crapload of installed packages, and no small amount of cruft.  I followed this howto carefully, checking the output at each command and the contents of generated text files, and dealing with issues as they arose  (there were not many).

The only modification I made to these steps was to uninstall software that was not originally installed from a deb package (ie VMware Workstation) before beginning, and reinstalling it after the 64 bit migration.

Thanks for the excellent howto.

Anonymous (not verified) Sun, 26/07/2015 - 21:28

"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."

I am new to debian and I don't know how to purge the i386 kernels.

Ewan Mon, 27/07/2015 - 14:36

In reply to by Anonymous (not verified)

You can list the installed kernels using dpkg --list "linux-image*" and the 32 bit kernels are shown below on the i386 lines.

Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name                                 Version                            Architecture Description
+++-====================================-==================================-============-==============================================================================
un  linux-image                                                                    (no description available)
un  linux-image-2.6-486                                                            (no description available)
ii  linux-image-2.6-686                  3.2+46                             i386         Linux for modern PCs (dummy package)
un  linux-image-2.6-686-bigmem                                                     (no description available)
un  linux-image-2.6-amd64                                                          (no description available)
un  linux-image-2.6-k7                                                             (no description available)
un  linux-image-2.6-openvz-686                                                     (no description available)
un  linux-image-2.6-vserver-686                                                    (no description available)
un  linux-image-2.6-vserver-686-bigmem                                             (no description available)
un  linux-image-2.6-xen-686                                                        (no description available)
ii  linux-image-3.2.0-4-686-pae          3.2.68-1+deb7u2                    i386         Linux 3.2 for modern PCs
ii  linux-image-3.2.0-4-amd64            3.2.46-1+deb7u1                    amd64        Linux 3.2 for 64-bit PCs
ii  linux-image-686-pae                  3.2+46                             i386         Linux for modern PCs (meta-package)
ii  linux-image-amd64                    3.2+46                             amd64        Linux for 64-bit PCs (meta-package)

You can then purge kernels, for example apt-get purge linux-image-2.6-686:i386 linux-image-3.2.0-4-686-pae:i386 linux-image-686-pae:i386

tombsar (not verified) Fri, 09/10/2015 - 13:48

I got as far as the middle of step 8 (running "dpkg --abort-after=1000 -i bootstrap-amd64/var/cache/apt/archives/*.deb"), but there is a huge list of errors such as "tar: /lib/i386-linux-gnu/libc.so.6: version `GLIBC_2.17' not found (required by tar)". I presume I will need to reinstall from scratch, but does anyone have insight into what might have caused the problem, and if there is an easy fix I have overlooked?

GG (not verified) Thu, 28/01/2016 - 21:54

For system's language other than english (example PL) add package locales to --include in debootstrap command (in point 6.)

Simon Hobson (not verified) Fri, 19/08/2016 - 17:14

Many, many thanks for this. It mostly worked great for me. There was a bit of a moment when somehow I'd ended up with a point version difference in a key package (libc6 IIRC) and then wondered how I'd get round the catch 22 of not having any means to copy a new file to the system without being able to install any of the tools that all relied on this lib. Then I found the correct i386 version was in fact there, installed it and carried on.
Rather than just re-installing everything that was on before, I took the opportunity to clean up a bit - but starting with a clone of the system (so all my scripts, customisations, config files etc all in place) certainly helped.

Angel (not verified) Mon, 14/11/2016 - 11:32

I used it on jessy. It works great.
Thank you for this great and well explained procedure

Hi Ewan
I'm just trying to do a migration of a Devuan system following your guide.
However, I've one or two small problems with the following line in section 6, which produced an empty file on my system:
ls -1 bootstrap-amd64/var/cache/apt/archives/|egrep "\.deb$"|cut -d "_" -f1|awk '{print $1 " install"}' >dpkg-get-selections.base
First, the dollar sign in egrep ... .deb$ leads to an empty output here. If I remove the dollar sign, it works. I know it should denote the end of the line; maybe ls outputs additional (invisible) characters after the .deb over here - I don't know.
Second, i mistook the -1 (one) after the ls for an -l (long), due to the typeface my browser uses to show this line.
If an -l (long) is erratically used, then awk ... print $1 returns the access rights with added install for every line, and print $9 would work :-)
I don't know whether a -1 is needed at all, because ls and ls -1 apparently seem to produce identical results; if that option is not needed I'd suggest to leave it out alltogether.
In any case, I would suggest to add a suggestion to check the content of all selection... files immediately after creating them - just to make sure they're not empty, because that might cause some major disappointment in the process.
Now, I'll try to continue...
Thanks again for writing up this guide!

js (not verified) Fri, 06/12/2019 - 00:36

On my system, I tried to add a foreign architecture amd64 and installed several libraries in the :amd64 version before I tried the migration.
In step 7, cat dpkg-get-selections.base-all-packages | dpkg --set-selections failed with some warnings some errors; the latter caused by "more than one version of several packages installed", and this would stop the process.
So I tried dpkg-remove `dpkg-query -l | grep -io .*:amd64 | cut -d " " -f3' to remove all :amd64 packages before doing the migration, hoping this would help.
This fixed this problem; i.e. the set-elections worked - still with 10 warnings, but no errors.
However, I guess the removal of amd64 packages should have happened right in the beginning, before the installation of the amd64 kernel.
(I don't know enough to be completely sure, but you might know.)
Kind regards, J.