Update (2021)
Debian ended support MIPS big endian, as a result some links became broken. I have updated the link and you can still follow this tutorial for MIPS little endian..
How to set up and build your own MIPS big endian or little endian image running under the QEMU emulator. This guide can also be applied to other architectures. For example I’m currently running this in a virtual machine inside another virtual machine on my MacBook Pro. “We Need To Go Deeper” - Dom Cobb, Inception.
Install Package
Since we are only emulating a MIPS system on QEMU, we only require a specific package namely; qemu-system-mips. On most Linux distos you can simply install through apt-get. This will also install further packages required by QEMU:
$ sudo apt-get install qemu-system-mips
The exact version used: QEMU emulator version 2.8.1(Debian 1:2.8+dfsg-6+deb9u3).
Download files
There are two versions of the MIPS-32 (Big Endian Little Endian); Malta and Octeon. This guide will be using the Malta version. Although it’s almost the exact same process for Octeon with a few minor option differences. I have updated the links below to reflect the changes.
The Kernel filename may differ to one listed below. As the Debian team provides newer releases and updates, the filename will change over time. Link to Latest Stable.
Download both the installer and boot files from stable release:
- Installer (initrd.gz) ~21MB:
$ wget https://ftp.debian.org/debian/dists/stable/main/installer-mipsel/current/images/malta/netboot/initrd.gz
- Kernel boot (vmlinuz-5.10.0-8-4kc-malta) ~11MB:
$ wget https://ftp.debian.org/debian/dists/stable/main/installer-mipsel/current/images/malta/netboot/vmlinuz-5.10.0-8-4kc-malta
- Optional: Verify downloaded files with SHA256SUMS by manually comparing the hash values:
$ shasum -a 256 initrd.gz vmlinuz-5.10.0-8-4kc-malta
15376785c6146daf17b225e475b15c329e274e9cd91df3300d96dcf5aa334158 initrd.gz
c0e7e76ce2c12451ef63e5dfecdd577c3de84ef013f643e5addc01d7d79e6a45 vmlinuz-5.10.0-8-4kc-malta
Create an QEMU image file
Create an QEMU image file specifying its storage size and filetype to be used as installation media. The table below shows the minimal hardware requirements as per Debian official documentation: Link
Install Type | Minimum (RAM) | Recommended (RAM) | Storage No Desktop | 128MB | 512MB | 2GB Desktop | 256MB | 1GB | 10GB
Create an qcow2 format image with 2G of storage:
$ qemu-img create -f qcow2 hda.img 2G
Install Debian MIPS
Before starting make sure all three files (hda.img, vmlinux-4.9.0-6-4kc-malta and initrd.gz) are actually in the current working directory. The installation process is almost identical to the standard x86_64 or i386 architectures.
To start the installation type:
$ qemu-system-mips -M malta \
-m 256 -hda hda.img \
-kernel vmlinux-4.9.0-6-4kc-malta \
-initrd initrd.gz \
-append "console=ttyS0 nokaslr" \
-nographic
By default QEMU enables a NATed network interface for Internet connectivity through the hosts network. This allows the virtual machine to install and update packages.
Install SSH server
I highly recommend installing a SSH server so you can communicate with the host machine for uploading and downloading files whilst in a NATed network. The writer has yet to explore network bridging and other network connectivity. This will probably be the next post.
Installation Completed
Once you see this screen your installation has completed and it’s time to shutdown. Unfortunately, if you hit continue qemu will reboot right back into the installer. Therefore you’d either want to kill process or enter cli shell by selecting Go Back > Go Down > Execute Shell and type command poweroff
that will shutdown the virtual machine.
Copy over Kernel initrd.img file
During the installation stage you’ll see this screen warning us that no bootloader has been installed.
Before you can use the freshly installed MIPS image you first need to extract the Kernel initrd.img-[version] file found in the /boot partition of the image. We must manually copy it by mounting the image and executing a few commands.
- Mount the boot partition of the image file:
sudo modprobe nbd max_part=63
sudo qemu-nbd -c /dev/nbd0 hda.img
sudo mount /dev/nbd0p1 /mnt
- Copy a single file or the entire folder to the current directory:
cp -r /mnt/boot/initrd.img-4.9.0-6-4kc-malta . # copy only initrd.img file
cp -r /mnt/boot . # copy the entire boot folder
- Unmount the image:
sudo umount /mnt
sudo qemu-nbd -d /dev/nbd0
Running the QEMU image
Now that all the files have been configured and set up. It’s time to officially start the virtual machine. The following set of options can be changed to your liking. You could also make the following into a Bash script.
To start the image type:
$ qemu-system-mips -M malta \
-m 256 -hda hda.img \
-kernel vmlinux-4.9.0-6-4kc-malta \
-initrd initrd.img-4.9.0-6-4kc-malta \
-append "root=/dev/sda1 console=ttyS0 nokaslr" \
-nographic \
-device e1000-82545em,netdev=user.0 \
-netdev user,id=user.0,hostfwd=tcp::5555-:22
The last option enables port forwarding on host machine port 5555 to the guest machine on port 22 for ssh communication.
To access the guest machine from Host machine to upload a file:
$ scp -P 5555 file.txt root@localhost:/tmp
Or to connect via ssh:
$ ssh root@localhost -p 5555
The result
Thanks
A few other resources that were very helpful: