[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: cross install 64bit target from 32bit host

On 05/29/2016 01:34 AM, Haines Brown wrote:
> This is an extension of my initial question, for I'm not sure my initial
> conclusion that it is impossible to chroot a 64bit system from a 32bit
> system is correct.

With a 32bit kernel you need qemu-user-static for this to work - but
expect it to be _at least_ a factor of 10 or so slower than your
normal system when using qemu. (Especially if your kernel is 32bit
x86, which is register-starved, so emulating other platforms is
likely going to be really slow.)

> Or can chroot be run on a 64 bit system mounted on /mnt/64bit/:
>   # dpkg --add-architecture amd64
>   # apt-get update
>   # apt-get install libc6-amd64
>   # LANG=C.UTF-8 chroot /mnt/64bit /bin/bash

dpkg --add-architecture (and installing libc6-amd64) is never
useful for chroots: either you can execute 64bit binaries (directly
via a 64bit kernel or indirectly via qemu-user-static), and then
chroot will just work (without any 64bit software on the host), or
you can't execute them, and then it won't help either.

What you can do is:

apt-get install qemu-user-static

Then you need to setup the x86_64 binfmt manually, because the
Debian package doesn't do that automatically anymore [1]:

/usr/sbin/update-binfmts --install qemu-x86_64 \
   /usr/bin/qemu-x86_64-static \
   --magic '\x7f\x45\x4c\x46\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x3e\x00' \
   --mask '\xff\xff\xff\xff\xff\xfe\xfe\xfc\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff' \
   --offset 0 --credential yes

Then copy the /usr/bin/qemu-x86_64-static binary into the chroot:

cp /usr/bin/qemu-x86_64-static /mnt/64bit/usr/bin/

And then you can just use chroot directly:

LANG=C.UTF-8 chroot /mnt/64bit /bin/bash

(Note that the normal rules for chroots also apply, i.e. that
you might need to handle the /proc, /sys and /dev{,/pts,/shm}
and /run file systems specially, depending on what you want to
do inside the chroot.)

But as I said above: with qemu-user-static it's going to be very
slow. Especially since your hardware does support 64bit code
directly, I would *really* recommend you to just install a 64bit
kernel [2] (you can leave the main packages 32bit) and reboot,
then you can chroot into either 64bit or 32bit environments
without having to resort to emulation. So unless you're just
using this as a temporary measure, I really wouldn't recommend


[1] See bug #604712, because i386 can be used with 64bit kernels,
    which is much more common than your use case, and there you
    don't want to have emulation.
[2] Will probably boil down to something like:
    dpkg --add-architecture amd64
    apt-get update
    apt-get install linux-image-amd64

Attachment: signature.asc
Description: OpenPGP digital signature

Reply to: