Making a template and cloning in KVM
-
At my current job, I'm getting experience with VMware for the first time. One thing that I like about it is that we have templates of a few editions of Window Server, which we keep patched to current and from which we deploy new VMs as needed.
My home lab uses KVM, so I wanted to see if I could create similar functionality. I'm not using oVirt or anything like that (that's a project for the future), but here's what I've done and do reduce a bit of time for deploying some new VMs.
- I have a VM of Fedora, which I keep patched to current. The VM is shutdown when not being patched so it's not eating resources.
- To deploy a new VM, I run the following command on my KVM host.
virt-clone --original VMtoBeCloned --name VMtoBeCreated --mac RANDOM --auto-clone
According to the man page simply not specifying
--mac
should generate new mac addresses for the NICs, but I'm a bit paranoid. The--auto-clone
option will automatically create the qcow2 storage file for the new VM.You can also clone from the Virt Manager GUI, which is what I did until I discovered the greatness of
--auto-clone
. -
Virt-Builder is another option if you will be creating Linux VMs.
It's slow the first time you use it but the next time, its a lot quicker.sudo virt-builder fedora-28 \ --root-password password:Password1 \ --output /home/kvm/libvirt/images/fedora28.qcow2 \ --format qcow2 \ --hostname fedora28.domain.com \ --timezone America/Denver \ --update \ --install cockpit \ --install cockpit-storaged \ --selinux-relabel \ --size 50G \ --firstboot-command 'systemctl enable --now cockpit.socket' \ --firstboot-command 'firewall-cmd --permanent --add-service=cockpit; firewall-cmd --reload' sudo virt-install \ --name fedora28 \ --vcpus 2 \ --ram 4096 \ --disk /home/kvm/libvirt/images/fedora28.qcow2,format=qcow2 \ --nographics \ --import \ --os-variant fedora28 \ --network type=direct,source=team0,source_mode=bridge
-
I've been using this to set up some test VMs on KVM. It's been working great.
virt-install --name Win2016a \ --description 'Windows Server 2016 Test' \ --ram 4096 \ --vcpus 2 \ --os-type Windows \ --os-variant "win2k16" \ --disk path=/DATA/vms/Win2016a/Win2016a.qcow2,bus=sata,size=50 \ --cdrom /DATA/img/WS2016_EVAL_14393.0.161119-1705.RS1_REFRESH_SERVER_EVAL_X64FRE_EN-US.ISO \ --network type=direct,source=eth0,source_mode=bridge,model=e1000 \ --graphics spice \ --noautoconsole \ --noreboot \ --boot uefi \
-
@obsolesce said in Making a template and cloning in KVM:
I've been using this to set up some test VMs on KVM. It's been working great.
virt-install --name Win2016a \ --description 'Windows Server 2016 Test' \ --ram 4096 \ --vcpus 2 \ --os-type Windows \ --os-variant "win2k16" \ --disk path=/DATA/vms/Win2016a/Win2016a.qcow2,bus=sata,size=50 \ --cdrom /DATA/img/WS2016_EVAL_14393.0.161119-1705.RS1_REFRESH_SERVER_EVAL_X64FRE_EN-US.ISO \ --network type=direct,source=eth0,source_mode=bridge,model=e1000 \ --graphics spice \ --noautoconsole \ --noreboot \ --boot uefi \
Something to note:
If you use
--cdrom
instead of--disk /path/to/iso,device=cdrom,etc...
, then it will auto-boot afterwards even if using--noreboot
. -
Started a new job last month and it's all VMware. I miss libguestfs tools.
-
@stacksofplates I can imagine. Good luck!