Last active
October 24, 2021 19:04
-
-
Save fjctp/40fab8d7324428822010fd31e09382be to your computer and use it in GitHub Desktop.
Using virt-install to create a virtual machine
This file contains 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 | |
# | |
# based on https://gist.github.com/Manouchehri/2b1b523eed834f295915 | |
set -e | |
ISO_FILE=~/Downloads/archlinux-2021.10.01-x86_64.iso | |
DISK_FILE=archlinux.qcow2 | |
if [[ ! -f ${ISO_FILE} ]]; then | |
echo "ISO does not exist!" | |
exit 1 | |
fi | |
# create the disk if it does not exist | |
if [[ ! -f ${DISK_FILE} ]]; then | |
qemu-img create -f qcow2 archlinux.qcow2 16G | |
fi | |
# start the machine | |
# to access, ssh -p 10022 localhost | |
qemu-system-x86_64 \ | |
-bios /usr/share/qemu/ovmf-x86_64-code.bin \ | |
-enable-kvm \ | |
-smp cpus=4 \ | |
-m size=2048 \ | |
-cdrom ${ISO_FILE} \ | |
-drive file=${DISK_FILE},media=disk,if=virtio \ | |
-net user,hostfwd=tcp::10022-:22 \ | |
-net nic \ | |
-vga qxl |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment