Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Raspberry Pi 3B - Chroot Using Qemu
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Gentoo on ARM
View previous topic :: View next topic  
Author Message
Jon Wilder
Tux's lil' helper
Tux's lil' helper


Joined: 04 Apr 2011
Posts: 112
Location: Fresno CA

PostPosted: Sun Jul 30, 2017 4:22 pm    Post subject: Raspberry Pi 3B - Chroot Using Qemu Reply with quote

I've about had it with Gentoo on a Rpi3B. I've gotten it working but it just doesn't have the horsepower to compile things on its own without getting too hot. As I only need a few applications on it, I've decided to have my cross build system emerge and build the packages in a cross-chroot environment.

I've tried to my wits end to chroot via Qemu and am ending up at square one every time -

Code:

gentoo /usr/aarch64-unknown-linux-gnu # chroot . /bin/bash --login
chroot: failed to run command ‘/bin/bash’: Exec format error


What's driving me so damn mad is that the documentation that is available for Qemu chrooting into a Raspberry Pi environment is SERIOUSLY LACKING!!! It's scattered across several pages, none of it seems to be complete, and following the steps in the pages just leads me to this.

Is there anyone who knows how to and has been successful with chrooting into a Rpi3B environment using Qemu? If so, can you please walk me through it?
Back to top
View user's profile Send private message
NeddySeagoon
Administrator
Administrator


Joined: 05 Jul 2003
Posts: 54208
Location: 56N 3W

PostPosted: Sun Jul 30, 2017 5:33 pm    Post subject: Reply with quote

Jon Wilder,

Its not ready for the main wiki.

That's 64 bit Pi 3. 32 bit will be similar. Commentary welcome.
Qemu is not a silver bullet. Some things won't build there.

-- edit --
It looks like the binfmt service service is not running on the host.
That needs kernel support too.
_________________
Regards,

NeddySeagoon

Computer users fall into two groups:-
those that do backups
those that have never had a hard drive fail.
Back to top
View user's profile Send private message
Jon Wilder
Tux's lil' helper
Tux's lil' helper


Joined: 04 Apr 2011
Posts: 112
Location: Fresno CA

PostPosted: Sun Jul 30, 2017 6:27 pm    Post subject: Reply with quote

NeddySeagoon wrote:
Jon Wilder,

Its not ready for the main wiki.

That's 64 bit Pi 3. 32 bit will be similar. Commentary welcome.
Qemu is not a silver bullet. Some things won't build there.

-- edit --
It looks like the binfmt service service is not running on the host.
That needs kernel support too.


binfmt service is running -

Code:

gentoo /usr/src/linux # rc-status | grep qemu
 qemu-binfmt                                                       [  started  ]


And here are my mount points for Raspberry Pi Chroot -

Code:

binfmt_misc on /proc/sys/fs/binfmt_misc type binfmt_misc (rw,nosuid,nodev,noexec,relatime)
/dev/sdb6 on /mnt/raspi-gentoo type ext4 (rw,relatime,data=ordered)
/dev/sdb1 on /mnt/raspi-gentoo/boot type vfat (rw,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=iso8859-1,shortname=mixed,errors=remount-ro)
devtmpfs on /mnt/raspi-gentoo/dev type devtmpfs (rw,nosuid,relatime,size=10240k,nr_inodes=433570,mode=755)
proc on /mnt/raspi-gentoo/proc type proc (rw,nosuid,nodev,noexec,relatime)
sysfs on /mnt/raspi-gentoo/sys type sysfs (rw,nosuid,nodev,noexec,relatime)
devpts on /mnt/raspi-gentoo/dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000)


Also have everything for BINFMT in the kernel enabled -

Code:

gentoo /usr/src/linux # cat ./.config | grep BINFMT
CONFIG_BINFMT_ELF=y
CONFIG_COMPAT_BINFMT_ELF=y
CONFIG_BINFMT_SCRIPT=y
CONFIG_BINFMT_MISC=y
Back to top
View user's profile Send private message
NeddySeagoon
Administrator
Administrator


Joined: 05 Jul 2003
Posts: 54208
Location: 56N 3W

PostPosted: Sun Jul 30, 2017 6:40 pm    Post subject: Reply with quote

