Emulate (or cross compile) Raspberry Pi on Linux64  to save time and flash disk? - Page 1
Forum section: electronics / general

author: cdev
author_rank: Super Contributor
timestamp: July 19, 2017, 04:28:02 pm
content: Hello, I am running various versions of raspbian (2 wheezy and 1 jessie) on 3 Raspberry Pis and trying to learn new stuff with hardware.However, building software on the Pi, especially the older hardware, is very slow, and as I invariably forget things and want to do it again its frustrating.Is anybody here adept at cross-compiling for their Pi from Linux, (64 bit) or using armhf emulation on qemu or VirtualBox or KVM and building images that way?who could maybe share their own experiences, the relative merits of each, etc.

author: legacy
author_rank: Super Contributor
timestamp: July 19, 2017, 05:41:18 pm
content: Quote from: cdev on July 19, 2017, 04:28:02 pmBah ... flash? Are you using an SD card as rootfs? Bad idea! You complaint that it's s slow because the storage device is slow, thus attaching an USB-hard drive will save you, since it's different orders of magnitude faster.Oh, now you have to chroot, from the SD (from where PI bootstraps) into the "mounted" harddrive. Not a problem, you also need to "bound" dev-names.PI, even the first model appeared on the market, is much more faster than older Unix machines whose user experiences has never gone in anything can be called "complain".

author: elecman14
author_rank: Unknown
timestamp: July 19, 2017, 05:56:03 pm
content: Did the qemu thing in the past. It was somewhat limited on emulation from what I remember. From what I remember it had limited screen resolution using cmd or a gui. This was a couple of years ago so things might have changed. You probably should read up on that before you end up spending the time to get it working.Also I do not believe virtualbox has emulation support for ARM only x86. No idea on KVM since I have never used it.Depending on what you want to do you should also look at network booting. It would save from having to flash multiple SD cards.

author: cdev
author_rank: Super Contributor
timestamp: July 19, 2017, 06:07:08 pm
content: What I do when I want to build software is I have a small external USB hard drive that is partitioned with a Linux filesystem which I use exclusively for builds on RPIs. I create a directory for the software untar the archive and build it there under my regular username. The Pi boots normally using the SD card but I don't build software on the SD card because of the wear issue.How long does it take? at least an hour for ntpd, several hours for the linux kernel.I build it on the external hard drive, which internally is a PATA drive mounted using a PATA adaptor. I could also use an external SATA drive. I am pretty sure the bottleneck is the RPI just not being that fast. Sure, its a lot faster than most machines decades or so ago. My desktop machine is not all that fast but it has six cores and the CPU speed is several times faster so its much faster.When I mount the external partition its in the normal way, mount -t . I don't use a chroot.I haven't thought of using a chroot. Under some conditions it would make sense definitely.

author: RoGeorge
author_rank: Super Contributor
timestamp: July 19, 2017, 08:46:55 pm
content: Some weeks ago I found this RPi emulator, but never had the time to test it:http://www.makeuseof.com/tag/emulate-raspberry-pi-pc/

author: 3db
author_rank: Frequent Contributor
timestamp: July 19, 2017, 09:31:50 pm
content: There used to be a Virtualbox VM for that purpose in the early days of Raspberry PI.

author: brucehoult
author_rank: Super Contributor
timestamp: July 19, 2017, 10:10:55 pm
content: Quote from: cdev on July 19, 2017, 04:28:02 pmYes, we do this all the time at work when we're building software for ARM devices. not only do x86 desktops or servers have more and faster cores than an ARM board like a Pi, but they can have dozens or hundreds of GB of RAM and big fast SSDs.Generally the best way:1) set up qemu-arm-static with binfmt_misc so that you can run arm linux elf binaries from the x86 command line the same as if they were x86 binaries.2) get a root file system for armhf or armel or whatever you want. I prefer to expand it on the host file system but you can also put it on a disk image and mount that3) copy qemu-arm-static to the same relative place in the ARM root filesystem as it is in the host file system e.g. /usr/bin/qemu-arm-static. If you don't use a disk image then you can hard link it instead of copying4) use chroot to switch into the ARM root filesystem. You need to set up a few things for /proc and maybe /dev before doing the chroot. Any chroot tutorial will go through that.On the fastest current x86 chips, qemu is a little bit slower than a core on a Pi 2 or Pi 3 (and quite a lot slower than an Odroid C2 or better XU4). But if you have a server with 36 cores and 128 GB of RAM then you're flying overall :-)

author: brucehoult
author_rank: Super Contributor
timestamp: July 19, 2017, 10:28:44 pm
content: Some instructions that look like they should work here:https://wiki.debian.org/RaspberryPi/qemu-user-staticThat's using a disk image and mounting it. It's all much of a muchness really. If you use a disk image you've got to worry about mounting it, making sure it's big enough etc. Copying the files into your normal filesystem you don't have to worry about any of that and it might even be slightly faster.

author: C
author_rank: Super Contributor
timestamp: July 20, 2017, 12:45:24 am
content: Are you thinking of big picture?From the PI being able to toapt get updatewould be an easy command on PI. You would need to setup your own software source. Have no idea how hard this is, but could pull from cross compiled output.You might also want to look at ANSIBLE.It's a way to build, update & check systems.Not a bad way to automate things, just needs SSH access to the PI's.You could go so far as to build the cross compile environment on your PC as part of process.Think sky is limit for possible use.