0

Previously (some years back) I have used vmbuilder, but this now seems to be unmaintained and cannot be used with newer ubuntu versions.

I have also tried vagrant with vagrant-libvirt plugin, apart from this method requires a huge amount of packages to be installed it didn't work in the end after all because there is no ubuntu cloud images for the libvirt provider.

I have also looked into standard virt-installer providing the standard ISO image as CD-ROM, but that is not non-interactive. Apart from that I also ran into a ubiquity bug during the interactive installation.

So what is the best way to non-interactively provision ubuntu virtual machines using libvirt? Or what is the replacement of vmbuilder?

Jarl
  • 247

3 Answers3

1

I think you are looking for virt-builder.

Virt-builder starts with cleanly installed OS templates for a variety of distributions and allows you to customize them by setting a root password, copying in files, and more.

Virt-builder is in the libguestfs-tools package.

sudo apt install libguestfs-tools

These basic commands should get you started; you can find more advanced stuff in the man page.

List the available VM templates:

virt-builder --list

Create a fresh Ubuntu 18.04 LTS image:

virt-builder ubuntu-18.04

By default, virt-builder creates no user accounts, and enables the root account with a random password, which is printed on your terminal when the VM image is created. As mentioned before, you can change this with various command options.

(Note that with respect to Ubuntu, virt-builder only supports LTS releases of Ubuntu.)

Michael Hampton
  • 1,860
  • 1
  • 16
  • 27
  • This looks like the tool I was looking for. However I run into issues using virt-builder. I have reported it on https://bugs.launchpad.net/ubuntu/+source/libguestfs/+bug/1813662 – Jarl Jan 28 '19 at 21:05
  • 1
    Well, at least there's a workaround. – Michael Hampton Jan 28 '19 at 22:32
  • virt-builder only creates the disk I am still missing the xml-file, i.e. the domain definition in libvirt. – Jarl Jan 30 '19 at 14:28
  • @Jarl You can easily create the VM to your own desires using virt-install and using the --import option to tell it to use the existing disk, rather than trying to run an OS installer. – Michael Hampton Jan 30 '19 at 15:01
  • Could you add the final steps needed to provision a ubuntu server so that it will show up on the output from virsh list? – Jarl Feb 04 '19 at 13:12
1

I'd recommend taking a look at either uvtool which in my experience works much better than virt-builder.

But given it is no more 2016 I'd actually recommend even more taking a look at the modern and even cross platform solution of multipass. By default that would spawn qemu directly but you can make it use the libvirt backend instead with

snap set multipass driver=LIBVIRT

Both tools will give you a CLI interface to spawn guests based on Ubuntu cloud images.

  • Thanks for the pointers to both tools, very nice. If you by "spawning" mean "run" then I am not so much interested in spawning guests, I will use virsh for that, I am interested in building/creating the guests, that is, creating a virtual disk image and an XML file that defines a domain that is seen in the output from virsh list. – Jarl Jan 31 '19 at 05:42
  • Yeah, that will all work. After the initial creation you can use plain libvirt/virsh as you like. – Christian Ehrhardt Feb 01 '19 at 09:46
-1

Things move fast in Ubuntu Land....as of Q4 2019, I would be using Multipass for virtual machines and LXD for machine containers. Ideally using Ubuntu images...

Configuration of machine instances is handled differently:

  1. Machine containers - use LXD profiles
  2. Virtual Machines - cloud-init for initial configuration of network and user data settings

If you are wanting to run a variety of different OS flavours then things get a bit more complicated....

damadam
  • 2,883
  • Ofcourse I should also say that a second parallel set of options exists for managing machine images and configurations within Systemd. See machinectl for more information https://www.freedesktop.org/software/systemd/man/machinectl.html. But again this has a linux centred focus. – Shaun Forgie Nov 26 '19 at 20:47