-
Notifications
You must be signed in to change notification settings - Fork 390
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
153: Add support to use qemu-system to run linux aarch64 binaries r=Dylan-DPC a=malbarbo Fixes #146 Co-authored-by: Marco A L Barbosa <malbarbo@gmail.com>
- Loading branch information
Showing
9 changed files
with
437 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
set -ex | ||
|
||
main() { | ||
local version=2017.75 \ | ||
td=$(mktemp -d) | ||
|
||
local dependencies=( | ||
autoconf | ||
automake | ||
bzip2 | ||
curl | ||
make | ||
zlib1g-dev | ||
) | ||
|
||
apt-get update | ||
local purge_list=() | ||
for dep in ${dependencies[@]}; do | ||
if ! dpkg -L $dep; then | ||
apt-get install --no-install-recommends -y $dep | ||
purge_list+=( $dep ) | ||
fi | ||
done | ||
|
||
pushd $td | ||
|
||
curl -L https://matt.ucc.asn.au/dropbear/dropbear-$version.tar.bz2 | \ | ||
tar --strip-components=1 -xj | ||
|
||
# Remove some unwanted message | ||
sed -i '/skipping hostkey/d' cli-kex.c | ||
sed -i '/failed to identify current user/d' cli-runopts.c | ||
|
||
./configure \ | ||
--disable-syslog \ | ||
--disable-shadow \ | ||
--disable-lastlog \ | ||
--disable-utmp \ | ||
--disable-utmpx \ | ||
--disable-wtmp \ | ||
--disable-wtmpx \ | ||
--disable-pututline \ | ||
--disable-pututxline | ||
|
||
nice make -j$(nproc) PROGRAMS=dbclient | ||
cp dbclient /usr/local/bin/ | ||
|
||
# Clean up | ||
apt-get purge --auto-remove -y ${purge_list[@]} | ||
|
||
popd | ||
|
||
rm -rf $td | ||
rm $0 | ||
} | ||
|
||
main "${@}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,179 @@ | ||
set -ex | ||
|
||
main() { | ||
# arch in the rust target | ||
local arch=$1 \ | ||
kversion=4.9.0-8 | ||
|
||
# select debian arch and kernel version | ||
case $arch in | ||
aarch64) | ||
arch=arm64 | ||
kernel=$kversion-arm64 | ||
;; | ||
*) | ||
echo "Invalid arch: $arch" | ||
exit 1 | ||
;; | ||
esac | ||
|
||
local dependencies=( | ||
cpio | ||
sharutils | ||
) | ||
|
||
local purge_list=() | ||
apt-get update | ||
for dep in ${dependencies[@]}; do | ||
if ! dpkg -L $dep; then | ||
apt-get install --no-install-recommends -y $dep | ||
purge_list+=( $dep ) | ||
fi | ||
done | ||
|
||
# Download packages | ||
mv /etc/apt/sources.list /etc/apt/sources.list.bak | ||
echo "deb http://http.debian.net/debian/ stretch main" > \ | ||
/etc/apt/sources.list | ||
echo "deb http://security.debian.org/ stretch/updates main" >> \ | ||
/etc/apt/sources.list | ||
|
||
# Old ubuntu does not support --add-architecture, so we directly change multiarch file | ||
if [ -f /etc/dpkg/dpkg.cfg.d/multiarch ]; then | ||
cp /etc/dpkg/dpkg.cfg.d/multiarch /etc/dpkg/dpkg.cfg.d/multiarch.bak | ||
fi | ||
dpkg --add-architecture $arch || echo "foreign-architecture $arch" > /etc/dpkg/dpkg.cfg.d/multiarch | ||
# Add debian keys | ||
apt-key adv --recv-key --keyserver keyserver.ubuntu.com EF0F382A1A7B6500 | ||
apt-key adv --recv-key --keyserver keyserver.ubuntu.com 9D6D8F6BC857C906 | ||
apt-key adv --recv-key --keyserver keyserver.ubuntu.com 8B48AD6246925553 | ||
apt-key adv --recv-key --keyserver keyserver.ubuntu.com 7638D0442B90D010 | ||
apt-get update | ||
|
||
mkdir -p -m 777 /qemu/$arch | ||
cd /qemu/$arch | ||
apt-get -t stretch -d --no-install-recommends download \ | ||
busybox:$arch \ | ||
dropbear-bin:$arch \ | ||
libc6:$arch \ | ||
libgcc1:$arch \ | ||
libssl1*:$arch \ | ||
libstdc++6:$arch \ | ||
linux-image-$kernel:$arch \ | ||
ncurses-base \ | ||
zlib1g:$arch | ||
cd /qemu | ||
|
||
# Install packages | ||
root=root-$arch | ||
mkdir -p $root/{bin,etc/dropbear,root,sys,dev,proc,sbin,usr/{bin,sbin},var/log} | ||
for deb in $arch/*deb; do | ||
dpkg -x $deb $root/ | ||
done | ||
|
||
# kernel | ||
cp $root/boot/vmlinu* kernel | ||
|
||
# initrd | ||
mkdir -p $root/modules | ||
cp \ | ||
$root/lib/modules/*/kernel/drivers/net/virtio_net.ko \ | ||
$root/lib/modules/*/kernel/drivers/virtio/* \ | ||
$root/lib/modules/*/kernel/fs/9p/9p.ko \ | ||
$root/lib/modules/*/kernel/fs/fscache/fscache.ko \ | ||
$root/lib/modules/*/kernel/net/9p/9pnet.ko \ | ||
$root/lib/modules/*/kernel/net/9p/9pnet_virtio.ko \ | ||
$root/modules || true # some file may not exist | ||
rm -rf $root/boot | ||
rm -rf $root/lib/modules | ||
|
||
cat << 'EOF' > $root/etc/hosts | ||
127.0.0.1 localhost qemu | ||
EOF | ||
|
||
cat << 'EOF' > $root/etc/hostname | ||
qemu | ||
EOF | ||
|
||
cat << 'EOF' > $root/etc/passwd | ||
root::0:0:root:/root:/bin/sh | ||
EOF | ||
|
||
cat << 'EOF' | uudecode -o $root/etc/dropbear/dropbear_rsa_host_key | ||
begin 600 dropbear_rsa_host_key | ||
M````!W-S:"UR<V$````#`0`!```!`0"N!-<%K,3Z.!Z,OEMB2.N\O.$IWQ*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=@D]1 | ||
H_&DE8Y(OT%%EPG]!$H&5HX*),_D1A2\P=R.7G'`0L%YM-79Y"T">$0`` | ||
` | ||
end | ||
EOF | ||
|
||
# dropbear complains when this file is missing | ||
touch $root/var/log/lastlog | ||
|
||
cat << 'EOF' > $root/init | ||
#!/bin/busybox sh | ||
set -e | ||
/bin/busybox --install | ||
mount -t devtmpfs devtmpfs /dev | ||
mount -t proc none /proc | ||
mount -t sysfs none /sys | ||
mkdir /dev/pts | ||
mount -t devpts none /dev/pts/ | ||
# some archs does not have virtio modules | ||
insmod /modules/virtio.ko || true | ||
insmod /modules/virtio_ring.ko || true | ||
insmod /modules/virtio_mmio.ko || true | ||
insmod /modules/virtio_pci.ko || true | ||
insmod /modules/virtio_net.ko || true | ||
insmod /modules/fscache.ko | ||
insmod /modules/9pnet.ko | ||
insmod /modules/9pnet_virtio.ko || true | ||
insmod /modules/9p.ko | ||
ifconfig lo 127.0.0.1 | ||
ifconfig eth0 10.0.2.15 | ||
route add default gw 10.0.2.2 eth0 | ||
mkdir /target | ||
mount -t 9p -o trans=virtio target /target -oversion=9p2000.L || true | ||
exec dropbear -F -E -B | ||
EOF | ||
|
||
chmod +x $root/init | ||
cd $root && find . | cpio --create --format='newc' --quiet | gzip > ../initrd.gz | ||
|
||
# Clean up | ||
rm -rf /qemu/$root /qemu/$arch | ||
mv -f /etc/apt/sources.list.bak /etc/apt/sources.list | ||
if [ -f /etc/dpkg/dpkg.cfg.d/multiarch.bak ]; then | ||
mv /etc/dpkg/dpkg.cfg.d/multiarch.bak /etc/dpkg/dpkg.cfg.d/multiarch | ||
fi | ||
# can fail if arch is used (amd64 and/or i386) | ||
dpkg --remove-architecture $arch || true | ||
apt-get update | ||
apt-get purge --auto-remove -y ${purge_list[@]} | ||
ls -lh /qemu | ||
} | ||
|
||
main "${@}" |
Oops, something went wrong.