Created
January 8, 2023 02:38
-
-
Save roguephysicist/ff928ee07b0a3b6a313e80c3b2682fab to your computer and use it in GitHub Desktop.
QEMU Wrapper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
MODE="$1" | |
# Image files | |
# FILE_ISO="CentOS-7-x86_64-NetInstall-2009.iso" | |
# FILE_IMG="centos7.qcow2" | |
FILE_IMG="centos8.qcow2" | |
# FILE_ISO="CentOS-8.3.2011-x86_64-boot.iso" | |
# FILE_IMG="ubuntu.qcow2" | |
# FILE_ISO="ubuntu-20.04.1-live-server-amd64.iso" | |
# VM properties | |
QEMU_BIN=qemu-system-x86_64 | |
QEMU_MEM=8G | |
QEMU_CPU=4 | |
QEMU_PRT=5555 | |
# VM configuration | |
QEMU_BOX="-m $QEMU_MEM -smp $QEMU_CPU -enable-kvm" # cpu and memory | |
QEMU_NIC="-nic user,hostfwd=tcp::${QEMU_PRT}-:22" # ssh -p 5555 localhost | |
QEMU_3DG="-vga virtio" # experimental 3D! add at end of QEMU_OPT | |
QEMU_OPT="$QEMU_BOX $QEMU_NIC" # options all put together | |
# VM disks | |
QEMU_DSK_DUO="-boot d -hda $FILE_IMG -cdrom $FILE_ISO" # boot from ISO with HDD attached | |
QEMU_DSK_HDD="-boot c -hda $FILE_IMG" # HDD only | |
QEMU_DSK_ISO="-boot d -cdrom $FILE_ISO" # ISO only | |
if [[ $MODE == "install" ]]; then | |
qemu-img create -f qcow2 $FILE_IMG 32G # create disk image | |
$QEMU_BIN $QEMU_OPT $QEMU_DSK_DUO & | |
else | |
$QEMU_BIN $QEMU_OPT $QEMU_DSK_HDD & | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment