Hacker News new | past | comments | ask | show | jobs | submit login

On Linux, it's even easier (lol, who would have guessed?).

I recently had the need to compile quite a bit of software to run on the Pi zero, and the ability to be able to "chroot" to the Pi on my PC has made the experience so much more pleasant. Everything compiles ten times faster!

I also noticed that none of the available guides work well with Ubuntu 17.04 (and possibly newer/older), so I put together a simple script to do that on Ubuntu for anyone who is interested. It will always work when you chroot on the sdcard:

https://gist.github.com/htruong/7df502fb60268eeee5bca21ef3e4...

You can theoretically chroot into the image directly, but the resizing the partitions operation is unreliable on the host for some reason, and it might cause the image to not be bootable. I've found myself better off booting the sd card once with the vanilla image on the Pi first so it resizes itself before chrooting into the SD card.




I had this problem with my similar script until I added 'sync; sleep 1; partprobe' after the writing the new partition information (before running e2fsck).


Great, I will check it out :)


Thank you! I'm developing a project involving rpi0 now; this will simplify things so much!


Am I misreading or are you chrooting to an x86 build of Raspbian?


Good observation :) it's the raspbian arm build -- you are chroot-ing into the exact SD card that you put into the Pi.

I don't know how exactly this sorcery works either. But I think chroot just "knows" that it needs to invoke qemu when it sees the binfmt of /bin/bash being arm.


If you read the script, it copies the relevant qemu binary on line 52 to the chroot's /usr/bin/.

What's happening here is binfmt-support on the host has a path registered for arm binaries as the file you just copied to /usr/bin - whenever the chroot tries to run anything, the host directs it to this bianry which is your arm emulator :).


That's an awesome explanation - thanks! I just copied and pasted from other people's code and prettified it a bit so it's easier to use, but I didn't really understand why it worked. Now I do a bit better.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: