Note

The Funtoo Linux project has transitioned to "Hobby Mode" and this wiki is now read-only.

Difference between revisions of "Package:Fchroot"

From Funtoo
Jump to navigation Jump to search
 
(10 intermediate revisions by one other user not shown)
Line 1: Line 1:
{{Subpages|Releases}}
{{Note|{{LatestRelease|fchroot}}}}
"fchroot" is the Funtoo franken-chroot tool, which uses the power of QEMU to allow you to "fchroot" into a non-x86 system on an x86 system and use it as if it were a native chroot.
"fchroot" is the Funtoo franken-chroot tool, which uses the power of QEMU to allow you to "fchroot" into a non-x86 system on an x86 system and use it as if it were a native chroot.
It currently allows chrooting into arm-32bit, arm-64bit and riscv-64bit systems (with version 0.2 adding PowerPC support) on a regular 64-bit PC.
It currently allows chrooting into arm-32bit, arm-64bit and riscv-64bit systems (with version 0.2 adding PowerPC support) on a regular 64-bit PC.


The pypi package index for fchroot can be found here: https://pypi.org/project/fchroot/
The pypi package index for fchroot can be found here: https://pypi.org/project/fchroot/
A YouTube video demo of the tool can be seen here:
{{#evt:service=youtube|id=https://youtu.be/TAg2mfwPtHY}}


=== Installation ===
=== Installation ===


To emerge fchroot, perform the following steps:
To emerge fchroot, add the following lines to {{f|/etc/portage/package.use}} (you will be prompted to add these lines if you just skip to the {{c|emerge}} command, below.) This will ensure that QEMU is emerged with the proper non-native architecture support,
and that the wrapper that it creates can be compiled statically and thus run inside the fchroot without any additional libraries, which
is necessary for simple operation:


{{console|body=
{{file|name=/etc/portage/package.use|body=
###i## cat >> /etc/portage/package.use << "EOF"
app-emulation/qemu static-user qemu_user_targets_aarch64 qemu_user_targets_riscv64 qemu_user_targets_arm qemu_user_targets_ppc64
app-emulation/qemu static-user qemu_user_targets_aarch64 qemu_user_targets_riscv64 qemu_user_targets_arm
dev-libs/glib static-libs
dev-libs/glib static-libs
dev-libs/libpcre static-libs
dev-libs/libpcre static-libs
sys-apps/attr static-libs
sys-apps/attr static-libs
EOF
}}
 
Now, emerge {{c|fchroot}}:
 
{{console|body=
###i## emerge -av fchroot
###i## emerge -av fchroot
}}
}}
Line 23: Line 36:


{{console|body=
{{console|body=
# ##i##cd /var/tmp/riscv-stage3
# ##i##cd /home/pnoecker/sexybeast
# ##i##tar --numeric-owner --xattrs --xattrs-include='*' -xpf stage3-sifive-fu740-next-2021-10-21.tar.xz
# ##i##fchroot tools
# ##i##fchroot . /bin/bash
 
>>> Setting up /proc...
Funtoo fchroot 0.2 ("Darth Elmo"); Copyright 2020-2022 Funtoo Solutions, Inc.
>>> Setting up /sys...
Licensed under the Apache License, Version 2.0
>>> Setting up /dev...
 
>>> ##y##riscv-64bit##!y## frankenchroot B]...
\##g##>>> ##c##Entering powerpc-64bit (power7 CPU)##!c## fchroot...
%fchroot%
bash-5.1#
}}
}}


Fchroot does the steps necessary to enable the QEMU emulation, and also takes care of performing bind-mounts for {{c|/dev}}, {{c|/proc}} and {{c|/sys}}, and copying {{c|/etc/resolv.conf}} into the chroot environment to ensure that name resolution works.
Fchroot does the steps necessary to enable the QEMU emulation, and also takes care of performing bind-mounts for {{c|/dev}}, {{c|/proc}} and {{c|/sys}}, and copying {{c|/etc/resolv.conf}} into the chroot environment to ensure that name resolution works. It will recursively unmount these directories when you exit the chroot.


You are now fchrooted into a riscv environment, running riscv via QEMU, and this will be reflected in the {{c|uname -a}} output:
You are now fchrooted into a PowerPC environment, running riscv via QEMU, and this will be reflected in the {{c|uname -a}} output:


{{console|body=
{{console|body=
%fchroot% ##i##uname -a
%fchroot% ##i##uname -a
Linux ryzen 5.10.46_p4-debian-sources #1 SMP Wed Aug 4 23:05:15 MDT 2021 ##g##riscv64##!g## GNU/Linux                                                                        
Linux alkaline-dev-1 5.16.7_p1-debian-sources #1 SMP PREEMPT Mon Feb 7 13:06:48 MST 2022 ##g##ppc64##!g## GNU/Linux                                                                      
}}
}}


You can do anything you would do in a regular chroot, including {{c|ego sync}} and emerging things, as long as you disable {{c|pid-sandbox}}
You can do anything you would do in a regular chroot, including {{c|ego sync}} and emerging things, as long as you disable {{c|pid-sandbox}} in environment you are chrooted in.
for Portage:
for Portage:


Line 53: Line 66:
In your fchrooted environment, you will be running a 'native' RISCV or ARM system, but it will be executing via QEMU transparently whenever it encounters a binary that is for the foreign architecture. It will have the number of cores and the amount of memory that you have on your host x86 system. When you use 'htop' in the chroot, you will be able to see all processes on your x86 system. If you run 'htop' outside of the fchroot, you will be able to also see processes running inside the fchroot. You will also see that all executables running in the fchroot are using a QEMU wrapper to execute. This is done transparently by the kernel after fchroot has done its configuration magic.
In your fchrooted environment, you will be running a 'native' RISCV or ARM system, but it will be executing via QEMU transparently whenever it encounters a binary that is for the foreign architecture. It will have the number of cores and the amount of memory that you have on your host x86 system. When you use 'htop' in the chroot, you will be able to see all processes on your x86 system. If you run 'htop' outside of the fchroot, you will be able to also see processes running inside the fchroot. You will also see that all executables running in the fchroot are using a QEMU wrapper to execute. This is done transparently by the kernel after fchroot has done its configuration magic.


It's even possible to fchroot into an NFS mount of a remote RISCV or ARM system, and compile packages using your x86 CPU and memory. The packages that install will be for the native architecture. This is very handy for raspberry pi and systems that have minimal RAM and cores.
It's even possible to fchroot into an NFS mount of a remote RISCV or ARM system, and compile packages using your x86 CPU and memory. The packages that install will be for the native architecture. This is very handy for Raspberry Pi and systems that have minimal RAM and cores.


See a live demo here:
[[Category:Official Documentation]]
 
{{#evt:service=youtube|id=https://youtu.be/TAg2mfwPtHY}}
[[Category:First Steps]]

Latest revision as of 18:56, June 9, 2024

Subpages:
   Note

The latest release of fchroot is 1.0.0, released on 11 June 2022. It is a major software release. View Release Notes.

"fchroot" is the Funtoo franken-chroot tool, which uses the power of QEMU to allow you to "fchroot" into a non-x86 system on an x86 system and use it as if it were a native chroot. It currently allows chrooting into arm-32bit, arm-64bit and riscv-64bit systems (with version 0.2 adding PowerPC support) on a regular 64-bit PC.

The pypi package index for fchroot can be found here: https://pypi.org/project/fchroot/

A YouTube video demo of the tool can be seen here:

Installation

To emerge fchroot, add the following lines to /etc/portage/package.use (you will be prompted to add these lines if you just skip to the emerge command, below.) This will ensure that QEMU is emerged with the proper non-native architecture support, and that the wrapper that it creates can be compiled statically and thus run inside the fchroot without any additional libraries, which is necessary for simple operation:

   /etc/portage/package.use
app-emulation/qemu static-user qemu_user_targets_aarch64 qemu_user_targets_riscv64 qemu_user_targets_arm qemu_user_targets_ppc64
dev-libs/glib static-libs
dev-libs/libpcre static-libs
sys-apps/attr static-libs

Now, emerge fchroot:

root # emerge -av fchroot

Use

You can now extract your non-x86 stage3 tarball to your preferred location, such as /var/tmp/riscv-stage3, and then fchroot into it:

root # cd /home/pnoecker/sexybeast
root # fchroot tools

Funtoo fchroot 0.2 ("Darth Elmo"); Copyright 2020-2022 Funtoo Solutions, Inc.
Licensed under the Apache License, Version 2.0

>>> Entering powerpc-64bit (power7 CPU) fchroot...
bash-5.1#

Fchroot does the steps necessary to enable the QEMU emulation, and also takes care of performing bind-mounts for /dev, /proc and /sys, and copying /etc/resolv.conf into the chroot environment to ensure that name resolution works. It will recursively unmount these directories when you exit the chroot.

You are now fchrooted into a PowerPC environment, running riscv via QEMU, and this will be reflected in the uname -a output:

fchroot # uname -a
Linux alkaline-dev-1 5.16.7_p1-debian-sources #1 SMP PREEMPT Mon Feb 7 13:06:48 MST 2022 ppc64 GNU/Linux

You can do anything you would do in a regular chroot, including ego sync and emerging things, as long as you disable pid-sandbox in environment you are chrooted in. for Portage:

   /etc/make.conf - add sandbox
FEATURES="-pid-sandbox"

Implications

In your fchrooted environment, you will be running a 'native' RISCV or ARM system, but it will be executing via QEMU transparently whenever it encounters a binary that is for the foreign architecture. It will have the number of cores and the amount of memory that you have on your host x86 system. When you use 'htop' in the chroot, you will be able to see all processes on your x86 system. If you run 'htop' outside of the fchroot, you will be able to also see processes running inside the fchroot. You will also see that all executables running in the fchroot are using a QEMU wrapper to execute. This is done transparently by the kernel after fchroot has done its configuration magic.

It's even possible to fchroot into an NFS mount of a remote RISCV or ARM system, and compile packages using your x86 CPU and memory. The packages that install will be for the native architecture. This is very handy for Raspberry Pi and systems that have minimal RAM and cores.