Install Cirros on KVM

· Read in about 3 min · (456 words) ·

The other day I needed a small OS to install on KVM just to test that a VM got the right DNS name. I noticed there was a small Linux Distribution called Cirros available in virt-builder.

There were a few small issues starting the image though.

  1. During bootup it tries to load metadata for the VM from the cloud provider it is running on. This makes the bootup quite slow.
  2. The default settings for the DHCP client udhcpc are slow.
  3. Part of the boot output got redirected to ttyS0.
  4. The --hostname setting of virt-builder did not work.
  5. No DNS entry with the hostname is requested.
  6. I also intermittently ran into an issue that it ignored DHCP leases it was offered. Link

Due to the DHCP issue I tried both Cirros 0.3.1 and 0.3.5. 0.3.5 seemed a little bit more prone to the DHCP issue.

Pretty much all the issues can be fixed by using virt-builder's --edit flag.

  1. The cloud metadata loading can be disabled editing the /etc/cirros-init/config file. And setting DATASOURCE_LIST to nocloud.
  2. The udhcpc settings can be configured in /etc/network/interfaces by configuring udhcpc_opts. This does not work anymore in 0.3.5.
  3. Removing console=ttyS0 from the command line in /boot/grub/mendu.lst fixes the output going nowhere.
  4. The hostname is easily fixed by editing /etc/hostname
  5. The DNS entry can be requested via udhcpc_opts as well.
  6. No real solution, it seems a 2nd offer is often accepted. The link above lists some other work arounds.

virt-builder is quite convenient if you want apply some small tweaks to a VM. It's possible to edit files, install packages, copy files into the VM, run commands at bootup, install SSH keys etc. It's worth checking out the man page.

The final incantation to create a cirros-0.3.1 VM on KVM then becomes:

> virt-builder cirros-0.3.1 \
    --format qcow2 \
    --output /var/lib/libvirt/images/cirros31.qcow2 \
    --size 50M \
    --memsize=512 \
    --network \
    --edit '/etc/hostname:s/.+/cirros31/' \
    --edit '/etc/cirros-init/config:s/DATASOURCE_LIST=.+/DATASOURCE_LIST="nocloud"/' \
    --edit '/etc/network/interfaces:s/dhcp/dhcp
udhcpc_opts -t 40 -T 3 -x hostname:cirros31/' \
    --edit '/boot/grub/menu.lst:s/console=ttyS0//'

> virt-install --name=cirros31 \
    --ram=512 \
    --vcpus=1 \
    --disk path=/var/lib/libvirt/images/cirros31.qcow2,format=qcow2,bus=virtio \
    --import \
    --network network:default \
    --noautoconsole

For Cirros 0.3.5 there are some differences:

  • Specifying udhcpc_opts in /etc/network/interfaces doesn't work anymore, so no tweaking of the amount and timeouts for the DHCP requests. I did not find another way to get around the timeouts.
  • It requests the DNS name by default, so that's good.

For simple testing I'd prefer 0.3.1 at the moment. But still you can create a 0.3.5 VM like this:

> virt-builder cirros-0.3.5 \
    --format qcow2 \
    --output /var/lib/libvirt/images/cirros35.qcow2 \
    --size 50M \
    --memsize 512 \
    --network \
    --edit '/etc/hostname:s/.+/cirros35/' \
    --edit '/etc/cirros-init/config:s/DATASOURCE_LIST=.+/DATASOURCE_LIST="nocloud"/' \
    --edit '/boot/grub/menu.lst:s/console=ttyS0//'

> virt-install --name=cirros35 \
    --ram=512 \
    --vcpus=1 \
    --disk path=/var/lib/libvirt/images/cirros35.qcow2,format=qcow2,bus=virtio \
    --import \
    --network network:default \
    --noautoconsole

Enjoy!

comments powered by Disqus