Jon Wilder,

Looks good so far.
Are you running the kernel you think you are?

What is the date/time in
Code:
uname -a

Thats the build date/time of the running kernel.

Did you build qemu with USE=static-user, QEMU_SOFTMMU_TARGETS=aarch64 QEMU_USER_TARGETS=aarch64 then subsequently install the binary package inside your /usr/aarch64-unknown-linux-gnu/ arm64 chroot?

Thats /mnt/raspi-gentoo for you.

It will be run from there to execute the arm64 code.

Where does my guide go wrong for you?
_________________
Regards,

NeddySeagoon

Computer users fall into two groups:-
those that do backups
those that have never had a hard drive fail.
Back to top
View user's profile Send private message
Jon Wilder
Tux's lil' helper
Tux's lil' helper


Joined: 04 Apr 2011
Posts: 112
Location: Fresno CA

PostPosted: Sun Jul 30, 2017 8:24 pm    Post subject: Reply with quote

NeddySeagoon wrote:
Jon Wilder,

Looks good so far.
Are you running the kernel you think you are?

What is the date/time in
Code:
uname -a

Thats the build date/time of the running kernel.


Code:

jon@gentoo ~ $ uname -a
Linux gentoo 4.12.4-gentoo #1 SMP Sat Jul 29 18:52:57 PDT 2017 x86_64 Intel(R) Pentium(R) D CPU 2.80GHz GenuineIntel GNU/Linux
jon@gentoo ~ $ ls -l /usr/src/linux
lrwxrwxrwx 1 root root 19 Jul 29 18:00 /usr/src/linux -> linux-4.12.4-gentoo
jon@gentoo ~ $


NeddySeagoon wrote:

Did you build qemu with USE=static-user, QEMU_SOFTMMU_TARGETS=aarch64 QEMU_USER_TARGETS=aarch64 then subsequently install the binary package inside your /usr/aarch64-unknown-linux-gnu/ arm64 chroot?


Code:

=================================================================
                        Package Settings
=================================================================

app-emulation/qemu-2.9.0-r56::gentoo was built with the following:
USE="aio alsa bluetooth bzip2 caps curl fdt filecaps gtk jpeg ncurses nls opengl pin-upstream-blobs png sdl seccomp static-user usb vhost-net vnc xattr -accessibility -debug -glusterfs -gnutls -gtk2 -infiniband -iscsi -lzo -nfs -numa -pulseaudio -python -rbd -sasl -sdl2 (-selinux) -smartcard -snappy -spice -ssh -static -systemtap -tci -test -usbredir -vde -virgl -virtfs -vte -xen -xfs" ABI_X86="(64)" LINGUAS="-bg -de_DE -fr_FR -hu -it -tr -zh_CN" PYTHON_TARGETS="python2_7" QEMU_SOFTMMU_TARGETS="arm -aarch64 -alpha -cris -i386 -lm32 -m68k -microblaze -microblazeel -mips -mips64 -mips64el -mipsel -moxie -nios2 -or1k -ppc -ppc64 -ppcemb -s390x -sh4 -sh4eb -sparc -sparc64 -tricore -unicore32 -x86_64 -xtensa -xtensaeb" QEMU_USER_TARGETS="arm -aarch64 -alpha -armeb -cris -hppa -i386 -m68k -microblaze -microblazeel -mips -mips64 -mips64el -mipsel -mipsn32 -mipsn32el -nios2 -or1k -ppc -ppc64 -ppc64abi32 -ppc64le -s390x -sh4 -sh4eb -sparc -sparc32plus -sparc64 -tilegx -x86_64"


It appears I built it with arm instead of aarch64. Is this where I may have gone wrong?

NeddySeagoon wrote:

Did you build qemu with USE=static-user, QEMU_SOFTMMU_TARGETS=aarch64 QEMU_USER_TARGETS=aarch64 then subsequently install the binary package inside your /usr/aarch64-unknown-linux-gnu/ arm64 chroot?

Where does my guide go wrong for you?


https://wiki.gentoo.org/wiki/Raspberry_Pi#Compiling_using_chroot

