Ever wanted an armhf container on your x86 machine? It’s now possible with LXC in Ubuntu Precise

It took a while to get some apt resolver bugs fixed, a few packages marked for multi-arch and some changes in the Ubuntu LXC template, but since yesterday, you can now run (using up to date Precise):

  • sudo apt-get install lxc qemu-user-static
  • sudo lxc-create -n armhf01 -t ubuntu — -a armhf -r precise
  • sudo lxc-start -n armhf01
  • Then login with root as both login and password

And enjoy an armhf system running on your good old x86 machine.

Now, obviously it’s pretty far from what you’d get on real ARM hardware.
It’s using qemu’s user space CPU emulation (qemu-user-static), so won’t be particularly fast, will likely use a lot of CPU and may give results pretty different from what you’d expect on real hardware.

Also, because of limitations in qemu-user-static, a few packages from the “host” architecture are installed in the container. These are mostly anything that requires the use of ptrace (upstart) or the use of netlink (mountall, iproute and isc-dhcp-client).
This is the bare minimum I needed to install to get the rest of the container to work using armhf binaries. I obviously didn’t test everything and I’m sure quite a few other packages will fail in such environment.

This feature should be used as an improvement on top of a regular armhf chroot using qemu-user-static and not as a replacement for actual ARM hardware (obviously), but it’s cool to have around and nice to show what LXC can do.

I confirmed it to work for armhf and armel, powerpc should also work, though it didn’t succeed to debootstrap when I tried it earlier today.

Enjoy!

About Stéphane Graber

Project leader of Linux Containers, Linux hacker, Ubuntu core developer, conference organizer and speaker.
This entry was posted in Canonical voices, LXC, Planet Ubuntu and tagged . Bookmark the permalink.

12 Responses to Ever wanted an armhf container on your x86 machine? It’s now possible with LXC in Ubuntu Precise

  1. Rohan Garg says:

    Hi!
    I was wondering, would it be possible for you to fix pbuilder-dist in ubuntu for armel packages as well? Seems like it works on Debian sid but fails to create a armel chroot on precise because Ubuntu seems to enable fortify_source ( https://wiki.ubuntu.com/Security/Features#fortify-source )

  2. André Balsa says:

    Hello Stéphane and thanks for the very good article on getting an armhf container working in an Ubuntu 12.04 workstation. This is exactly what I needed to compile/develop/test armhf applications!
    I used exactly the commands you described above but upon starting my container, I got the usual error messages:
    lxc-start: failed to attach 'vethpiHx6b' to the bridge 'lxcbr0' : No such device
    lxc-start: failed to create netdev
    lxc-start: failed to create the network
    lxc-start: failed to spawn 'armhf01'

    I had forgotten to setup a bridge! This was solved with a few extra commands:
    sudo brctl addbr lxcbr0
    sudo brctl setfd lxcbr0 0
    sudo brctl addif lxcbr0 eth0
    sudo ifconfig lxcbr0 192.168.12.22 promisc up
    sudo ifconfig eth0 0.0.0.0 up
    sudo route add -net default gw 192.168.12.1 lxcbr0

    and everything worked like a charm! 🙂

    1. You shouldn’t have to create lxcbr0, the lxc and lxc-net upstart jobs do that for you.
      Maybe you have something wrong going on in /etc/default/lxc or something else that’s making the init scripts fail. You may want to check /var/log/upstart/lxc*

      1. Stuart Naylor says:

        I do quite a lot of evalution work by knocking up a quick VM usually virtual box.

        I got the same errors until I ran lxc bare metal and then no probs.

  3. André Balsa says:

    Thanks for the tip, Stéphane. I think I found the problem: I was already using dnsmasq. The /etc/default/lxc file has a warning about it:
    # If you have the dnsmasq daemon installed, you’ll also have to update
    # /etc/dnsmasq.d/lxc and restart the system wide dnsmasq daemon.

    Next I’ll experiment with LXC directly on ARM hardware (an MK802 Android stick that can optionally boot Ubuntu Precise armhf and try to run both Ubuntu Precise and Android ICS side-by-side!

  4. mike says:

    Works great thanks:-
    installed gcc then tested with this little snippet, saved as test.c, compiled withh gcc test.c, and run with ./a.out to see hello on the screen.

    #include
    void main(void){
    asm (“mov r0, r0”);
    puts (“hello”);
    }

  5. Brendan Donegan says:

    The command text is a little confusing because the ‘–‘ characters seem to have been converted to a — So if we copy and paste (which many will) we will get cryptic errors from lxc-create. If it’s possible, update that so that it’s literally ‘–‘.

    1. chinmoy says:

      sudo lxc-create -n armhf01 -t ubuntu — -a armhf -r precise — > It will work .

      1. chinmoy says:

        Sorry it is like” —” = two times of this –

  6. Leo Arias says:

    What is the way to do this in xenial?

  7. chinmoy says:

    sudo lxc-start -n armhf01
    lxc-start: lxccontainer.c: wait_on_daemonized_start: 799 Received contain er state “ABORTING” instead of “RUNNING”
    The container failed to start.
    To get more details, run the container in foreground mode.
    Additional information can be obtained by setting the –logfile and –log priority options.
    ***
    I didnot get why it is faling here

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.