Virtual machine unattended Debian installations with libvirt and d-i preseeding
That recipe explains how to perform an unattended Debian GNU/Linux installation (thanks to preseeds) on a virtual machine using
libvirt is a virtualization tool/library providing a common API to manage virtual machines over KVM, qemu, LXC, Xen, OpenVZ and many others. A interesting feature of libvirt is
virsh, an application that allows to perform most of virtual machine operations from command line. That is good because… you can script virtual machine deployments!
You need to install:
Virtual machine networking
You will need a virtual network to connect virtual machines to the host computer,
libvirt comes with a default nat-based virtual network. You may see details of that network using next command:
It is required to start default network before run installer:
Next command installs a debian net-install in a virtual machine with name node1, RAM 512MB, virtual hard disk with name
node1.img with a maximum of 8GB. If you do not specify other network, default is used.
virt-install script has many options with a lot of detail. The command above is the minimal functional option set that I found, but you probably may improve or customize it.
Now you must connect to the virtual machine console:
…and continue with the typical Debian installation wizard
virsh you are able to do a lot of operation over your virtual machine from command line:
And many many others. Also it is possible to manage virtual machines in remote actual computers (even migrate among them!).
Debian installer preseeding
But we want to improve this procedure. We want to get a basic but fully functional Debian installation with absolutely no manual operation. To make that possible we can use the Debian Install Preseeding system. You need to write a configuration file with the answers to all the wizard questions. For this recipe I am using next preseed file:
[ preseed.cfg ]
You can get detailed information of all these sentences in the Automating the installation using preseeding document.
root-password-crypted line. This contains the MD5 sum for the root account password. This has been created executing the command:
You must make this file accesible for the installer. A simple way is to install
lighttpd and copy it in
Other alternative is to run next commad in the directory containing the file.
virt-install load preseeds
We are going to repeat the installation using the preseed configuration. The new version of the
virt-install command include an
extra-args argument that will be passed as kernel options to the virtual machine:
- ask only critical installation details.
node1as hostname. This way you can use the same pressed file to build many virtual machines.
- URL to fetch the preseed config (at the host webserver in this case).
I want more, please
If you enjoy that, read
virsh manpage and take a look to virt-manager … :-)