0

I am currently able to make a Ubuntu 16.04 VM via KVM on my host Ubuntu.

What I'm trying is to install the Ubuntu image but then not have to go through the installation process of choosing a username, password, machine name, and time zone.

Is it possible to do this via KVM?

Zanna
  • 70,465
nadermx
  • 545

2 Answers2

1

If you already have an installed VM you can simply copy the installed VM This would allow you to go through the installation process only once although you may have to do some editing...

First copy the VM's disks from /var/lib/libvirt/images on src host to the same dir on destination host.

Next, run virsh dumpxml VMNAME > domxml.xml on the source host and copy this xml to the dest. host

Then, on the destination host run virsh define domxml.xml

and start the VM.

Addendum: If the VM has snapshots that you want to preserve, you should dump the snapshot xml-files on the source with virsh snapshot-dumpxml $dom $name > file.xml for each snapshot in the snapshot list of the VM virsh snapshot-list --name $dom.

Then on the destination use virsh snapshot-create --redefine $dom file.xml to finish migrating the snapshots.

If you also care about which snapshot is the current one, then additionally do on the source: virsh snapshot-current --name $dom and on the destination: virsh snapshot-current $dom $name

Note: If the disk location differs, you need to edit the xml's devices/disk node to point to the image on the destination host If the VM is attached to custom defined networks, you'll need to either edit them out of the xml on the destination host or redefine them as well (virsh net-dumpxml > netxml.xml and the virsh net-define netxml.xml && virsh net-start NETNAME & virsh net-autostart NETNAME)

Sources: This answer shamelessly modeled on answers found on

https://serverfault.com/questions/434064/correct-way-to-move-kvm-vm

Elder Geek
  • 36,023
  • 25
  • 98
  • 183
0

You can use virt-builder to create virtual machine images of a wide variety of Linux distributions.

Virt-builder is included in the libguestfs-tools package. Install it with:

sudo apt-get install libguestfs-tools

You run virt-builder by telling it what Linux distribution you want to build an image for. To learn what virtual machines it can build, run:

virt-builder --list
....
ubuntu-10.04             x86_64     Ubuntu 10.04 (Lucid)
ubuntu-12.04             x86_64     Ubuntu 12.04 (Precise)
ubuntu-14.04             x86_64     Ubuntu 14.04 (Trusty)
ubuntu-16.04             x86_64     Ubuntu 16.04 (Xenial)

To build a virtual machine, specify whether you want a raw or QCOW2 image, the disk size you want, and a filename, and go:

virt-builder ubuntu-16.04 --format qcow2 --size 10G --output my-ubuntu-vm.qcow2

By default, virt-builder will enable the root account and set a random password for it. If you don't want this, you can set your own root password. You can also add user accounts, install or remove packages, set the VM hostname, and even run arbitrary commands. The virt-builder man page has all the details on these, if you need them.