For System mode source code build/Qemu4 , refer to Qemu4 build --target-list ARM(bare bone and linux-user)/Intel(linux-user only) (KVM enabled) https://blog.csdn.net/hushui/article/details/97899484
The next part is for User mode/Qemu2 bianry test used for Chroot/ARM elf execution under X86 Linux.
Refer to https://wiki.gentoo.org/wiki/Crossdev_qemu-static-user-chroot
Host/Kernel needs to enable
Executable file formats / Emulations --->
[*] Kernel support for MISC binaries
zgrep CONFIG_BINFMT_MISC /proc/config.gz
CONFIG_BINFMT_MISC=y || CONFIG_BINFMT_MISC=m
Refer to https://unix.stackexchange.com/questions/41889/how-can-i-chroot-into-a-filesystem-with-a-different-architechture/177122#177122
chroot /mnt qemu-arm-static /bin/bash
>>>>>>>>>>
You can also look in /proc/sys/fs/binfmt_misc
if there exists a file qemu-arm
. If not restart the service binfmt_support
.
>>>>>>>>>
Refer ArchLinuxARM for sun4i_rootfs/AllWinner ARM executed on Host X86 through qemu-arm-static to https://www.veryarm.com/20136.html
echo ':arm:M::x7fELFx01x01x01x00x00x00x00x00x00x00x00x00x02x00x28x00:xffxffxffxffxffxffxffx00xffxffxffxffxffxffxffxffxfexffxffxff:/usr/bin/qemu-arm-static:' > /proc/sys/fs/binfmt_misc/register
echo ':armeb:M::x7fELFx01x02x01x00x00x00x00x00x00x00x00x00x00x02x00x28:xffxffxffxffxffxffxffx00xffxffxffxffxffxffxffxffxffxfexffxff:/usr/bin/qemu-arm-static:' > /proc/sys/fs/binfmt_misc/register
### apt install qemu-user-static (QEMU2.11) from Ubunt18.04.1/X86_64bit
lake@lake-Latitude-5491:~$ uname -a
Linux lake-Latitude-5491 4.15.0-29-generic #31-Ubuntu SMP Tue Jul 17 15:39:52 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
lake@lake-Latitude-5491:~$ cat /etc/issue
Ubuntu 18.04.1 LTS \n \l
lake@lake-Latitude-5491:~$ qemu-system-
qemu-system-aarch64 qemu-system-mips64el qemu-system-sh4eb
qemu-system-alpha qemu-system-mipsel qemu-system-sparc
qemu-system-arm qemu-system-moxie qemu-system-sparc64
qemu-system-cris qemu-system-nios2 qemu-system-tricore
qemu-system-i386 qemu-system-or1k qemu-system-unicore32
qemu-system-lm32 qemu-system-ppc qemu-system-x86_64
qemu-system-m68k qemu-system-ppc64 qemu-system-x86_64-spice
qemu-system-microblaze qemu-system-ppc64le qemu-system-xtensa
qemu-system-microblazeel qemu-system-ppcemb qemu-system-xtensaeb
qemu-system-mips qemu-system-s390x
qemu-system-mips64 qemu-system-sh4
lake@lake-Latitude-5491:~$ qemu-system-arm -version
QEMU emulator version 2.11.1(Debian 1:2.11+dfsg-1ubuntu7.10)
Copyright (c) 2003-2017 Fabrice Bellard and the QEMU Project developers
lake@lake-Latitude-5491:~$ qemu-system-aarch64 -version
QEMU emulator version 2.11.1(Debian 1:2.11+dfsg-1ubuntu7.10)
Copyright (c) 2003-2017 Fabrice Bellard and the QEMU Project developers
lake@lake-Latitude-5491:~$ sudo apt install qemu-user-static
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
libblkid1:i386 libcom-err2:i386 libmount1:i386 libsystemd0:i386
libudev1:i386 libuuid1:i386
Use 'sudo apt autoremove' to remove them.
The following packages will be REMOVED:
qemu-user-binfmt
The following NEW packages will be installed:
qemu-user-static
0 upgraded, 1 newly installed, 1 to remove and 793 not upgraded.
Need to get 10.0 MB of archives.
After this operation, 101 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://cn.archive.ubuntu.com/ubuntu bionic-updates/universe amd64 qemu-user-static amd64 1:2.11+dfsg-1ubuntu7.21 [10.0 MB]
Fetched 10.0 MB in 1min 20s (125 kB/s)
(Reading database ... 170406 files and directories currently installed.)
Removing qemu-user-binfmt (1:2.11+dfsg-1ubuntu7.10) ...
Selecting previously unselected package qemu-user-static.
(Reading database ... 170406 files and directories currently installed.)
Preparing to unpack .../qemu-user-static_1%3a2.11+dfsg-1ubuntu7.21_amd64.deb ...
Unpacking qemu-user-static (1:2.11+dfsg-1ubuntu7.21) ...
Setting up qemu-user-static (1:2.11+dfsg-1ubuntu7.21) ...
Processing triggers for man-db (2.8.3-2) ...
lake@lake-Latitude-5491:~$
lake@lake-Latitude-5491:~$ ls -l /usr/bin/ |grep qemu |grep static
-rwxr-xr-x 1 root root 3621200 Oct 15 17:23 qemu-aarch64-static
-rwxr-xr-x 1 root root 2943592 Oct 15 17:23 qemu-alpha-static
-rwxr-xr-x 1 root root 3551760 Oct 15 17:23 qemu-armeb-static
-rwxr-xr-x 1 root root 3543568 Oct 15 17:23 qemu-arm-static
-rwxr-xr-x 1 root root 2952456 Oct 15 17:23 qemu-cris-static
-rwxr-xr-x 1 root root 2980680 Oct 15 17:23 qemu-hppa-static
-rwxr-xr-x 1 root root 4091264 Oct 15 17:23 qemu-i386-static
-rwxr-xr-x 1 root root 3123976 Oct 15 17:23 qemu-m68k-static
-rwxr-xr-x 1 root root 2940680 Oct 15 17:23 qemu-microblazeel-static
-rwxr-xr-x 1 root root 2944776 Oct 15 17:23 qemu-microblaze-static
-rwxr-xr-x 1 root root 3500712 Oct 15 17:23 qemu-mips64el-static
-rwxr-xr-x 1 root root 3504808 Oct 15 17:23 qemu-mips64-static
-rwxr-xr-x 1 root root 3455848 Oct 15 17:23 qemu-mipsel-static
-rwxr-xr-x 1 root root 3504776 Oct 15 17:23 qemu-mipsn32el-static
-rwxr-xr-x 1 root root 3508872 Oct 15 17:23 qemu-mipsn32-static
-rwxr-xr-x 1 root root 3459944 Oct 15 17:23 qemu-mips-static
-rwxr-xr-x 1 root root 2909480 Oct 15 17:23 qemu-nios2-static
-rwxr-xr-x 1 root root 2902568 Oct 15 17:23 qemu-or1k-static
-rwxr-xr-x 1 root root 4074824 Oct 15 17:23 qemu-ppc64abi32-static
-rwxr-xr-x 1 root root 4058472 Oct 15 17:23 qemu-ppc64le-static
-rwxr-xr-x 1 root root 4066664 Oct 15 17:23 qemu-ppc64-static
-rwxr-xr-x 1 root root 4003304 Oct 15 17:23 qemu-ppc-static
-rwxr-xr-x 1 root root 3192424 Oct 15 17:23 qemu-s390x-static
-rwxr-xr-x 1 root root 2964328 Oct 15 17:23 qemu-sh4eb-static
-rwxr-xr-x 1 root root 2956136 Oct 15 17:23 qemu-sh4-static
-rwxr-xr-x 1 root root 3105800 Oct 15 17:23 qemu-sparc32plus-static
-rwxr-xr-x 1 root root 3105832 Oct 15 17:23 qemu-sparc64-static
-rwxr-xr-x 1 root root 3051784 Oct 15 17:23 qemu-sparc-static
-rwxr-xr-x 1 root root 2894376 Oct 15 17:23 qemu-tilegx-static
-rwxr-xr-x 1 root root 4074688 Oct 15 17:23 qemu-x86_64-static
### http://cdimage.ubuntu.com/ubuntu-base/releases/18.04/release/
### Magic of qemu-arm-static/qemu-aarch64-static for ubuntu-base-18.04-base-armhf/ubuntu-base-18.04-base-arm64
lake@lake-Latitude-5491:~/T3/ubuntu-base-18.04-base-arm64$ sudo cp /usr/bin/qemu-arm-static usr/bin/
lake@lake-Latitude-5491:~/T3/ubuntu-base-18.04-base-arm64$ sudo cp /usr/bin/qemu-aarch64-static usr/bin/
### Note host/linux /proc/sys/fs/binfmt_misc/register will register path of /usr/bin/qemu-arm-static for binfmt_misc.
Refer to https://wiki.gentoo.org/wiki/Embedded_Handbook/General/Compiling_with_qemu_user_chroot
lake@lake-Latitude-5491:~/T3/ubuntu-base-18.04-base-arm64$ cat ch-mount.sh
Refer to https://fuchsia.googlesource.com/third_party/qemu/+/v2.5.1/scripts/qemu-binfmt-conf.sh
#!/bin/bash
function mnt() {
echo "MOUNTING"
sudo mount -t proc /proc ${2}proc
sudo mount -t sysfs /sys ${2}sys
sudo mount -o bind /dev ${2}dev
sudo mount -o bind /run ${2}run
sudo mount --bind / ${2}host
#sudo mount -vt tmpfs shm ${2}dev/shm
#sudo mount -t /dev/shm ${2}dev/shm
sudo chroot ${2}
}
function umnt() {
echo "UNMOUNTING"
sudo umount ${2}proc
sudo umount ${2}sys
#sudo umount ${2}dev/shm
sudo umount ${2}dev
sudo umount ${2}run
sudo umount ${2}host
}
if [ "$1" == "-m" ] && [ -n "$2" ] ;
then
mnt $1 $2
elif [ "$1" == "-u" ] && [ -n "$2" ];
then
umnt $1 $2
else
echo ""
echo "Either 1'st, 2'nd or both parameters were missing"
echo ""
echo "1'st parameter can be one of these: -m(mount) OR -u(umount)"
echo "2'nd parameter is the full path of rootfs directory(with trailing '/')"
echo ""
echo "For example: ch-mount -m /media/sdcard/"
echo ""
echo 1st parameter : ${1}
echo 2nd parameter : ${2}
fi
lake@lake-Latitude-5491:~/T3/ubuntu-base-18.04-base-arm64$ sudo mkdir host
##
### Copy Host DNS
lake@lake-Latitude-5491:~/T3/ubuntu-base-18.04-base-arm64$ sudo cp /etc/resolv.conf etc/
lake@lake-Latitude-5491:~/T3/ubuntu-base-18.04-base-arm64$ uname -a
Linux lake-Latitude-5491 4.15.0-29-generic #31-Ubuntu SMP Tue Jul 17 15:39:52 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
lake@lake-Latitude-5491:~/T3/ubuntu-base-18.04-base-arm64$ sudo ./ch-mount.sh -m `pwd`/
MOUNTING
root@lake-Latitude-5491:/# uname -a
Linux lake-Latitude-5491 4.15.0-29-generic #31-Ubuntu SMP Tue Jul 17 15:39:52 UTC 2018 aarch64 aarch64 aarch64 GNU/Linux
root@lake-Latitude-5491:/# df <<<< Exec ARM binary
Filesystem 1K-blocks Used Available Use% Mounted on
udev 16333472 0 16333472 0% /dev
tmpfs 3272824 3164 3269660 1% /run
/dev/nvme0n1p3 279787512 240220384 25331688 91% /host
root@lake-Latitude-5491:/# ls -l host ==> X86_64 host Ubuntu18
total 132
drwxr-xr-x 2 root root 4096 Mar 7 2019 bin
drwxr-xr-x 4 root root 4096 Apr 29 2019 boot
drwxr-xr-x 2 root root 4096 Jan 29 2019 cdrom
drwxr-xr-x 4 root root 4096 Jul 25 2018 dev
drwxr-xr-x 144 root root 12288 Dec 28 08:12 etc
drwxr-xr-x 3 root root 4096 Apr 13 2019 home
lrwxrwxrwx 1 root root 33 Jan 29 2019 initrd.img -> boot/initrd.img-4.15.0-29-generic
lrwxrwxrwx 1 root root 33 Jan 29 2019 initrd.img.old -> boot/initrd.img-4.15.0-29-generic
drwxr-xr-x 24 root root 4096 Mar 8 2019 lib
drwxr-xr-x 2 root root 4096 Jan 29 2019 lib32
drwxr-xr-x 2 root root 4096 Jul 25 2018 lib64
drwxr-xr-x 2 root root 4096 Jan 29 2019 libx32
drwx------ 2 root root 4096 Jan 29 2019 lost+found
drwxr-xr-x 3 root root 4096 Jan 29 2019 media
drwxr-xr-x 6 root root 4096 Dec 28 02:30 mnt
drwxr-xr-x 3 root root 4096 Jan 29 2019 opt
drwxr-xr-x 2 root root 4096 Apr 24 2018 proc
drwx------ 4 root root 4096 Nov 16 11:03 root
drwxr-xr-x 15 root root 4096 Apr 30 2019 run
drwxr-xr-x 2 root root 12288 Mar 8 2019 sbin
drwxr-xr-x 12 root root 4096 Mar 19 2019 snap
drwxr-xr-x 2 root root 4096 Jul 25 2018 srv
drwxr-xr-x 2 root root 4096 Apr 24 2018 sys
drwxrwxrwt 16 root root 20480 Jan 1 06:17 tmp
drwxr-xr-x 15 root root 4096 Mar 8 2019 usr
drwxr-xr-x 14 root root 4096 Jul 25 2018 var
lrwxrwxrwx 1 root root 30 Jan 29 2019 vmlinuz -> boot/vmlinuz-4.15.0-29-generic
root@lake-Latitude-5491:/# which init <<<< Issue no init/systemd in ubuntu-base-18.04-base-arm64/armhf
root@lake-Latitude-5491:/# which systemd
root@lake-Latitude-5491:/# which busybox
root@lake-Latitude-5491:/# which ps
/bin/ps
root@lake-Latitude-5491:/# which init
root@lake-Latitude-5491:/#
root@lake-Latitude-5491:/# apt list --installed |grep systemd <<<<< Ubuntu18/arm/default no systemd
WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
libsystemd0/bionic,now 237-3ubuntu10 arm64 [installed]
#### Note /etc/resolv.conf is copied from Host
root@lake-Latitude-5491:/# ifconfig
0: error fetching interface information: Device not found <<<<< Not a issue.
root@lake-Latitude-5491:/# ping www.baidu.com
PING www.a.shifen.com (180.101.49.12) 56(84) bytes of data.
64 bytes from 180.101.49.12 (180.101.49.12): icmp_seq=1 ttl=54 time=7.53 ms
64 bytes from 180.101.49.12 (180.101.49.12): icmp_seq=2 ttl=54 time=6.83 ms
^C
--- www.a.shifen.com ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1002ms
rtt min/avg/max/mdev = 6.837/7.185/7.534/0.358 ms
root@lake-Latitude-5491:/# apt install vim
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
libgpm2 libpython3.6 vim-common vim-runtime xxd
Suggested packages:
gpm ctags vim-doc vim-scripts
The following NEW packages will be installed:
libgpm2 libpython3.6 vim vim-common vim-runtime xxd
0 upgraded, 6 newly installed, 0 to remove and 0 not upgraded.
Need to get 7833 kB of archives.
After this operation, 37.0 MB of additional disk space will be used.
Do you want to continue? [Y/n]
### Ubuntu16/ARM/default
root@ShSwDev2:/# apt list --installed |grep systemd
WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
libsystemd0/xenial,now 229-4ubuntu4 armhf [installed]
systemd/xenial,now 229-4ubuntu4 armhf [installed]
systemd-sysv/xenial,now 229-4ubuntu4 armhf [installed]
##
### ARM package list
# sudo sudo
# ssh ssh client/server
# net-tools ifconfig,netstat,route,arp/
# ethtool ethtool
#wireless-tools iwconfig wireless tool
# ifupdown ifup,ifdown
#network-manager Network Manager
# iputils-ping ping/ping6
# rsyslog Syslog
#bash-completion bash
# htop htop tool
root@lake-Latitude-5491:/# apt install net-tools iputils-ping
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
libcap2 libcap2-bin libidn11 libpam-cap
The following NEW packages will be installed:
iputils-ping libcap2 libcap2-bin libidn11 libpam-cap net-tools
0 upgraded, 6 newly installed, 0 to remove and 51 not upgraded.
Need to get 306 kB of archives.
After this operation, 1252 kB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 http://ports.ubuntu.com/ubuntu-ports bionic/main arm64 libcap2 arm64 1:2.25-1.2 [12.2 kB]
Get:2 http://ports.ubuntu.com/ubuntu-ports bionic-updates/main arm64 libidn11 arm64 1.33-2.1ubuntu1.2 [44.0 kB]
Get:3 http://ports.ubuntu.com/ubuntu-ports bionic-updates/main arm64 iputils-ping arm64 3:20161105-1ubuntu3 [51.9 kB]
Get:4 http://ports.ubuntu.com/ubuntu-ports bionic/main arm64 libcap2-bin arm64 1:2.25-1.2 [19.8 kB]
Get:5 http://ports.ubuntu.com/ubuntu-ports bionic/main arm64 libpam-cap arm64 1:2.25-1.2 [7060 B]
Get:6 http://ports.ubuntu.com/ubuntu-ports bionic/main arm64 net-tools arm64 1.60+git20161116.90da8a0-1ubuntu1 [171 kB]
Fetched 306 kB in 13s (23.5 kB/s)
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
LANGUAGE = (unset),
LC_ALL = (unset),
LC_PAPER = "en_US.UTF-8",
LC_NUMERIC = "en_US.UTF-8",
LC_IDENTIFICATION = "en_US.UTF-8",
LC_MEASUREMENT = "en_US.UTF-8",
LC_NAME = "en_US.UTF-8",
LC_TELEPHONE = "en_US.UTF-8",
LC_ADDRESS = "en_US.UTF-8",
LC_MONETARY = "en_US.UTF-8",
LC_TIME = "en_US.UTF-8",
LANG = "en_US.UTF-8"
are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
debconf: delaying package configuration, since apt-utils is not installed
E: Can not write log (Is /dev/pts mounted?) - posix_openpt (19: No such device)
Selecting previously unselected package libcap2:arm64.
(Reading database ... 4026 files and directories currently installed.)
Preparing to unpack .../0-libcap2_1%3a2.25-1.2_arm64.deb ...
Unpacking libcap2:arm64 (1:2.25-1.2) ...
Selecting previously unselected package libidn11:arm64.
Preparing to unpack .../1-libidn11_1.33-2.1ubuntu1.2_arm64.deb ...
Unpacking libidn11:arm64 (1.33-2.1ubuntu1.2) ...
Selecting previously unselected package iputils-ping.
Preparing to unpack .../2-iputils-ping_3%3a20161105-1ubuntu3_arm64.deb ...
Unpacking iputils-ping (3:20161105-1ubuntu3) ...
Selecting previously unselected package libcap2-bin.
Preparing to unpack .../3-libcap2-bin_1%3a2.25-1.2_arm64.deb ...
Unpacking libcap2-bin (1:2.25-1.2) ...
Selecting previously unselected package libpam-cap:arm64.
Preparing to unpack .../4-libpam-cap_1%3a2.25-1.2_arm64.deb ...
Unpacking libpam-cap:arm64 (1:2.25-1.2) ...
Selecting previously unselected package net-tools.
Preparing to unpack .../5-net-tools_1.60+git20161116.90da8a0-1ubuntu1_arm64.deb ...
Unpacking net-tools (1.60+git20161116.90da8a0-1ubuntu1) ...
Setting up libcap2:arm64 (1:2.25-1.2) ...
Processing triggers for libc-bin (2.27-3ubuntu1) ...
Setting up net-tools (1.60+git20161116.90da8a0-1ubuntu1) ...
Setting up libidn11:arm64 (1.33-2.1ubuntu1.2) ...
Setting up iputils-ping (3:20161105-1ubuntu3) ...
Setting up libpam-cap:arm64 (1:2.25-1.2) ...
debconf: unable to initialize frontend: Dialog
debconf: (No usable dialog-like program is installed, so the dialog based frontend cannot be used. at /usr/share/perl5/Debconf/FrontEnd/Dialog.pm line 76.)
debconf: falling back to frontend: Readline
debconf: unable to initialize frontend: Readline
debconf: (Can't locate Term/ReadLine.pm in @INC (you may need to install the Term::ReadLine module) (@INC contains: /etc/perl /usr/local/lib/aarch64-linux-gnu/perl/5.26.1 /usr/local/share/perl/5.26.1 /usr/lib/aarch64-linux-gnu/perl5/5.26 /usr/share/perl5 /usr/lib/aarch64-linux-gnu/perl/5.26 /usr/share/perl/5.26 /usr/local/lib/site_perl /usr/lib/aarch64-linux-gnu/perl-base) at /usr/share/perl5/Debconf/FrontEnd/Readline.pm line 7.)
debconf: falling back to frontend: Teletype
Setting up libcap2-bin (1:2.25-1.2) ...
Processing triggers for libc-bin (2.27-3ubuntu1) ...
root@lake-Latitude-5491:/# ifconfig
: error fetching interface information: Device not found
root@lake-Latitude-5491:/# ifconfig -a
: error fetching interface information: Device not found
root@lake-Latitude-5491:/#
Refer to https://www.jianshu.com/p/67cb69b55377
change /etc/apt/sources.list
中科大源
deb http://mirrors.ustc.edu.cn/ubuntu-ports/ xenial main multiverse restricted universe
清华源
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ xenial main multiverse restricted universe
#Ali yun的apt源
deb https://mirrors.aliyun.com/ubuntu-ports xenial main restricted universe multiverse
root@lake-Latitude-5491:/# exit
lake@lake-Latitude-5491:~/T3/ubuntu-base-18.04-base-arm64$ sudo ./ch-mount.sh -u `pwd`/
[sudo] password for lake:
UNMOUNTING
lake@lake-Latitude-5491:~/T3/ubuntu-base-18.04-base-arm64$
lake@lake-Latitude-5491:~/T3/ubuntu-base-18.04-base-arm64$