0

I'm straggling to use ubuntu minimal images to create libvirt/KVM VMs. I launched VM-Manager wizard, chose "import existing disk image", pointed it to the downloaded image and made sure that network adapter uses virtio driver. I assigned 2 virtual cores and 4GB RAM to the VM. All other settings were left with default values. Unfortunately the VM freezes at boot, right after displaying BIOS info and "Booting from Hard Disk..." message. I've tried both 16.04 and 18.04 images. In case of 16.04 the additional message "error: no such device: root" was displayed.

Any hints how to make it work would be appreciated :)

My host machine is running ubuntu-16.04 has 2 CPU cores (4 virtual cores with hyperthreading) and 16GB RAM.

  • Why 'minimal' images for a VM instead of the more common 'cloud' images? – user535733 Nov 17 '18 at 16:24
  • @user535733 they consume much less disk space (around 470MB) and boot much faster. When creating hundreds of cloud VMs the overall savings translate into considerable amount of $ ;) I'm setting them on my local KVM to have an exact mirror of my production environment for testing/debugging purposes. – morgwai Nov 17 '18 at 16:38
1

PREPARATION

See if the hardware supports hardware virtualization...

$ egrep -c '(vmx|svm)' /proc/cpuinfo 
2                // A result of '0' means no. '1' or higher means yes

...then reboot into BIOS and turn it on.

CREATING THE FIRST VM:

Once virtualization is turned on, then from zero to fully operating is just three commands. The host is Ubuntu 18.04. The guest will also be 18.04, but that is merely because I lack imagination.

1) Install KVM, qemu, virt-manager and all the other tools you need. The are all dependencies of a single package:

$ sudo apt install uvtool

2) Download a cloud image of Ubuntu 18.04. Cloud images are headless - shell only. The download takes a few minutes (approximately 350 MB), so don't panic:

$ uvt-simplestreams-libvirt sync release=bionic arch=amd64

3) Create and start VM Guest 'test1'

$ uvt-kvm create test1 release=bionic

STARTING, STOPPING, SUSPENDING, AND RESUMING THE VM GUEST FROM HOST

$ virsh list              // Check status
 Id    Name                           State
----------------------------------------------------
 1     test1                          running

$ virsh suspend test1
Domain test1 suspended

$ virsh resume test1
Domain test1 resumed

$ virsh shutdown test1
Domain test1 is being shutdown

$ virsh list --all        // Use --all to show inactive VMs
 Id    Name                           State
----------------------------------------------------
 -     test1                          shut off

$ virsh start test1
Domain test1 started

$ virsh list
 Id    Name                           State
----------------------------------------------------
 2     test1                          running

LOGIN TO THE GUEST

host$ uvt-kvm ssh test1
  • your answer was very helpful, yet few critical details were missing (most importantly the source URL for minimal images). Thus, I'm up-voting and referencing it from my own answer containing all the missing details. Thanks :) – morgwai Nov 17 '18 at 15:31
1

Minimal images are a sub-type of cloud images and as such need to be initialized with uvtool as explained in this answer. However there are few critical details missing:

1) to download minimal images a special URL must specified in the --source option for uvt-simplestreams-libvirt:

 uvt-simplestreams-libvirt sync --source https://cloud-images.ubuntu.com/minimal/releases/ release=bionic arch=amd64

2) if you have other images downloaded (like from the default source for example) it may be necessary to specify a proper label filter when creating a minimal VM:

uvt-kvm create --memory 4096 --cpu 2 myminimalvm release=bionic arch=amd64 "label=minimal release"

(you may also need/want to use --ssh-public-key-file option depending on your ssh setup)

3) after the VM is created you should make sure that Cloudinit tool has finished its job:

uvt-kvm wait --insecure myminimalvm

(you may also need to use --ssh-private-key-file option depending on your ssh setup)

At this point the VM is ready to rock :) You can now operate it (start/stop, pause/resume etc) with standard libvirt tools including virt manager GUI.

Note however that if you open its console, you will see only the BIOS boot information (as described in the question) as minimal images don't output anything on the console nor start the login service. you can only access them via ssh: either with

uvt-kvm ssh --insecure myminimalvm  # again, --ssh-private-key-file may be needed

or directly with ssh after you figure VM's IP (with virt manager, or uvt-kvm ip myminimalvm and also it is usually in the output of uvt-kvm wait):

ssh ubuntu@ip.of.the.vm

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.