Tip: Create a libvirt guest using virt-builder

virt-builder and virt-install together make it easy to create libvirt guests in just a few minutes.

Before you start, read the installation notes for the OS you’re about to install. They may contain essential tips for a successful installation:

$ virt-builder --notes ubuntu-13.10
[...]

Note I’m running this as root, but that’s only necessary because I want to write the guest to a logical volume. Normally you don’t (and shouldn’t) run virt-builder as root.

# lvcreate -L 50G -n builder-ubuntu1310 /dev/vg_data
# virt-builder ubuntu-13.10 \
    --output /dev/vg_data/builder-ubuntu1310 \
    --hostname builder-ubuntu1310 \
    --install build-essential,debhelper
[   0.0] Downloading: http://libguestfs.org/download/builder/ubuntu-13.10.xz
[   1.0] Uncompressing: http://libguestfs.org/download/builder/ubuntu-13.10.xz
[  23.0] Running virt-resize to expand the disk
[  99.0] Opening the new disk
[ 103.0] Setting a random seed
[ 103.0] Setting the hostname: builder-ubuntu1310
[ 103.0] Random root password: mOQ8YdwKuxkMlpOU [did you mean to use --root-password?]
[ 103.0] Installing packages: build-essential debhelper
[ 423.0] Finishing off
Output: /dev/vg_data/builder-ubuntu1310
Total usable space: 48.2G
Free space: 47.1G (97%)
# virt-install --import \
    --name builder-ubuntu1310 --ram 4096 \
    --disk path=/dev/vg_data/builder-ubuntu1310,format=raw

(Yes, I forgot to use the --root-password option …)

4 Comments

Filed under Uncategorized

4 responses to “Tip: Create a libvirt guest using virt-builder

  1. lzap

    This is so great effort, planning to look on this deeply 🙂

  2. Travis

    This tool looks great. I downloaded and built version 1.23.31. I am not having any success with the –install option. It fails to fetch the package from the network. Any ideas? Thanks!

    $ virt-builder ubuntu-13.10 -o umin-13.10.img –format qcow2 –size 20G –install “iperf” –firstboot-command “dpkg-reconfigure openssh-server” –source “http://libguestfs.org/download/builder/index.asc”[ 0.0] Downloading: http://libguestfs.org/download/builder/ubuntu-13.10.xz
    [ 2.0] Creating disk image: umin-13.10.img
    [ 2.0] Uncompressing: http://libguestfs.org/download/builder/ubuntu-13.10.xz
    [ 38.0] Running virt-resize to expand the disk to 20.0G
    [ 86.0] Opening the new disk
    [ 90.0] Setting a random seed
    [ 90.0] Random root password: Y0CGPqfyu6fRYgUY [did you mean to use –root-password?]
    [ 90.0] Installing packages: iperf
    Reading package lists…
    Building dependency tree…
    Reading state information…
    The following NEW packages will be installed:
    iperf
    0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
    Need to get 56.3 kB of archives.
    After this operation, 174 kB of additional disk space will be used.
    Err http://archive.ubuntu.com/ubuntu/ saucy/universe iperf amd64 2.0.5-3
    Could not resolve ‘archive.ubuntu.com’
    Failed to fetch http://archive.ubuntu.com/ubuntu/pool/universe/i/iperf/iperf_2.0.5-3_amd64.deb Could not resolve ‘archive.ubuntu.com’
    E: Unable to fetch some archives, maybe run apt-get update or try with –fix-missing?
    virt-builder: apt-get -y install ‘iperf’: command exited with an error
    travis@travis-ideapad:~$ ping -c 3 archive.ubuntu.comPING archive.ubuntu.com (91.189.92.177) 56(84) bytes of data.
    64 bytes from zaurac.canonical.com (91.189.92.177): icmp_req=1 ttl=48 time=203 ms
    64 bytes from zaurac.canonical.com (91.189.92.177): icmp_req=2 ttl=48 time=224 ms
    64 bytes from zaurac.canonical.com (91.189.92.177): icmp_req=3 ttl=48 time=246 ms

    — archive.ubuntu.com ping statistics —
    3 packets transmitted, 3 received, 0% packet loss, time 2001ms
    rtt min/avg/max/mdev = 203.258/224.667/246.339/17.597 ms

    • rich

      Yes, there were some fairly spectacular bugs in .31 😦

      You are probably hitting the bug which is fixed by this commit. I would advise trying 1.23.33, which fixes all known problems in virt-builder. Sorry about that.

      • rich

        Actually I think the problem is probably not fixed by the commit I pointed to. However I would try the later version anyway, since it does fix a lot of problems, and if you are still getting a problem then let me know.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.