Nowhere in this guide does it explain this. It only says to build it with static-user, which I have. Nowhere does it explain or mention anything about installing the binary package inside the /usr/aarch64-unknown-linux-gnu arm64 chroot. Attempting to go off of other articles, there just seems to be a lot missing.

How do I go about installing the binary package?
Back to top
View user's profile Send private message
NeddySeagoon
Administrator
Administrator


Joined: 05 Jul 2003
Posts: 54208
Location: 56N 3W

PostPosted: Sun Jul 30, 2017 9:22 pm    Post subject: Reply with quote

Jon Wilder,

arm is 32 bit, aarch64 is 64 bit ARM.
A QEMU built without aarch64 will not be able to execute arm64 code.

If you don't have
Code:
FEATURES=buildpkg
You won't have a binary tarball saved when you build QEMU.
The binary can be generated with the quickpkg command. You may need the --include-config=y option too.
I keep binaries of everything I build, so I don't use quickpkg very much.

Installing the binary into the chroot is described here

The Raspberry_Pi Compiling using chroot is specifically for 32 bit Raspberry Pi.
If you installed following that guide, you will have a 32 bit install but you have a /usr/aarch64-unknown-linux-gnu, which is 64 bit.

The 32 bit guide you referenced does not mention mounting shm after the bind mount of dev either.
Code:
 # must be after the bind mount of dev
mount tmpfs -t tmpfs -o rw,nosuid,nodev,noexec dev/shm


I like this guide better
_________________
Regards,

NeddySeagoon

Computer users fall into two groups:-
those that do backups
those that have never had a hard drive fail.
Back to top
View user's profile Send private message
Jon Wilder
Tux's lil' helper
Tux's lil' helper


Joined: 04 Apr 2011
Posts: 112
Location: Fresno CA

PostPosted: Mon Jul 31, 2017 6:24 pm    Post subject: Reply with quote

NeddySeagoon wrote:
Jon Wilder,

arm is 32 bit, aarch64 is 64 bit ARM.
A QEMU built without aarch64 will not be able to execute arm64 code.

If you don't have
Code:
FEATURES=buildpkg
You won't have a binary tarball saved when you build QEMU.
The binary can be generated with the quickpkg command. You may need the --include-config=y option too.
I keep binaries of everything I build, so I don't use quickpkg very much.

Installing the binary into the chroot is described here

The Raspberry_Pi Compiling using chroot is specifically for 32 bit Raspberry Pi.
If you installed following that guide, you will have a 32 bit install but you have a /usr/aarch64-unknown-linux-gnu, which is 64 bit.

The 32 bit guide you referenced does not mention mounting shm after the bind mount of dev either.
Code:
 # must be after the bind mount of dev
mount tmpfs -t tmpfs -o rw,nosuid,nodev,noexec dev/shm


I like this guide better


Got it.

I haven't tried to chroot yet with this new information. I did, however, manage to get a working Gentoo system going on a 16GB SD card on my Rpi3. A couple of things I would change on your 64-bit wiki -

The config.txt and cmdline.txt files created as shown in the Wiki I had issues with. Kept getting kernel panics and couldn't find the partitions correctly. However, I ended up copying these two files from a working Raspian SD card and editing the root= path in cmdline.txt to match my root partition number. These two files worked without a hitch.

MAKEOPTS - while there are 4 CPU cores and ideally -j5 "should" work, this seems to make the processor run very hot. Understandable though since it is an embedded processor and they don't come with big processor heat sinks/fans like a desktop PC would. Unless you have your Pi in a case with a fan or some other cooling medium, I would keep this setting at -j3.

Now I'm attempting to do a world update on it, but automake fails the install phase for some reason.
Back to top
View user's profile Send private message
salfter
Tux's lil' helper
Tux's lil' helper


Joined: 02 Jan 2003
Posts: 89

PostPosted: Wed Apr 03, 2019 3:20 pm    Post subject: Reply with quote

Sometime between the last post and now, this guide became available:

https://wiki.gentoo.org/wiki/Embedded_Handbook/General/Compiling_with_qemu_user_chroot

I went through it yesterday on a new VM to build binaries for the Raspberry Pi 3, and it worked like a champ. I have a couple of them attached to 3D printers running OctoPrint, so it should be useful for keeping them up to date.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Gentoo on ARM All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum