Note:
The Funtoo Linux project has transitioned to "Hobby Mode" and this wiki is now read-only.
Difference between revisions of "Funtoo binfmt misc Qemu chroot Guide"
Jump to navigation
Jump to search
Line 1: | Line 1: | ||
=''Funtoo binfmt_misc Qemu chroot Guide: aka (Frankenroot)''= | =''Funtoo binfmt_misc Qemu chroot Guide: aka (Frankenroot)''= | ||
==''Setting Up Your Filesystem''== | |||
===''Exporting Your Remote Mounts''=== | |||
{{file|name=/etc/exports|desc=NFS file systems being exported|body= | {{file|name=/etc/exports|desc=NFS file systems being exported|body= | ||
# /etc/exports: NFS file systems being exported. See exports(5). | # /etc/exports: NFS file systems being exported. See exports(5). | ||
Line 11: | Line 13: | ||
}} | }} | ||
===''Mount Your Remote Mounts Locally and Setup Psuedo Filesystem''=== | |||
{{console|body= | {{console|body= | ||
###i## mount foo.local:/ /mnt/piroot | ###i## mount foo.local:/ /mnt/piroot | ||
Line 23: | Line 26: | ||
}} | }} | ||
==''Local Configuration''== | |||
===''Editing Make.conf''=== | |||
{{file|name=/etc/portage/make.conf|desc=Portage make.conf file|body= | {{file|name=/etc/portage/make.conf|desc=Portage make.conf file|body= | ||
# /etc/portage/make.conf: | # /etc/portage/make.conf: | ||
Line 33: | Line 39: | ||
You ''WILL'' need to be updated to Funtoo-1.3-release and emerge the latest glib ebuild as it has fixed the static library creation needed to compile and run Qemu. | You ''WILL'' need to be updated to Funtoo-1.3-release and emerge the latest glib ebuild as it has fixed the static library creation needed to compile and run Qemu. | ||
}} | }} | ||
===''Building the Wrapper Binary''=== | |||
{{file|name=qemu-arm-wrapper.c|lang=C|desc=qemu arm wrapper|body= | {{file|name=qemu-arm-wrapper.c|lang=C|desc=qemu arm wrapper|body= | ||
Line 60: | Line 68: | ||
} | } | ||
}} | }} | ||
===''Setting up binfmt_misc''=== | |||
{{console|body= | {{console|body= | ||
Line 66: | Line 76: | ||
}} | }} | ||
{{file|name=masky.py|lang=python|desc=masky|body= | {{file|name=masky.py|lang=python|desc=masky|body= |
Revision as of 09:42, February 15, 2019
Funtoo binfmt_misc Qemu chroot Guide: aka (Frankenroot)
Setting Up Your Filesystem
Exporting Your Remote Mounts
/etc/exports
- NFS file systems being exported# /etc/exports: NFS file systems being exported. See exports(5).
/
192.168.0.0/24(insecure,no_root_squash,nohide,rw,sync,no_subtree_check)
/boot/
192.168.0.0/24(insecure,no_root_squash,nohide,rw,sync,no_subtree_check)
/dev/
192.168.0.0/24(insecure,no_root_squash,nohide,rw,sync,no_subtree_check,fsid=77)
Mount Your Remote Mounts Locally and Setup Psuedo Filesystem
root # mount foo.local:/ /mnt/piroot root # mount -t proc /proc /mnt/piroot/proc root # mount --rbind /sys /mnt/piroot/{sys,dev} root # mount --make-rslave /mnt/piroot/{sys,dev} root # mount -t devpts none /mnt/piroot/dev/pts
Tip
(For Better Performance!) mount a tmpfs on top of /mnt/piroot/var/tmp/portage
Local Configuration
Editing Make.conf
/etc/portage/make.conf
- Portage make.conf file# /etc/portage/make.conf:
QEMU_USER_TARGETS="aarch64 arm"
FEATURES="-sandbox -ipc-sandbox -usersandbox candy"
Warning
You WILL need to be updated to Funtoo-1.3-release and emerge the latest glib ebuild as it has fixed the static library creation needed to compile and run Qemu.
Building the Wrapper Binary
qemu-arm-wrapper.c
(C source code) - qemu arm wrapper/*
* Call QEMU binary with additional "-cpu cortex-a7" argument.
*
* Copyright (c) 2018 sakaki <sakaki@deciban.com>
* License: GPL v3.0+
*
* Based on code from the Gentoo Embedded Handbook
* ("General/Compiling_with_qemu_user_chroot")
*/
#include <string.h>
#include <unistd.h>
int main(int argc, char **argv, char **envp) {
char *newargv[argc + 3];
newargv[0] = argv[0];
newargv[1] = "-cpu";
newargv[2] = "cortex-a7";
memcpy(&newargv[3], &argv[1], sizeof(*argv) * (argc -1));
newargv[argc + 2] = NULL;
return execve("/usr/local/bin/qemu-arm", newargv, envp);
}
Setting up binfmt_misc
root # echo ":arm:M::\x7f\x45\x4c\x46\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28:\xff\xff\xff\xff\xff\xff\xff\xfc\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/local/bin/qemu-arm-wrapper:" > /proc/sys/fs/binfmt_misc/register
masky.py
(python source code) - masky#!/usr/bin/python3
import sys
import struct
import string
import codecs
printable_chars = set(string.printable)
printable_chars = set()
def print_out_hexstring(hexstring):
to_process = hexstring
while len(to_process):
ascii_value = chr(int(to_process[:2], 16))
to_process = to_process[2:]
if ascii_value in printable_chars:
sys.stdout.write(ascii_value)
else:
sys.stdout.write("\\x" + "{0:02x}".format(ord(ascii_value)))
chunk_as_hexstring = ""
with open(sys.argv[1], 'rb') as f:
for x in range(0,19):
chunk_as_hexstring += f.read(1).hex()
mask_as_hexstring = "fffffffffffffffcfffffffffffffffffeffff"
mask = int(mask_as_hexstring, 16)
chunk = int(chunk_as_hexstring, 16)
out_as_hexstring = hex(chunk & mask)[2:]
sys.stdout.write(":arm:M::")
print_out_hexstring(out_as_hexstring)
sys.stdout.write(":")
print_out_hexstring(mask_as_hexstring)
sys.stdout.write(":/usr/local/bin/qemu-arm-wrapper:\n")