|
#!/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 |