IT From All Angles

KVM Guests: Using Virt-Install to Install Debian and Ubuntu Guests

KVM Guests: Using Virt-Install to Install Debian and Ubuntu Guests

I like to be able to spin up a VM without looking for CD media so for a while now I have been using ISO images for all of my installs directly, however I found my self scurrying around “digitally” looking for the correct iso in much the same way I used to scurry about looking for physical CDs, except I was not physically moving.  So anyways the time was wasted either way, I figured it is time that I find a better (read: lazier) way to do this.  So the idea is that since the apt package manager contains all the packages and files needed to install and upgrade a system, we ought to be able to find a way to initiate the install over the wire.

Assumptions I Have Made

  • My KVM host is Ubuntu 10.10 and I am assuming that yours is as well.  If it is not then the syntax might be slightly different or may not include the same features.
  • That you have kvm installed on the host and you can manually create VMs using virt-manager and they work perfectly.
  • That you have a bridge configured and working on other guests.
  • That you have virt-install and libvirt-bin installed as well as virt-manager or virt-viewer so that you can complete the install after the virt-install command has completed.
  • That you are trying to install guests that support VirtIO devices (all four distros below do, if you have linux 2.6.25+ then they do as well, Windows has drivers available for install, though does not natively support it – so it will require a virtual boot floppy to install drivers).

The Basic Command

# virt-install -n vmname -r 2048 --os-type=linux --os-variant=debianlenny --disk    /kvm/images/disk/vmname_boot.img,device=disk,bus=virtio,size=8,sparse=true,format=raw -w bridge=br0,model=virtio --vnc --noautoconsole --location

If you’d like to install on a LVM logical volume which you have already created, simply change the –disk parameter to reference a LV /dev/vg_name/lv_name, additionally you will need to remove the size, sparse, and format options as these relate to the creation of a disk image file.

Parameters Detailed

  • -n vmname [the name of your VM]
  • -r 2048 [the amount of RAM in MB for your VM]
  • –os-type=linux [the type of OS linux or windows]
  • –os-variant=debianlenny [the distribution or version of Windows for a full list see man virt-install]
  • –disk /kvm/images/disk/vmname_boot.img,device=disk,bus=virtio,size=8,sparse=true,format=raw [this is a long one you define the path, then comma delimited options, device is the type of storage cdrom, disk, floppy, bus is the interface ide, scsi, usb, virtio – virtio is the fastest but you need to install the drivers for Windows and older versions of Linux don’t have support, size is the size in GB, sparse defines if the disk will be dynamically allocated or if a 40GB image file should take up 40GB on the host file system, format is the type of disk image you are using raw, qcow2, vmdk.  Now this command will create the file (if it doesn’t exist) or it can use an existing file]
  • -w bridge=br0,model=virtio [the network configuration, in this case we are connecting to a bridge named br0, and using the virtio drivers which perform much better if you are using an OS which doesn’t support virtio you can use e1000 or rtl8139.  You could alternatively use –nonetworks if you do not need networking]
  • –vnc [configures the graphics card to use VNC allowing you to use virt-viewer or virt-manager to see the desktop as if you were at the a monitor of a physical machine]
  • –noautoconsole [configures the installer to NOT automatically try to open virt-viewer to view the console to complete the installation – this is helpful if you are working on a remote system through SSH]
  • –location [this is the mirror which hosts the installer files of the distribution of your choice, in this case Debian Lenny]

Now that we have broke down that command and given you the basic building blocks of virt-install, please keep in mind there are many more options and details in the man pages for virt-install.  Once the virt-install command has run, you will need to connect to the console of the VM using virt-manager or virt-viewer to complete the actual install, this install is not automatic, it is just kicked off over the network.  Also keep in mind that if you have a slow link your install will be slow, if you have a lot of installs like this you should consider mirroring the distributions that you need internally to conserve your WAN links.

Install Debian 5 (Lenny)

# virt-install -n lenny001 -r 2048 --os-type=linux   --os-variant=debianlenny --disk   /kvm/images/disk/lenny001_boot.img,device=disk,bus=virtio,size=8,sparse=true,format=raw   -w bridge=br0,model=virtio --vnc --noautoconsole --location

Install Debian 6 (Squeeze)

# virt-install -n squeeze001 -r 2048 --os-type=linux  --os-variant=debiansqueeze --disk  /kvm/images/disk/squeeze001_boot.img,device=disk,bus=virtio,size=8,sparse=true,format=raw  -w bridge=br0,model=virtio --vnc --noautoconsole --location

Install Ubuntu 10.04 (Lucid)

# virt-install -n lucid001 -r 2048 --os-type=linux --os-variant=ubuntulucid --disk /kvm/images/disk/lucid001_boot.img,device=disk,bus=virtio,size=8,sparse=true,format=raw -w bridge=br0,model=virtio --vnc --noautoconsole --location

Install Ubuntu 10.10 (Maverick)

# virt-install -n maverick001 -r 2048 --os-type=linux --os-variant=ubuntumaverick --disk /kvm/images/disk/maverick001_boot.img,device=disk,bus=virtio,size=8,sparse=true,format=raw -w bridge=br0,model=virtio --vnc --noautoconsole --location

2 thoughts on “KVM Guests: Using Virt-Install to Install Debian and Ubuntu Guests

  1. Richard

    Hi – I don’t see any reference to debootstrap after the first paragraph, and this method doesn’t seem to use it?

  2. matthew.mattoon Post author

    Hi Richard,

    You are correct. It appears that virt-install (or the backend virtinst) does not use debootstrap. I incorrectly assumed that it did based on the fact that it operates very similarly, however I have looked through the python scripts that make up virtinst and it is simply using HTTP as an install source.