Skip to content

Instantly share code, notes, and snippets.

@mechanicker
Last active August 18, 2022 17:52
Show Gist options
  • Save mechanicker/fb716b7f60a4996679d59ffb7de8e87f to your computer and use it in GitHub Desktop.
Save mechanicker/fb716b7f60a4996679d59ffb7de8e87f to your computer and use it in GitHub Desktop.
Notes from running CentOS 7 in QEMU on Mac
# Install qemu
brew install qemu
# Create disk image for root file system
qemu-img create -f qcow2 centos-7.qcow2 10G
# Run with ISO image mounted as cdrom for installing
qemu-system-x86_64 \
-m 2048 \
-vga virtio \
-usb \
-device usb-tablet \
-enable-kvm \
-cdrom CentOS-7-x86_64-Minimal-2003.iso \
-drive file=centos-7.qcow2,if=virtio \
-machine accel=hvf \
-cpu host
# Run configured instance
qemu-system-x86_64 \
-m 2048 \
-vga virtio \
-usb \
-device usb-tablet \
-enable-kvm \
-drive file=centos-7.qcow2,if=virtio \
-machine accel=hvf \
-cpu host
# Configure network in CentOS 7
# https://phoenixnap.com/kb/configure-centos-network-settings
vi /etc/sysconfig/network-scripts/ifcfg-ens3
`ONBOOT="yes"`
`DNS1=1.1.1.1`
`DNS2=8.8.8.8`
#!/usr/bin/env bash
# Create raw image: qemu-img create -f qcow2 centos-7.qcow2 25G
# Download Centos 7: curl -sSLO http://mirrors.oit.uci.edu/centos/7.8.2003/isos/x86_64/CentOS-7-x86_64-Minimal-2003.iso
shopt -s extglob
cd ~/QEMU
msg="starting qemu..."
OPT_SNAPSHOT="-snapshot"
for arg in $*; do
if [ ${arg} == "--dry-run" -o ${arg} == "-n" ]; then
ACTION="echo"
fi
if [ ${arg} == "--update" -o ${arg} == "-u" ]; then
echo -n "warning: starting in update mode, continue [y/n]: "
read input
case "${input}" in
[Yy]) ;;
[Nn]*|'') exit 0;;
*) echo "error: Invalid response, Please try again." && exit -1;;
esac
msg="${msg}\nwarning: Starting in update mode!"
OPT_SNAPSHOT=""
fi
done
OPTS="${OPT_SNAPSHOT} $*"
echo -e ${msg}
set -x
${ACTION} qemu-system-x86_64 \
-m 2048 \
-vga virtio \
-usb \
-device usb-tablet \
-enable-kvm \
-cdrom CentOS-7-x86_64-Minimal-2003.iso \
-drive file=centos-7.qcow2,if=virtio \
-machine accel=hvf \
-cpu host \
-display cocoa,show-cursor=on \
${OPTS}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment