Last active
March 9, 2020 18:02
-
-
Save tidwall/05192a09b862dbf4aa9d558a4ac96713 to your computer and use it in GitHub Desktop.
Quickly create Debian VMs on Linux
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 | |
NAME="$1" | |
TYPE="$2" | |
usage() { | |
echo "usage: mkvm.sh name type" | |
echo "" | |
echo " name: user-defined name for the vm" | |
echo " type: (nano,micro,small,medium,large,xlarge,2xlarge)" | |
echo "" | |
echo " type vcpus ram disk" | |
echo " -------------------------" | |
echo " nano 1 512M 4G" | |
echo " micro 1 1G 8G" | |
echo " small 1 2G 16G" | |
echo " medium 2 4G 32G" | |
echo " large 4 8G 64G" | |
echo " xlarge 8 16G 128G" | |
echo " 2xlarge 16 32G 256G" | |
echo "" | |
} | |
if [[ "$NAME" == "" || "$NAME" == "-h" ]]; then | |
usage | |
exit 1 | |
fi | |
if [ "$TYPE" == "nano" ]; then | |
opts="--vcpus=1 --memory=512 --disk size=4" | |
elif [ "$TYPE" == "micro" ]; then | |
opts="--vcpus=1 --memory=1024 --disk size=8" | |
elif [ "$TYPE" == "small" ]; then | |
opts="--vcpus=1 --memory=2048 --disk size=16" | |
elif [ "$TYPE" == "medium" ]; then | |
opts="--vcpus=2 --memory=4096 --disk size=32" | |
elif [ "$TYPE" == "large" ]; then | |
opts="--vcpus=4 --memory=8192 --disk size=64" | |
elif [ "$TYPE" == "xlarge" ]; then | |
opts="--vcpus=8 --memory=16384 --disk size=128" | |
elif [ "$TYPE" == "2xlarge" ]; then | |
opts="--vcpus=16 --memory=32768 --disk size=256" | |
else | |
echo "invalid type" | |
usage | |
exit 1 | |
fi | |
wget -nc https://cdimage.debian.org/debian-cd/current/amd64/iso-cd/debian-10.3.0-amd64-netinst.iso | |
virt-install $opts \ | |
--name="$NAME" \ | |
--location=debian-10.3.0-amd64-netinst.iso \ | |
--nographics \ | |
--extra-args='console=tty0 console=ttyS0,115200n8 serial' \ | |
--network bridge:virbr0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment