Skip to content

Instantly share code, notes, and snippets.

@bradfa
Last active June 14, 2023 11:14
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save bradfa/46ceff759a0cf9f392cc069c4f0f095a to your computer and use it in GitHub Desktop.
Save bradfa/46ceff759a0cf9f392cc069c4f0f095a to your computer and use it in GitHub Desktop.
mips64el Debian QEMU install

Installing Debian Stretch mips64el Using QEMU

We're going to emulate the mips64el "malta" machine and install Debian Stretch using QEMU on a amd64 Debian Buster host.

Likely you need your user to be in the "libvirt" group and have installed these packages (or a subset of such):

sudo apt install qemu-system-mips virt-manager libguestfs-tools

Create a directory to store the files in:

mkdir qemu-mips64el
cd qemu-mips64el

Get the stretch mips64el installer kernel and mips64el installer initrd for the malta board:

wget -O vmlinux-4.9.0-7-5kc-malta-installer http://http.us.debian.org/debian/dists/stretch/main/installer-mips64el/20170615+deb9u4/images/malta/netboot/vmlinux-4.9.0-7-5kc-malta
wget -O initrd-4.9.0-7-5kc-malta.gz-installer http://http.us.debian.org/debian/dists/stretch/main/installer-mips64el/20170615+deb9u4/images/malta/netboot/initrd.gz

Create a qcow2 disk file to use as the hard disk:

qemu-img create -f qcow2 hda.qcow2 10G

Start the installer with 256 MB of RAM using the downloaded files and qcow2 disk image from above:

qemu-system-mips64el \
	-machine malta \
	-m 256 \
	-cpu 5KEc \
	-kernel vmlinux-4.9.0-7-5kc-malta-installer \
	-initrd initrd-4.9.0-7-5kc-malta.gz-installer \
	-drive if=none,file=hda.qcow2,format=qcow2,id=hd \
	-device virtio-blk-pci,drive=hd \
	-netdev user,id=qemunet \
	-device virtio-net-pci,netdev=qemunet \
	-nographic \
	-no-reboot \
	-append "console=ttyS0"

Go through the installer prompts how ever you like for setting up a Debian system. At the end the QEMU machine should shut down instead of rebooting due to the -no-reboot option, which is what we want.

To actually boot your Debian machine you'll need to obtain the kernel and initrd used for normal boots. See how the qcow2 image was partitioned:

virt-filesystems -a hda.qcow2

I chose the defaults during install so I only have one big /dev/sda1 partition. We can list the files in this partition within the qcow2 file like:

virt-ls -a hda.qcow2 /boot/

Extract the kernel and initrd from the qcow2 like:

virt-copy-out -a hda.qcow2 /boot/initrd.img-4.9.0-7-5kc-malta /boot/vmlinux-4.9.0-7-5kc-malta .

Now boot your mips64el Debian machine using the copied out kernel and initrd, we have to also specify to the kernel how to find the root file system which will be at /dev/vda1 in my case (as above):

qemu-system-mips64el \
	-machine malta \
	-m 256 \
	-cpu 5KEc \
	-kernel vmlinux-4.9.0-7-5kc-malta \
	-initrd initrd.img-4.9.0-7-5kc-malta \
	-drive if=none,file=hda.qcow2,format=qcow2,id=hd \
	-device virtio-blk-pci,drive=hd \
	-netdev user,id=qemunet \
	-device virtio-net-pci,netdev=qemunet \
	-nographic \
	-no-reboot \
	-append "console=ttyS0 root=/dev/vda1"

The downside of doing networking like above is that you're quite limited. I happen to have a network bridge on my desktop for other reasons and I want to bridge my QEMU guest to that. To do this we first have to create a tap network interface, connect the tap to the bridge, then tell QEMU to use it (and likely you'll need to run qemu-system-mips64el as root now):

First setup the tap0 network interface and add it to the br0 bridge:

sudo ip tuntap add tap0 mode tap user `whoami`
sudo ip link set tap0 up
sudo ip link set tap0 master br0

Now launch your QEMU like before but change the networking options to use tap0 and not leverage QEMU's normal scripting features (since we manually setup the tap0 device) like:

sudo qemu-system-mips64el \
	-machine malta \
	-m 256 \
	-cpu 5KEc \
	-kernel vmlinux-4.9.0-7-5kc-malta \
	-initrd initrd.img-4.9.0-7-5kc-malta \
	-drive if=none,file=hda.qcow2,format=qcow2,id=hd \
	-device virtio-blk-pci,drive=hd \
	-netdev tap,id=qemunet,ifname=tap0,script=no,downscript=no \
	-device virtio-net-pci,netdev=qemunet \
	-nographic \
	-no-reboot \
	-append "console=ttyS0 root=/dev/vda1"

If you want to pass in a USB device from the host to the guest (example shows passing bus 1 device 18 through), add the following options to the end of your qemu-system command line (and you'll probably again need to run qemu as root):

-usb -device usb-host,hostbus=1,hostaddr=18

If you don't want to pass an entire bus or address but instead a VID/PID combo, do it like (but use the proper VID/PID):

-usb -device usb-host,vendorid=0x1234,productid=0x4321
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment