Skip to content

Instantly share code, notes, and snippets.

@sergev
Last active May 28, 2025 09:01
Show Gist options
  • Save sergev/86638b242bd516ad8c94d91ebfd42203 to your computer and use it in GitHub Desktop.
Save sergev/86638b242bd516ad8c94d91ebfd42203 to your computer and use it in GitHub Desktop.
Installing Debian MIPS32 on QEMU

Let's install Debian 9.0 "Stretch" on QEMU MIPS32 under Ubuntu.

Step 1: Install QEMU

sudo apt install qemu-system-mips

Step 2: Download Linux kernel and installation image

wget http://ftp.debian.org/debian/dists/stretch/main/installer-mipsel/current/images/malta/netboot/vmlinux-4.9.0-11-4kc-malta
wget http://ftp.debian.org/debian/dists/stretch/main/installer-mipsel/current/images/malta/netboot/initrd.gz

Step 3: Create a new hard disk

qemu-img create -f qcow2 hda.qcow 8G

Step 4: Install Debian

qemu-system-mipsel \
    -cpu    4KEc \
    -M      malta \
    -m      512 \
    -hda    hda.qcow \
    -kernel vmlinux-4.9.0-11-4kc-malta \
    -initrd initrd.gz \
    -append "root=/dev/sda1 nokaslr" \
    -nographic   

Proceed with the installation to complete.

Step 5: Extract starting image from disk

During installation process, the installer has created a initrd.img that contains all the needed drivers for booting the system. We need to extract this file from the disk. Utility qemu-nbd helps to mount the QEMU disk image.

sudo apt-get install qemu-utils
sudo modprobe nbd max_part=8
sudo qemu-nbd --connect=/dev/nbd0 hda.qcow 
sudo mount /dev/nbd0p1 /mnt
cp /mnt/boot/initrd.img-4.9.0-1-4kc-malta .
sudo umount /mnt
sudo qemu-nbd --disconnect /dev/nbd0

Step 6: Boot from disk

qemu-system-mipsel \
    -cpu    4KEc \
    -M      malta \
    -m      2048 \
    -hda    hda.qcow \
    -kernel vmlinux-4.9.0-11-4kc-malta \
    -initrd initrd.img-4.9.0-11-4kc-malta \
    -append root=/dev/sda1 \
    -nographic

See protocol-debian-mipsel for a protocol of booting the resulting system.

See device-tree-mipsel-on-qemu for a device tree.

@sergev
Copy link
Author

sergev commented Feb 8, 2024

after image extraction I also needed to run sudo qemu-nbd --disconnect /dev/nbd0

Thank you for noticing that! I will update the text.

@hugocotoflorez
Copy link

I found the following error while trying to download the kernel:

wget http://ftp.debian.org/debian/dists/stretch/main/installer-mipsel/current/images/malta/netboot/vmlinux-4.9.0-11-4kc-malta
--2025-05-28 08:49:05--  http://ftp.debian.org/debian/dists/stretch/main/installer-mipsel/current/images/malta/netboot/vmlinux-4.9.0-11-4kc-malta
Resolving ftp.debian.org (ftp.debian.org)... 151.101.130.132, 151.101.66.132, 151.101.2.132, ...
Connecting to ftp.debian.org (ftp.debian.org)|151.101.130.132|:80... connected.
HTTP request sent, awaiting response... 404 Not Found
2025-05-28 08:49:05 ERROR 404: Not Found.

the folder stretch is not in ./debian/dist/. I can solve it by selecting a valid debian version from here.

I also have to set -vga none to avoid an error on vga cirrus module. Note that I have to change the version in all the scripts.

Thanks for the tutorial, I get it running after solving this small issue.

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