KVM – Easily Create KVM Scripts

If you have a great time typing out all the commands to start a VM via the CLI this is an easy way to make it a little simpler.

Instead of typing this out each time you want to make a VM on the CLI

virt-install \
–virt-type=kvm \
–name centos-server \
–ram 2048 \
–vcpus=2 \
–cdrom=/var/lib/libvirt/images/CentOS-7-x86_64-DVD-1810.iso \
–network=bridge=br0,model=virtio \
–graphics vnc \
–disk path=/HDD1/centos-server.qcow2,size=20,bus=virtio,format=qcow2

Create the directory /home/bin if you dont already have one and create a file using nano or vi and enter

#!bin/bash

virt-install \
–virt-type=kvm \
–name centos-server \
–ram 2048 \
–vcpus=2 \
–cdrom=/var/lib/libvirt/images/CentOS-7-x86_64-DVD-1810.iso \
–network=bridge=br0,model=virtio \
–graphics vnc \
–disk path=/HDD1/centos-server.qcow2,size=20,bus=virtio,format=qcow2

Save it and then you can use cp and change the name to each VM setup you want to create. Then whenever you want to create a VM or duplicate a VM you can edit the file and change the name, etc.

To run the script just run

./name-of-file

And your VM will be started

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s