Skip to content

Preparation of the Virtual Machine (qemu)

Meliurwen edited this page May 14, 2018 · 3 revisions

You can release the mouse lock with L-CTRL + L-ALT or CTRL + ALT + G

Requirements

Packages:

  • qemu-system-arm (>= 2.11)

Recommended distros:

  • Ubuntu 18.04 or higher
  • Debian 10 Buster or higher

Install qemu

On Debian and Debian-based distros:

sudo apt install qemu-system-arm

Install the Virtual Machine

Create the directories that will host our virtual machine's files:

mkdir ~/rasp-qemu && mkdir ~/rasp-qemu/qemu-rpi-kernel

Move into qemu-rpi-kernel folder and download the patched kernel and its .dtb:

cd ~/rasp-qemu/qemu-rpi-kernel
wget https://github.com/dhruvvyas90/qemu-rpi-kernel/raw/master/kernel-qemu-4.9.59-stretch
wget https://github.com/dhruvvyas90/qemu-rpi-kernel/raw/master/versatile-pb.dtb

Move to the parent folder:

cd ..

Create an executable file and give execution permission:

echo "qemu-system-arm -kernel ./qemu-rpi-kernel/kernel-qemu-4.9.59-stretch \
                   -append 'root=/dev/sda2 panic=1 rootfstype=ext4 rw' \
                   -hda 2018-03-13-raspbian-stretch-lite.img \
                   -cpu arm1176 \
                   -m 256 \
                   -machine versatilepb \
                   -no-reboot \
                   -serial stdio \
                   -dtb ./qemu-rpi-kernel/versatile-pb.dtb \
                   -net nic -net user,hostfwd=tcp::2222-:22" > coderbot.sh && chmod +x coderbot.sh

Execute the .sh file, et voilà!

./coderbot.sh

Enable SSH Key-Based Authentication

Create the keys in keys folder:

mkdir keys && ssh-keygen -t rsa -b 2048 -q -f keys/rpi_key -P ""

Pass the public key to the Raspberry trough SSH:

ssh-copy-id pi@localhost -i keys/rpi_key.pub -p 2222

Now we should be able to login:

ssh pi@localhost -p 2222 -i ~/rasp-qemu/keys/rpi_key