1

I am building a tool to help me manage my KVM server. It generates a command that uses a kickstart file to automatically install KVM guests for me. Below is an example command that it generated to automatically install an Ubuntu 16.04 guest.

virt-install --connect qemu:///system  \
--nographics \
--os-type linux \
--accelerate \
--hvm \
--network network=default,model=virtio \
--name testing124 \
--os-variant ubuntu16.04 \
--ram 1024 \
--vcpus 2 \
--location http://us.archive.ubuntu.com/ubuntu/dists/xenial/main/installer-amd64/ \
--disk /home/stuart/code-copy/vms/testing124/disk.raw,bus=virtio,format=raw,cache=writethrough \
--extra-args "console=ttyS0 ks=http://pastebin.com/raw/6TznVUuN"

I want this command to be executed from inside the tool with an exec command, rather than printing it out and requiring me to manually copy and paste it to execute, as I have done up until now. The problem is that the command will never complete because the virt-console always remains open. By default, guests will reboot, and the console connected. If I specify shutdown instead of reboot, then the installation will get stuck on this step:

enter image description here

If I specify halt or poweroff instead of shutdown, then the guest shuts down, but the console is left hanging on a blank screen. Virsh also shows the guest as running if you execute virsh list --all

What changes do I need to make to the command or kickstart file for KVM guest installation to finish gracefully?

Appendices

The kickstart file is copied down below in case the referenced one ever changes or gets lost.

# Ubuntu server 64bit example kickstart/seed with shutdown

# System language
#lang en_US
lang en_GB

# Language modules to install
#langsupport en_US
langsupport en_GB

# System keyboard
keyboard us

# System mouse
mouse

# System timezone
#timezone America/Chicago
timezone --utc America/Chicago

# Root password
rootpw --disabled

# Initial user
user ubuntu --fullname "" --password ubuntu
preseed user-setup/allow-password-weak boolean true

# pick only one of these actions to take after installation completed
#reboot
#shutdown
#halt
poweroff

# Use text mode install
text

# Install OS instead of upgrade
install

# Use http installation media
url --url http://archive.ubuntu.com/ubuntu

# System bootloader configuration
bootloader --location=mbr

# Clear the Master Boot Record
zerombr yes

# Partition clearing information
clearpart --all --initlabel

# Partition setup
part / --fstype ext4 --size 1 --grow
#part /boot --fstype ext2 --size 200 --asprimary
#part swap  --size 1024
#part pv.01 --size 1 --grow
#volgroup rootvg pv.01
#logvol / --fstype ext4 --vgname=rootvg --size=1 --grow --name=rootvol
#preseed partman-lvm/confirm_nooverwrite boolean true

# If you have swap commented out/not specified then you need to have this line.
preseed --owner partman-basicfilesystems partman-basicfilesystems/no_swap boolean false

# System authorization infomation
auth  --useshadow  --enablemd5

# Firewall configuration
firewall --disabled

# Do not configure the X Window System
skipx

# Make sure to install the acpid package so that virsh commands such
# as virsh shutdown will take effect
%packages
@ubuntu-server
@openssh-server
@acpid

2 Answers 2

2

Turns out this is what the --noautoconsole option in virt-install is perfect for.

Description from the man page:

Don't automatically try to connect to the guest console. The default behaviour is to launch a VNC client to display the graphical console, or to run the "virsh" "console" command to display the text console. Use of this parameter will disable this behaviour.

Now the virt-install command that the program executes will execute and return almost immediately as it won't connect to the console and wait for the guest to finish installing. The guest will still proceed to install in the background using the kickstart script even though nothing is connected to the console. As long as there is nothing wrong with the kickstart file, the guest will perform a full installation and shutdown (if shutdown specified in kickstart file) when it has completed. I can tell when a guest has finished installing by polling virsh list --all until the guest is no longer shown as running.

The updated command is below:

virt-install --connect qemu:///system  \
--nographics \
--os-type linux \
--accelerate \
--hvm \
--network network=default,model=virtio \
--name testing124 \
--os-variant ubuntu16.04 \
--ram 1024 \
--vcpus 2 \
--location http://us.archive.ubuntu.com/ubuntu/dists/xenial/main/installer-amd64/ \
--disk /home/stuart/code-copy/vms/testing124/disk.raw,bus=virtio,format=raw,cache=writethrough \
--noautoconsole \
--extra-args "console=ttyS0 ks=http://pastebin.com/raw/6TznVUuN"
1

What I typically use in an automated installation is --noreboot --noautoconsole which pretty much covers a completely unattended install. Having said that, it is generally faster and better to use virt-builder instead of virt-install, as the command is more stable and image manipulation is faster and more consistent than a full fledged installation of an OS. With a premade template VM image things are even faster than that btw.

1
  • thanks for the tip about virt-builder, that looks really useful. I had considered putting up a public FTP of base installations for users to download but that does a better job of achieving a similar effect (download a prepared image). Commented Mar 13, 2017 at 11:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .