Building a Debian Stretch (9) QEMU image running MIPSel
TL;DR Two new images, Debian Stretch on MIPSel and MIPS64el were added to my QEMU image repo The rest of this post explains how I built them.
As @Fox0x01 already covered fairly exhaustively how to build an QEMU ARMv6 compatible VM , through this blog post I intend to provide a step-by-step how-to on building a Debian Stretch Malta MIPS32el image.
Note: there is no miracle here, I’ve just spend a long time googling for solution every time I was facing a problem. This tuto is more for a being a personal reminder for the future times I need to build an image :)
For the Debian MIPS net installer, the
initrd is the installation
device. No need to download any ISO or such, simply download:
- the initrd (the distro installer):
- a kernel to boot on:
You also need a hard drive to install the OS on:
Since we’re using the Debian net installer, we will need an Internet connection. Also don’t be surprised to see your CPU activity jump up and your fans get louder!
Start the installation with:
The kernel boot option
nokaslr is required or you’ll get an error when the
kernel will try to decompress
initrd. The reason is:
[…] that QEMU loads the initrd into the memory immediately after the kernel, but that bit of memory might get overwritten by KASLR when the kernel starts and relocates itself. You can workaround it by passing “-append nokaslr” to QEMU, […]
Then your MIPSel (Malta-flavor) system boots, and you end up in the regular
ncurses Debian installer.
Let the installer do its magic.
Since it’s a VM for test and lab stuff, the guided partitionning is more than
enough (and select
All files in one partition). Feel free to tweak that part.
I usually install only the minimum OS to get a running shell once I boot. For
there I install everything from
apt-get. With a proper
installed, I then create 2 scripts:
start.shwith all the good QEMU parameters, to launch the VM in non-graphic mode, and set up the port forward on tcp/22
ssh.shto connect to the VM.
Debian will detect no boot loader, and show the following warning:
So remember to append
-append option before running your
Then the installation will finish successfully:
Fixing the last quirks
If you try to boot directly the VM by simply removing the
-initrd line, the
kernel will panic like this:
We must extract the
initrd image from the installation: to do so you must
mounting the QEMU disk via the
Network Block Device
Extract the initramfs file (
And unmount the NBD device.
You can now boot the VM with the following command:
On all the images I’ve created, Debian doesn’t properly DHCP the Ethernet
interface (get a wrong name for the interface), so it must be done manually at
the first boot (use
ip -a to show the interface name):
You can now use the
start.sh script to init the VM, and
ssh.sh to SSH to it
start.sh usually looks like
For Windows, simply convert
script.sh to Batch.
Download the new images
Since I’ve built in parallel a Malta MIPS32el and MIPS64el for this tutorial, both have been added to the folder on Mega.nz
The MIPS64el was created exactly the same way, except that QEMU required the proper CPU version to boot correctly:
The adequate files were downloaded from here
A few known issues
The kernel doesn’t boot the
initrd: from my experience on it, either your initrd is incorrect, or try to append proper kernel boot options (
WARNING: I/O thread spun for 1000 iterationsappears often: that’s a QEMU warning from
os_host_main_loop_wait()and the code provides a good description of the issue:
- For simplicity, I highly recommand to only use the official repo (from
mirrors.kernel.org). It might be a bit slower than your local mirror, but mirrors do not always mirror all the architectures generated by Debian maintainers.
That’s how you get started with making your own QEMU images. Debian, as the real hacker distro it is, is usually the one that works best for trying weird combination, and MIPS CPUs are very well supported. More posts will come on building other QEMU images for other ABI, which are not necesarily that easy to setup.
I hope you now have all the information to make your own QEMU images. Thanks for reading!
Note (2017-11-15): links updated
Share this post: