pinilpypinilpy
Posts: 7
Joined: Sat Dec 30, 2017 1:31 am

running x86 linux programs on the raspberry pi

Mon Feb 05, 2018 1:04 am

I managed to get an i386 wheezy chroot running on stretch (pi2) with qemu-i386-static. as far as I know, to get a working version of wine you need to compile eltech's 2g/2g version from their github page. I have not tried it. everything works but it runs slowly. it took half a minute to start PuTTY.
(ps. another way to get wine working is to compile the pi's kernel with a 3g/1g memory split) :(

qemu only uses one core, so it might be a good idea to overclock.

instructions:

Code: Select all

sudo su

Code: Select all

apt-get update && apt-get install qemu qemu-user qemu-user-static binfmt-support debootstrap binutils

Code: Select all

mount -t binfmt_misc none /proc/sys/fs/binfmt_misc
        echo -1 > /proc/sys/fs/binfmt_misc/status
        echo ':i386:M::\x7fELF\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x03:\xff\xff\xff\xff\xff\xfe\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfb\xff\xff:/usr/bin/qemu-i386-static:' > /proc/sys/fs/binfmt_misc/register

Code: Select all

debootstrap --arch=i386 --foreign wheezy chroot-wheezy-i386 http://ftp.de.debian.org/debian

Code: Select all

(as user) cd chroot-wheezy-i386

Code: Select all

cp /usr/bin/qemu-i386-static usr/bin/

Code: Select all

id (need for later)

Code: Select all

cd

Code: Select all

sudo su

Code: Select all

  DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true LC_ALL=C LANGUAGE=C LANG=C chroot chroot-wheezy-i386 /debootstrap/debootstrap --second-stage

Code: Select all

echo "deb http://ftp.ca.debian.org/debian/ wheezy main" > chroot-wheezy-i386/etc/apt/sources.list.d/wheezy.list (or mirror of your choice)

Code: Select all

env -i TERM=xterm /usr/sbin/chroot chroot-wheezy-i386 /bin/su -l root (welcome to your new debian wheezy chroot!) 

Code: Select all

apt-get update && apt-get install libsm6 libxext6 libfreetype6 libpng12-0 libmpg123-0 sudo(ignore errors)

Code: Select all

 adduser --uid (insert uid here) pi

Code: Select all

exit

Code: Select all

mount --bind /home/pi /home/pi/chroot-wheezy-i386/home/pi  mount --bind /dev /home/pi/chroot-wheezy-i386/dev mount --bind /proc /home/pi/chroot-wheezy-i386/proc

Code: Select all

exit

next part:

to use the chroot:

Code: Select all

sudo su
mount -t binfmt_misc none /proc/sys/fs/binfmt_misc
        echo -1 > /proc/sys/fs/binfmt_misc/status
        echo ':i386:M::\x7fELF\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x03:\xff\xff\xff\xff\xff\xfe\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfb\xff\xff:/usr/bin/qemu-i386-static:' > /proc/sys/fs/binfmt_misc/register

Code: Select all

mount --bind /home/pi /home/pi/chroot-wheezy-i386/home/pi
        mount --bind /dev /home/pi/chroot-wheezy-i386/dev
        mount --bind /proc /home/pi/chroot-wheezy-i386/proc

Code: Select all

xhost +

Code: Select all

env -i TERM=xterm /usr/sbin/chroot chroot-wheezy-i386 /bin/su -l root (or pi)

Code: Select all

export DISPLAY=:0.0
anything (and everything)you put in the pi's home/pi directory will appear in the chroot's pi directory

I may have made a few mistakes, and all thanks goes to bernhardu @ the WineHQ Forums (link to original post by bernhardu -https://forum.winehq.org/viewtopic.php? ... =25#p84325)

have fun! :P
(and bye-bye exagear)

mikerr
Posts: 2745
Joined: Thu Jan 12, 2012 12:46 pm
Location: UK
Contact: Website

Re: running x86 linux programs on the raspberry pi

Tue Mar 13, 2018 3:39 pm

That gets an x86 environment- to add and use Wine for windows apps, I also did the next stage
- compiled the pi kernel for 3/1G and packaged it all into a ready made .img based on latest Stretch:

https://sourceforge.net/projects/pi-qemu-wine/

Using it is as "easy" as:

double click in the wine-user icon

type:

wine ~/.wine/drive_c/windows/notepad.exe
Android app - Raspi Card Imager - download and image SD cards - No PC required !

Flabou
Posts: 1
Joined: Tue Aug 07, 2018 10:51 am

Re: running x86 linux programs on the raspberry pi

Wed Aug 08, 2018 2:24 pm

Hello,
I am trying to achieve the same results as you but with the most recent version of Raspbian/Debian (stretch). I've been at this for quite a while and I also read in the original thread that the host and guest OS should be the same version. Which isn't the case for Raspberry pi 3 version provided by mikerr (it runs stretch host with wheezy guest), I don't know for the Raspberry Pi 1 version provided by AlbrechtL. I don't know if this impacts performance/compatibility a lot but I am having trouble running the program I need so I want to give it a shot.

However, I don't understand everything and I have some differences with you, especially in the lines :

Code: Select all

mount -t binfmt_misc none /proc/sys/fs/binfmt_misc
echo -1 > /proc/sys/fs/binfmt_misc/status
echo ':i386:M::\x7fELF\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x03:\xff\xff\xff\xff\xff\xfe\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfb\xff\xff:/usr/bin/qemu-i386-static:' > /proc/sys/fs/binfmt_misc/register
First of all I can't mount none because I already have the following mounted on binfmt_misc:

Code: Select all

[email protected]:~ $ mount | grep binfmt
systemd-1 on /proc/sys/fs/binfmt_misc type autofs (rw,relatime,fd=27,pgrp=1,timeout=0,minproto=5,maxproto=5,direct)
binfmt_misc on /proc/sys/fs/binfmt_misc type binfmt_misc (rw,relatime)
I tried doing the echos anyway, I also tried unmounting everything before mounting none, but in both case I was unable to run

Code: Select all

DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true LC_ALL=C LANGUAGE=C LANG=C chroot chroot-wheezy-i386 /debootstrap/debootstrap --second-stage
However, having installed qemu using apt-get as suggested, I see there is already an entry in binfmt_misc which points to the binary qemu-i386-static. So I tried leaving everything as it is and it did launch the second phase of the debootstrap and started configuring and unpacking everything, but then it reached "Unpacking the base system" and it got stuck there for around 7 hours (I'm guessing it's too long) before I had to stop it. I had the exact same results on two different systems (a Raspberry Pi 1 and a beaglebone black wireless).

Can someone explain me why we have to mount "None" to binfmt_misc? I understand that binfmt is a feature which allows to detect executables and execute them through the correct interpreter (in this case qemu-i386-static). So I believe it should work the way I have done it (it was able to start the second stage which means it clearly used the correct interpreter otherwise I would have a "Bad exec format" error). The next thing I want to try is to create the debootstrap chroot system on standard i386 system and then copy and paste the chroot folder, is that a good idea? It means I wouldn't even need the --foreign argument and could do it in one go.

Also I don't understand why the 3G/1G is necessary on raspberry pi 3 but not on pi 1? Are they compiled with a different kernel? How do you find the virtual memory split value of the running kernel? Is it better to compile a new kernel 3G/1G or to compile a wine version which is 2G/2G like it was done by exagear?

One last question if anyone know : In the older version of this tutorial, qemu was in version 1.4.0 and required a NPTL patch as well as a system call patch to work. Here you install it without any patch, is this okay? Did qemu correct those "problems"?

Thanks in advance for your help.

liveis.life
Posts: 2
Joined: Mon Aug 20, 2018 5:27 pm

Re: running x86 linux programs on the raspberry pi

Fri Aug 24, 2018 4:42 pm

Hi
I tried all step by step with no errors. but when i enter

Code: Select all

wine ~/.wine/drive_c/windows/notepad.exe
i get
Segmentation fault
what should i do?

User avatar
DougieLawson
Posts: 35021
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: running x86 linux programs on the raspberry pi

Fri Aug 24, 2018 6:02 pm

Forget it. Either buy the Eltechs stuff or buy an X86_64 based computer.
Note: Having anything remotely humorous in your signature is completely banned on this forum.

Any DMs sent on Twitter will be answered next month.

This is a hippy & doctor free zone.

jdonald
Posts: 139
Joined: Fri Nov 03, 2017 4:36 pm

Re: running x86 linux programs on the raspberry pi

Fri Nov 16, 2018 6:48 am

Thanks so much for building that image, mikerr. Works like a charm when I try it with a basic helloworld C exercise.

Code: Select all

    $ sudo apt install gcc-mingw-w64-i686
    $ i686-w64-mingw32-gcc hello.c -o hello.exe
    $ file hello.exe
    hello.exe: PE32 executable (console) Intel 80386, for MS Windows
    $ cp hello.exe ~/chroot-wheezy-i386/home/wine-user/

Then in the Wine x86 user shell:

Code: Select all

    $ wine hello.exe
    ...
    hello, world!
Flabou wrote:
Wed Aug 08, 2018 2:24 pm
I've been at this for quite a while and I also read in the original thread that the host and guest OS should be the same version.
Haven’t read that whole thread, but I don’t see why this should be a restriction. If the guest OS is only used for sandboxing Wine i386, it might as well be wheezy or anything. Your other questions are good and I don't have answers, but I can say I'm grateful to have the pre-made image so that I don't have to go through the same headaches.
liveis.life wrote:
Fri Aug 24, 2018 4:42 pm
I tried all step by step with no errors. but when i enter wine ~/.wine/drive_c/windows/notepad.exe i get Segmentation fault what should i do?
The Notepad window pops up for me when I run exactly that command in the Wine x86 shell. Are you following pinilpypinilpy’s complete tutorial? If so, maybe you should skip it and just use mikerr's handy image :)

For what it’s worth I’m running on a Pi 3.

tenochtitlanuk
Posts: 155
Joined: Fri Jul 06, 2012 8:51 pm
Location: Taunton, Somerset, UK
Contact: Website

Re: running x86 linux programs on the raspberry pi

Fri Nov 16, 2018 1:27 pm

If you haven't seen it, Dougie is referring to https://eltechs.com/product/exagear-desktop/

Minecon724
Posts: 1
Joined: Sun Sep 16, 2018 11:39 am

Re: running x86 linux programs on the raspberry pi

Sat Dec 29, 2018 11:09 am

How to delete it? :roll:

jdonald
Posts: 139
Joined: Fri Nov 03, 2017 4:36 pm

Re: running x86 linux programs on the raspberry pi

Sat Dec 29, 2018 4:52 pm

Try this:

Code: Select all

sudo umount ~/chroot-wheezy-i386
rm -rf ~/chroot-wheezy-i386
sudo apt remove qemu qemu-user qemu-user-static binfmt-support debootstrap binutils
Some things might remain like the userid, but it will free up the bulk of disk space used here.

Return to “Advanced users”