Skip to content

Instantly share code, notes, and snippets.

@sergev
Last active August 30, 2024 15:08
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.

@geniot
Copy link

geniot commented Jan 7, 2024

Thank you for these instructions. I could install Debian MIPS 32. One thing I noticed: after image extraction I also needed to run
sudo qemu-nbd --disconnect /dev/nbd0
Otherwise my image file was locked:

qemu-system-mips: -hda mips.img: Failed to get "write" lock
Is another process using the image [mips.img]?

@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.

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