Skip to content

Instantly share code, notes, and snippets.

@cellularmitosis
Last active April 3, 2025 01:03
Show Gist options
  • Save cellularmitosis/54d3cc18e1b128b9286d7ceed3c5bdb7 to your computer and use it in GitHub Desktop.
Save cellularmitosis/54d3cc18e1b128b9286d7ceed3c5bdb7 to your computer and use it in GitHub Desktop.
Quick-n-dirty QEMU script to spin up Debian on various CPU's

Blog 2020/9/1

<- previous | index | next ->

Quick-n-dirty QEMU script to spin up Debian on various CPU's

updated 2025/4/2

This script downloads one of the QEMU images from https://people.debian.org/~aurel32/qemu/ and boots up a vm.

(unfortunately, these are all wheezy images, which is quite old now, but still useful for e.g. compiling a C file or running a binary)

Usage examples:

qemu.sh mips
qemu.sh ppc
qemu.sh arm
qemu.sh x86
qemu.sh x64

Notes:

  • The root account password is root
  • There is a user account named user with password user
  • Port 22 is port-forwarded to 2222, try ssh -p 2222 user@localhost

Tips:

  • The debian packages for wheezy have moved to archive.debian.org. You can echo deb http://archive.debian.org/debian wheezy main > /etc/apt/sources.list, but be aware that there are no more security updates for wheezy.
  • apt-get remove bash-completion (too laggy under emulation)
