Skip to content

Instantly share code, notes, and snippets.

@colebob9
Last active May 1, 2020 12:10
Show Gist options
  • Save colebob9/d866c84c2649b8e6a4c193286617f235 to your computer and use it in GitHub Desktop.
Save colebob9/d866c84c2649b8e6a4c193286617f235 to your computer and use it in GitHub Desktop.
Installs QEMU on a Mac, doesn't need admin

InstallQEMUOnMac Script

  1. Right/Two Finger click on each .sh script below, clicking on "Save link as..." each time. Make sure they are both downloading as a shell script.
  2. Place them both in a new folder, as they will make files on install.
  3. Open a terminal and navigate (using cd) to the folder you put both scripts into. Execute both of these commands:
chmod +x InstallQEMUOnMac.sh
chmod +x LaunchQEMU.sh
  1. Install the Amphetamine app from the Mac App Store. Open and enable it. (Technically optional, but a lot more painful to go through without it) This will keep your Mac from sleeping. Although, don't close the lid.
  2. Execute this command in the Terminal:
./InstallQEMUOnMac.sh

This will start the install script. Read the listed instructions on the prompt.

  1. After you start the install script, it will will ask you if you see a window pop up relating to developer tools. If it does, click "Install now..." on the box and wait for it to completely finish before continuing in the script.
  2. Sit back and wait for it to install!
  3. If all goes well, you have it installed!

How to launch QEMU

  1. Navigate, using the Terminal, to the folder that you have both script in.
  2. Execute in Terminal:
./LaunchQEMU.sh
  1. It will ask you for a few options:

[y/n] = yes/no - simply type y or n to turn options on or off.

Use KVM? [y/n]: This means it will try to use virtualization supported by your CPU. Will make your experience way faster. Although, it has not worked for me yet. Still, try to use it once. If it doesn't launch, simply have it disabled. Be warned, it becomes way slower than normal.

Launching with ISO? [y/n]: This is needed if you haven't installed your OS (Ubuntu probably). This will use the .iso downloaded with the install script.

How much RAM? (in MB): Simply how much RAM you want to dedicate to the VM. Start out with 1024 MB, especially with older/Air model Macs. Only accepts numbers, for example:

How much RAM? (In MB, try 1024): 1024
  1. It should now launch!
# InstallQEMUOnMac v1
# colebob9
# Installs QEMU using homebrew and downloads Ubuntu on a Mac
# Execute `chmod +x InstallQEMUOnMac.sh` before using.
echo "This will install QEMU on your Mac. Please note that this will take about 40 minutes to get through. Go watch some YouTube videos or something cause you're going to be here for a while. This script will take care of everything."
echo "Please make sure you have your charger plugged in, and a lot of patience."
echo "Do not *at any point* exit out of this Terminal window, even if it looks stuck. It's not."
echo "It is also recommended to have the Mac apps \"Amphetamine\" or \"Caffeine\" installed and enabled now, so your Mac doesn't sleep. Do not close your lid either."
echo ""
echo -n "Press any key to start..."
read
SECONDS=0
SCRIPTDIR=$(cd -P -- "$(dirname -- "$0")" && pwd -P)
mkdir QEMU_Setup
cd QEMU_Setup
# Get homebrew portable
mkdir homebrew && curl -L https://github.com/Homebrew/brew/tarball/master | tar xz --strip 1 -C homebrew
cd homebrew/bin
BINDIR=$(cd -P -- "$(dirname -- "$0")" && pwd -P)
BINDIR="${BINDIR}/"
./brew update
echo ""
echo "Your Mac may have told you that you need some developer tools. Click the \"Install now...\" button if you have that window. Continue once it is finished."
echo "If not, you may already have those tools. Continue on if that's the case and you didn't get any errors above."
echo -n "Press any key to continue..."
read
./brew update
./brew install qemu
# Delete from here to disable downloading and setting up QEMU for Ubuntu
cd ${SCRIPTDIR}
mkdir Ubuntu
cd Ubuntu
curl -O http://releases.ubuntu.com/16.04/ubuntu-16.04.3-desktop-amd64.iso
IMGCOMMAND="${BINDIR}qemu-img create -f qcow2 ubuntu.img 10G"
$IMGCOMMAND
echo "Done with Install! :D"
duration=$SECONDS
echo "Install took $(($duration / 60)) minutes and $(($duration % 60)) seconds elapsed."
echo "Now use LaunchQEMU.sh to use QEMU from now on!"
# LaunchQEMU v1
# colebob9
# Launches QEMU nicely for Ubuntu.
# Execute `chmod +x LaunchQEMU.sh` before using.
BINDIR="QEMU_Setup/homebrew/bin/"
read -p "Use KVM? (try using first) [y/n]: " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
KVM=" -enable-kvm "
fi
read -p "Launching with ISO? (Need for install) [y/n]: " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
ISO=" -cdrom Ubuntu/ubuntu-16.04.3-desktop-amd64.iso"
fi
read -p "How much RAM? (In MB, try 1024): " RAM
LAUNCHCOMMAND="${BINDIR}qemu-system-x86_64 -m ${RAM} -boot d${KVM} -smp 3 -net nic -net user -hda Ubuntu/ubuntu.img${ISO}"
echo "Using command: ${LAUNCHCOMMAND}"
$LAUNCHCOMMAND
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment