Skip to content

Instantly share code, notes, and snippets.

@cellularmitosis
Last active April 26, 2024 06:45
Show Gist options
  • Star 22 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • 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

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)

TODO:

  • DONE port forward the ssh port
  • DONE port this to macOS
#!/bin/bash
set -e -o pipefail
RAM=256M
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 "$(uname -s)" = "Darwin"
then
echo "brew install qemu"
brew install qemu
elif "$(uname -s)" = "Linux"
then
echo "sudo apt-get install qemu qemu-system"
sudo apt-get install qemu qemu-system
else
echo "Error: please install qemu" >&2
exit 1
fi
fi
function notes {
echo "Notes:"
echo "- The root account 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'"
}
if test "$1" = "mips" -o "$1" = "mipsel"
then
mkdir -p ~/.qemu.sh/wheezy/mipsel
cd ~/.qemu.sh/wheezy/mipsel
test -e debian_wheezy_mipsel_standard.qcow2 \
|| wget https://people.debian.org/~aurel32/qemu/mipsel/debian_wheezy_mipsel_standard.qcow2
test -e vmlinux-3.2.0-4-4kc-malta \
|| wget https://people.debian.org/~aurel32/qemu/mipsel/vmlinux-3.2.0-4-4kc-malta
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 \
-append "root=/dev/sda1 console=tty0" \
-no-reboot
elif test "$1" = "ppc" -o "$1" = "powerpc"
then
mkdir -p ~/.qemu.sh/wheezy/powerpc
cd ~/.qemu.sh/wheezy/powerpc
test -e debian_wheezy_powerpc_standard.qcow2 \
|| wget https://people.debian.org/~aurel32/qemu/powerpc/debian_wheezy_powerpc_standard.qcow2
notes
qemu-system-ppc \
-m $RAM \
-hda debian_wheezy_powerpc_standard.qcow2 \
-net nic -net user,hostfwd=tcp::2222-:22 \
-no-reboot
elif test "$1" = "arm" -o "$1" = "armel"
then
mkdir -p ~/.qemu.sh/wheezy/armel
cd ~/.qemu.sh/wheezy/armel
test -e debian_wheezy_armel_standard.qcow2 \
|| wget https://people.debian.org/~aurel32/qemu/armel/debian_wheezy_armel_standard.qcow2
test -e initrd.img-3.2.0-4-versatile \
|| wget https://people.debian.org/~aurel32/qemu/armel/initrd.img-3.2.0-4-versatile
test -e vmlinuz-3.2.0-4-versatile \
|| wget https://people.debian.org/~aurel32/qemu/armel/vmlinuz-3.2.0-4-versatile
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 \
-append "root=/dev/sda1"
elif test "$1" = "x86" -o "$1" = "i386"
then
mkdir -p ~/.qemu.sh/wheezy/i386
cd ~/.qemu.sh/wheezy/i386
test -e debian_wheezy_i386_standard.qcow2 \
|| wget https://people.debian.org/~aurel32/qemu/i386/debian_wheezy_i386_standard.qcow2
notes
qemu-system-i386 \
-m $RAM \
-hda debian_wheezy_i386_standard.qcow2 \
-net nic -net user,hostfwd=tcp::2222-:22
elif test "$1" = "x64" -o "$1" = "x86_64" -o "$1" = "amd64"
then
mkdir -p ~/.qemu.sh/wheezy/amd64
cd ~/.qemu.sh/wheezy/amd64
test -e debian_wheezy_amd64_standard.qcow2 \
|| wget https://people.debian.org/~aurel32/qemu/amd64/debian_wheezy_amd64_standard.qcow2
notes
qemu-system-x86_64 \
-m $RAM \
-hda debian_wheezy_amd64_standard.qcow2 \
-net nic -net user,hostfwd=tcp::2222-:22
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