#!/bin/bash
# A bash script to download and run a debian on mips, ppc, arm, x86 or x64 using qemu.
# Copyright 2020 Jason Pepas
# Released under the MIT license, see https://opensource.org/license/mit
# Usage:
# $ qemu.sh mips
# $ qemu.sh ppc
# $ qemu.sh arm
# $ qemu.sh x86
# $ qemu.sh x64
# Note: any additional arguments are passed to qemu itself, e.g.:
# $ qemu.sh mips -vnc
# The root password is 'root', the account 'user' has password 'user'.
# SSH via 'ssh -p 2222 user@localhost'.
# Tips:
# - Debian packages for wheezy have been moved to archive.debian.org, try:
# 'echo deb http://archive.debian.org/debian wheezy main > /etc/apt/sources.list'.
# - The smart bash-completion package is slow under qemu, try:
# 'apt-get remove bash-completion'.
set -e -o pipefail
RAM=256M
function notes {
echo "Notes:"
echo "- The root password is 'root'."
echo "- There is a user account named 'user' with password 'user'."
echo "- Port 22 is port-forwarded to 2222, try 'ssh -p 2222 user@localhost'."
echo "- Debian packages for wheezy have been moved to archive.debian.org, try:"
echo " 'echo deb http://archive.debian.org/debian wheezy main > /etc/apt/sources.list'"
echo "- The smart bash-completion package is slow under qemu, try:"
echo " 'apt-get remove bash-completion'"
echo "- Shutdown via 'su -' (password 'root'), then 'poweroff'."
echo "Starting qemu with $RAM RAM."
}
if ! which qemu-system-mipsel >/dev/null ||
! which qemu-system-ppc >/dev/null ||
! which qemu-system-arm >/dev/null ||
! which qemu-system-i386 >/dev/null ||
! which qemu-system-x86_64 >/dev/null
then
if test "$(uname -s)" = "Darwin"; then
echo "Installing qemu"
echo "$ brew install qemu"
brew install qemu
elif test "$(uname -s)" = "Linux"; then
echo "Installing qemu"
echo "$ sudo apt-get install qemu-system"
sudo apt-get install qemu-system
else
echo "Error: please install qemu" >&2
exit 1
fi
fi
if test "$1" = "mips" -o "$1" = "mipsel"; then
shift
mkdir -p ~/.qemu.sh/wheezy/mipsel
cd ~/.qemu.sh/wheezy/mipsel
if test ! -e debian_wheezy_mipsel_standard.qcow2 ; then
url='https://people.debian.org/~aurel32/qemu/mipsel/debian_wheezy_mipsel_standard.qcow2'
echo "Fetching disk image"
echo "$ curl -fLO $url"
curl -fLO $url
fi
if test ! -e vmlinux-3.2.0-4-4kc-malta ; then
url='https://people.debian.org/~aurel32/qemu/mipsel/vmlinux-3.2.0-4-4kc-malta'
echo "Fetching kernel"
echo "$ curl -fLO $url"
curl -fLO $url
fi
notes
qemu-system-mipsel \
-m $RAM \
-M malta -kernel vmlinux-3.2.0-4-4kc-malta \
-hda debian_wheezy_mipsel_standard.qcow2 \
-net nic -net user,hostfwd=tcp::2222-:22 \
-nographic -no-reboot -append "root=/dev/sda1" $@
elif test "$1" = "ppc" -o "$1" = "powerpc"; then
shift
mkdir -p ~/.qemu.sh/wheezy/powerpc
cd ~/.qemu.sh/wheezy/powerpc
if test ! -e debian_wheezy_powerpc_standard.qcow2 ; then
url='https://people.debian.org/~aurel32/qemu/powerpc/debian_wheezy_powerpc_standard.qcow2'
echo "Fetching disk image"
echo "$ curl -fLO $url"
curl -fLO $url
fi
notes
qemu-system-ppc \
-m $RAM \
-hda debian_wheezy_powerpc_standard.qcow2 \
-net nic -net user,hostfwd=tcp::2222-:22 \
-nographic -no-reboot $@
elif test "$1" = "arm" -o "$1" = "armel"; then
shift
mkdir -p ~/.qemu.sh/wheezy/armel
cd ~/.qemu.sh/wheezy/armel
if test ! -e debian_wheezy_armel_standard.qcow2 ; then
url='https://people.debian.org/~aurel32/qemu/armel/debian_wheezy_armel_standard.qcow2'
echo "Fetching disk image"
echo "$ curl -fLO $url"
curl -fLO $url
fi
if test ! -e initrd.img-3.2.0-4-versatile ; then
url='https://people.debian.org/~aurel32/qemu/armel/initrd.img-3.2.0-4-versatile'
echo "Fetching initial ram disk"
echo "$ curl -fLO $url"
curl -fLO $url
fi
if test ! -e vmlinuz-3.2.0-4-versatile ; then
url='https://people.debian.org/~aurel32/qemu/armel/vmlinuz-3.2.0-4-versatile'
echo "Fetching kernel"
echo "$ curl -fLO $url"
curl -fLO $url
fi
notes
qemu-system-arm \
-m $RAM \
-M versatilepb -kernel vmlinuz-3.2.0-4-versatile \
-initrd initrd.img-3.2.0-4-versatile \
-hda debian_wheezy_armel_standard.qcow2 \
-net nic -net user,hostfwd=tcp::2222-:22 \
-nographic -no-reboot -append "root=/dev/sda1" $@
elif test "$1" = "x86" -o "$1" = "i386"; then
shift
mkdir -p ~/.qemu.sh/wheezy/i386
cd ~/.qemu.sh/wheezy/i386
if test ! -e debian_wheezy_i386_standard.qcow2 ; then
url='https://people.debian.org/~aurel32/qemu/i386/debian_wheezy_i386_standard.qcow2'
echo "Fetching disk image"
echo "$ curl -fLO $url"
curl -fLO $url
fi
notes
qemu-system-i386 \
-m $RAM \
-hda debian_wheezy_i386_standard.qcow2 \
-net nic -net user,hostfwd=tcp::2222-:22 \
-nographic -no-reboot $@
elif test "$1" = "x64" -o "$1" = "x86_64" -o "$1" = "amd64"; then
shift
mkdir -p ~/.qemu.sh/wheezy/amd64
cd ~/.qemu.sh/wheezy/amd64
if test ! -e debian_wheezy_amd64_standard.qcow2 ; then
url='https://people.debian.org/~aurel32/qemu/amd64/debian_wheezy_amd64_standard.qcow2'
echo "Fetching disk image"
echo "$ curl -fLO $url"
curl -fLO $url
fi
notes
qemu-system-x86_64 \
-m $RAM \
-hda debian_wheezy_amd64_standard.qcow2 \
-net nic -net user,hostfwd=tcp::2222-:22 \
-nographic -no-reboot -append "root=/dev/sda1" $@
else
echo "Error: unknown architecture " $1 >&2
echo "Please specify one of mips|ppc|arm|x86|x64" >&2
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment