Skip to content

Instantly share code, notes, and snippets.

@depau
Created August 23, 2019 02:30
Show Gist options
  • Save depau/6c0ccc7377949c68bb30608bef87b9cd to your computer and use it in GitHub Desktop.
Save depau/6c0ccc7377949c68bb30608bef87b9cd to your computer and use it in GitHub Desktop.
Run Android-x68 on QEMU with emulated USB stick
#!/bin/bash
# By Chih-Wei Huang <[email protected]>
# License: GNU Generic Public License v2
continue_or_stop()
{
echo "Please Enter to continue or Ctrl-C to stop."
read
}
QEMU_ARCH=`uname -m`
QEMU=qemu-system-${QEMU_ARCH}
which $QEMU > /dev/null 2>&1 || QEMU=qemu-system-i386
if ! which $QEMU > /dev/null 2>&1; then
echo -e "Please install $QEMU to run the program.\n"
exit 1
fi
#cd ${OUT:-bliss-x86-11.7}
[ -e system.img ] && SYSTEMIMG=system.img || SYSTEMIMG=system.sfs
if [ -d data ]; then
if [ `id -u` -eq 0 ]; then
DATA="-virtfs local,id=data,path=data,security_model=passthrough,mount_tag=data"
DATADEV='DATA=9p'
else
echo -e "\n$(realpath data) subfolder exists.\nIf you want to save data to it, run $0 as root:\n\n$ sudo $0\n"
continue_or_stop
fi
elif [ -e data.img ]; then
if [ -w data.img ]; then
DATA="-drive index=2,if=virtio,id=data,file=data.img"
DATADEV='DATA=vdc'
else
echo -e "\n$(realpath data.img) exists but is not writable.\nPlease grant the write permission if you want to save data to it.\n"
continue_or_stop
fi
fi
run_qemu_on_port()
{
$QEMU -enable-kvm \
-kernel kernel \
-append "root=/dev/ram0 androidboot.selinux=permissive androidboot.hardware=android_x86_64 console=ttyS0 RAMDISK=vdb $DATADEV" \
-initrd initrd.img \
-m 2048 -smp 2 -cpu host \
-usb -device usb-tablet,bus=usb-bus.0 \
-soundhw ac97 \
-boot menu=on \
-drive index=0,if=virtio,id=system,file=$SYSTEMIMG,format=raw,readonly \
-drive index=1,if=virtio,id=ramdisk,file=ramdisk.img,format=raw,readonly \
-netdev user,id=mynet,hostfwd=tcp::$port-:5555 -device virtio-net-pci,netdev=mynet \
-serial mon:stdio \
-device nec-usb-xhci,id=xhci \
-drive if=none,id=usbstick,file=usb.img,format=raw \
-device usb-storage,bus=xhci.0,drive=usbstick \
$DATA $@
}
#-machine vmport=off \
run_qemu()
{
port=5555
while [ $port -lt 5600 ]; do
run_qemu_on_port $@ && break
let port++
done
}
# Try to run QEMU in several VGA modes
#run_qemu -vga virtio -display sdl,gl=on $@ || \
run_qemu -vga qxl -display sdl,gl=on $@ -serial mon:stdio || \
run_qemu -vga std -display sdl $@ || \
run_qemu $@
@brunoaduarte
Copy link

brunoaduarte commented Feb 18, 2021

Is it possible that instead of a "data.img" file, the emulated USB storage points to a folder on the host machine? Like a shared folder mapping.

@depau
Copy link
Author

depau commented Feb 18, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment