3 **Parent ticket**: [[!tails_ticket 6354]]
7 This is currently easiest to set up (to avoid backporting, see below)
8 on a Debian Sid box with libvirt installed:
10 sudo apt-get install vagrant
11 vagrant plugin install vagrant-libvirt
13 After this, the Tails branch `feature/vagrant-libvirt` makes
14 everything work like when Vagrant was using Virtualbox, except basebox
17 # Issues (and their workarounds) with vagrant-libvirt
21 `vagrant-libvirt` is not packaged in Debian yet ([[!debbug 753012
22 desc="RFP bug"]]). We need to have it packaged, and then backported
25 Also, some of `vagrant-libvirt`'s dependencies are too old in Wheezy:
27 * `ruby-fog >= 1.10.0`: Sid has 1.12.1 and backporting is trivial
28 (i.e. just rebuild in a Wheezy chroot).
29 * `vagrant >= 1.1`: Sid has 1.2.2, backporting is trivial but also
30 requires packporting the follwing dependencies:
31 - `ruby-childprocess >= 0.3.7`: Sid has 0.3.9 and backporting is
33 - `ruby-net-scp >= 1.1.0`: Sid has 1.1.1 and backporting is almost
34 trivial; tests are failing due to errors loading `ruby-mocha`.
35 This can probably be fixed in
36 `debian/patches/disable-rubygems-in-tests.patch` by requiring
37 `mocha` instead of `mocha/setup` or similar (see the difference
38 between this patch in the Wheezy and Sid sources). It of course
39 builds if tests are disabled (i.e. `DEB_BUILD_OPTIONS=nocheck`).
40 - `ruby-net-ssh >= 2.6.6`: Sid has 2.6.8, and backporting is
41 identical to backporting `ruby-net-scp`, described above.
43 ## Syncing (Tails' Git and built images)
45 When using the libvirt provider in Vagrant, "synced folders" are
46 simply `rsync`:ed into the VM's filesystem, unlike with Vagrant with
47 Virtualbox, which uses its shared folder feature. The `rsync:`ing only
48 happens at VM start (not at VM stop; Vagrant specifies this as legit
49 behaviour, so it's not a bug), so any changes made to Tails' git after
50 that are not pulled into `/amnesia.git` (a VM restart is required),
51 and the built image can't be synced to the host using `/vagrant`
52 (remember, syncing back to host never happens). The current
53 implementation therefore doesn't rely on synced folders but instead:
55 * manually uploads Tails' git before starting the build using
56 Vagrant's upload feature.
57 * manually downloads the built image after building is complete
58 using Vagrant's download feature.
60 Proper synced folders (bidirectional, continously "syncing", like
61 Virtualbox' shared folders) would be preferable (faster, less disk
62 usage (size of Tails' .git) in build guest, less code complexity,
63 etc.), so we'd like this
64 [upstream issue](https://github.com/pradels/vagrant-libvirt/issues/7)
67 It should be noted that the libvirt provider does support shares using
68 NFS, which would give synced folders with the properties we want, but
69 this requires configuring an NFS server on the host box, which makes
70 this approach too complicated.
72 ## Get rid of the Vagrant "verified downloads" monkeypatch
74 We monkeypatch Vagrant to verify the integrity of the downloaded
75 basebox in `vagrant/lib/vagrant_verified_download.rb`. Due to heavy
76 code reorganizing of Vagrant beween 1.0.x and 1.2.x, the monkeypatch
77 isn't very pretty or convenient any more. Although the current one
78 works, it's very fragile, but so are monkeypatches in general. A
79 proper patch has been written and submitted upstream
80 ([issue](https://github.com/mitchellh/vagrant/issues/1124), [pull
81 request](https://github.com/tails-developers/vagrant/pull/1)) and, if
82 accepted, we hopefully can get the next Vagrant containing the patch
87 The squeeze definition on Tails branch `feature/vagrant-libvirt` can
88 be successfully built using KVM (`veewee kvm build squeeze`) with the
89 current release of `veewee` (0.3.7, installed per our
90 [[current instructions|contribute/design/vagrant]]), but:
92 * `veewee kvm export` is not implemented.
93 * the box image is created in the `raw` format, so it consumes the
94 full 10 GiB disk space, and is incompatible with `vagrant-libvirt`,
95 which only supports `qcow2`.
97 Both of these issues are fixed in `veewee`'s Git, but getting it to
98 run/install brought gem dependency hell onto my machine, so I've been
99 unable to test it. Hopefully this will be easier after next realse (so
100 there's a Ruby gem). Having the next version of `veewee` in Debian
101 (and backported to Wheezy) would of course be ideal
102 ([RFP](http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=658863)).
104 Until a `vagrant-libvirt`-compatible `veewee` is released, basebox
105 building won't be fully automatic using `rake` any more. One will have
106 to pick either of steps `1.{a,b,c}` below to create a disk image, and
107 then step `2` to package it into a `.box` (personally I went with
108 `1c + 2` as that doesn't require any fiddling with Ruby gems):
110 ### 1.a How to fix images built with veewee 0.3.7 using KVM
112 For now we can manually convert the `raw` image created by `veewee`
113 like this (note: `squeeze.img` below can be found in your libvirt pool's
116 qemu-img convert -c -O qcow2 squeeze.img box.img
118 ### 1.b How to fix images built with veewee using Virtualbox
120 Since Virtualbox currently is better supported (both be `veewee` and
121 our Rakefile) this may be an easier approach. The disk image can be
122 extracted from the exported `.box` with `tar xf` (or `tar xzf`), and
123 if we assume it's named `box.vmdk` we can make it compatible with
124 `vagrant-libvirt` like this:
126 qemu-img convert -c -O qcow2 box.vmdk box.img
128 ### 1.c How to fix our old squeeze.box
130 We can actually use the disk image `box-disk1.vmdk` from our
131 [old `squeeze.box`](http://dl.amnesia.boum.org/tails/project/vagrant/squeeze.box),
132 unpack it with `tar xf`). While libvirt/KVM supports the vmdk format I
133 recommend converting it to a better supported one (I/O errors are
134 common in libvirt/KVM when using vmdk):
136 qemu-img convert -c -O qcow2 box-disk1.vmdk box-disk1.img
138 Next, setup a `x86_64` domain in libvirt and boot it with a virtual
139 hard drive backed by `box-disk1.img`, and install the new
140 dependencies, which actually only is `rsync`, and while we're at it we
141 might just as well update the system and take steps to reduce the
147 sudo apt-get install rsync
148 sudo apt-get remove virtualbox*
149 sudo apt-get autoremove
151 sudo rm -rf /var/lib/apt/lists/*
152 sudo rm -f /var/lib/dhcp/*.leases
153 sudo dd if=/dev/zero of=/EMPTY bs=1M
155 date | sudo tee /etc/vagrant_box_build_time
158 Note that even though our `box-disk1.img` is in `qcow2` format
159 already, we want to re-convert it using `qemu-img` to reduce the image
160 size (that's why we run `dd` in the VM above):
162 qemu-img convert -c -O qcow2 box-disk1.img box.img
164 ### 2 How to package the .box
166 This is how we package `box.img` from any of the previous steps into a
167 `vagrant-libvirt`-compatible `.box`:
169 echo 'Vagrant.require_plugin "vagrant-libvirt"' > Vagrantfile
170 cat > metadata.json << END
172 "provider" : "libvirt",
177 tar czf squeeze-libvirt.box ./metadata.json ./Vagrantfile ./box.img
179 To test it, temporarily set (overwriting existing values):
181 config.vm.box_url = 'file:///path/to/squeeze-libvirt.box'
182 config.vm.box_checksum = '<sha256 checksum of squeeze-libvirt.box>'
184 in `vagrant/Vagrantfile`.