vagrant-libvirt 0.8.1 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +51 -2076
  3. data/lib/vagrant-libvirt/action/create_domain.rb +57 -94
  4. data/lib/vagrant-libvirt/action/create_network_interfaces.rb +1 -1
  5. data/lib/vagrant-libvirt/action/create_networks.rb +3 -3
  6. data/lib/vagrant-libvirt/action/destroy_domain.rb +21 -5
  7. data/lib/vagrant-libvirt/action/destroy_networks.rb +2 -2
  8. data/lib/vagrant-libvirt/action/handle_box_image.rb +3 -1
  9. data/lib/vagrant-libvirt/action/package_domain.rb +1 -5
  10. data/lib/vagrant-libvirt/action/remove_libvirt_image.rb +3 -1
  11. data/lib/vagrant-libvirt/action/resolve_disk_settings.rb +181 -0
  12. data/lib/vagrant-libvirt/action/snapshot_delete.rb +26 -0
  13. data/lib/vagrant-libvirt/action/snapshot_restore.rb +22 -0
  14. data/lib/vagrant-libvirt/action/snapshot_save.rb +27 -0
  15. data/lib/vagrant-libvirt/action/start_domain.rb +80 -11
  16. data/lib/vagrant-libvirt/action.rb +58 -4
  17. data/lib/vagrant-libvirt/cap/snapshots.rb +12 -0
  18. data/lib/vagrant-libvirt/cap/synced_folder_9p.rb +4 -4
  19. data/lib/vagrant-libvirt/cap/synced_folder_virtiofs.rb +4 -4
  20. data/lib/vagrant-libvirt/config.rb +113 -10
  21. data/lib/vagrant-libvirt/driver.rb +108 -46
  22. data/lib/vagrant-libvirt/errors.rb +23 -3
  23. data/lib/vagrant-libvirt/plugin.rb +7 -3
  24. data/lib/vagrant-libvirt/provider.rb +1 -1
  25. data/lib/vagrant-libvirt/templates/domain.xml.erb +43 -12
  26. data/lib/vagrant-libvirt/util/byte_number.rb +0 -1
  27. data/lib/vagrant-libvirt/util/compat.rb +23 -0
  28. data/lib/vagrant-libvirt/util/domain_flags.rb +15 -0
  29. data/lib/vagrant-libvirt/util/unindent.rb +7 -0
  30. data/lib/vagrant-libvirt/util.rb +1 -0
  31. data/lib/vagrant-libvirt/version +1 -1
  32. data/locales/en.yml +28 -4
  33. data/spec/acceptance/additional_storage_spec.rb +32 -0
  34. data/spec/acceptance/package_domain_spec.rb +90 -0
  35. data/spec/acceptance/provider_settings_spec.rb +54 -0
  36. data/spec/acceptance/simple_vm_provision_via_shell_spec.rb +31 -0
  37. data/spec/acceptance/snapshots_spec.rb +41 -0
  38. data/spec/acceptance/support-skeletons/package_complex/Vagrantfile.testbox +14 -0
  39. data/spec/acceptance/support-skeletons/package_complex/scripts/sysprep.sh +32 -0
  40. data/spec/acceptance/support-skeletons/package_simple/Vagrantfile.testbox +10 -0
  41. data/spec/acceptance/two_disks_spec.rb +29 -0
  42. data/spec/acceptance/use_qemu_agent_for_connectivity_spec.rb +35 -0
  43. data/spec/spec_helper.rb +3 -0
  44. data/spec/support/acceptance/configuration.rb +21 -0
  45. data/spec/support/acceptance/context.rb +70 -0
  46. data/spec/support/acceptance/isolated_environment.rb +41 -0
  47. data/spec/support/libvirt_acceptance_context.rb +64 -0
  48. data/spec/support/libvirt_context.rb +4 -0
  49. data/spec/support/sharedcontext.rb +1 -0
  50. data/spec/unit/action/cleanup_on_failure_spec.rb +0 -2
  51. data/spec/unit/action/create_domain_spec/sysinfo.xml +66 -0
  52. data/spec/unit/action/create_domain_spec/sysinfo_only_required.xml +49 -0
  53. data/spec/unit/action/create_domain_spec.rb +188 -140
  54. data/spec/unit/action/create_domain_volume_spec.rb +0 -3
  55. data/spec/unit/action/destroy_domain_spec.rb +43 -10
  56. data/spec/unit/action/forward_ports_spec.rb +0 -1
  57. data/spec/unit/action/handle_box_image_spec.rb +31 -14
  58. data/spec/unit/action/package_domain_spec.rb +0 -5
  59. data/spec/unit/action/remove_libvirt_image_spec.rb +43 -0
  60. data/spec/unit/action/resolve_disk_settings_spec/default_domain.xml +43 -0
  61. data/spec/unit/action/resolve_disk_settings_spec/default_no_aliases.xml +42 -0
  62. data/spec/unit/action/{create_domain_spec → resolve_disk_settings_spec}/default_system_storage_pool.xml +0 -0
  63. data/spec/unit/action/resolve_disk_settings_spec/multi_volume_box.xml +55 -0
  64. data/spec/unit/action/resolve_disk_settings_spec/multi_volume_box_additional_and_custom_no_aliases.xml +67 -0
  65. data/spec/unit/action/resolve_disk_settings_spec/multi_volume_box_additional_storage.xml +67 -0
  66. data/spec/unit/action/resolve_disk_settings_spec.rb +385 -0
  67. data/spec/unit/action/start_domain_spec/clock_timer_removed.xml +38 -0
  68. data/spec/unit/action/start_domain_spec/clock_timer_rtc_tsc.xml +39 -0
  69. data/spec/unit/action/start_domain_spec/existing_added_nvram.xml +62 -0
  70. data/spec/unit/action/start_domain_spec/nvram_domain.xml +64 -0
  71. data/spec/unit/action/start_domain_spec/nvram_domain_other_setting.xml +64 -0
  72. data/spec/unit/action/start_domain_spec/nvram_domain_removed.xml +64 -0
  73. data/spec/unit/action/start_domain_spec.rb +122 -22
  74. data/spec/unit/action/wait_till_up_spec.rb +0 -2
  75. data/spec/unit/action_spec.rb +88 -3
  76. data/spec/unit/cap/synced_folder_9p_spec.rb +120 -0
  77. data/spec/unit/cap/synced_folder_virtiofs_spec.rb +120 -0
  78. data/spec/unit/config_spec.rb +151 -6
  79. data/spec/unit/driver_spec.rb +3 -1
  80. data/spec/unit/plugin_spec.rb +42 -0
  81. data/spec/unit/templates/domain_all_settings.xml +21 -6
  82. data/spec/unit/templates/domain_scsi_bus_storage.xml +44 -0
  83. data/spec/unit/templates/domain_scsi_device_storage.xml +44 -0
  84. data/spec/unit/templates/domain_scsi_multiple_controllers_storage.xml +130 -0
  85. data/spec/unit/templates/domain_spec.rb +106 -21
  86. data/spec/unit/util/byte_number_spec.rb +1 -1
  87. metadata +169 -79
  88. data/spec/unit/provider_spec.rb +0 -11
data/README.md CHANGED
@@ -1,2102 +1,71 @@
1
1
  # Vagrant Libvirt Provider
2
2
 
3
- [![Join the chat at https://gitter.im/vagrant-libvirt/vagrant-libvirt](https://badges.gitter.im/vagrant-libvirt/vagrant-libvirt.svg)](https://gitter.im/vagrant-libvirt/vagrant-libvirt?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
4
- [![Build Status](https://github.com/vagrant-libvirt/vagrant-libvirt/actions/workflows/unit-tests.yml/badge.svg)](https://github.com/vagrant-libvirt/vagrant-libvirt/actions/workflows/unit-tests.yml)
5
- [![Coverage Status](https://coveralls.io/repos/github/vagrant-libvirt/vagrant-libvirt/badge.svg?branch=master)](https://coveralls.io/github/vagrant-libvirt/vagrant-libvirt?branch=master)
6
- [![Gem Version](https://badge.fury.io/rb/vagrant-libvirt.svg)](https://badge.fury.io/rb/vagrant-libvirt)
7
-
8
- This is a [Vagrant](http://www.vagrantup.com) plugin that adds a
9
- [Libvirt](http://libvirt.org) provider to Vagrant, allowing Vagrant to
10
- control and provision machines via Libvirt toolkit.
11
-
12
- **Note:** Actual version is still a development one. Feedback is welcome and
13
- can help a lot :-)
14
-
15
- ## Index
16
-
17
- <!-- note in vim set "let g:vmt_list_item_char='-'" to generate the correct output -->
18
- <!-- vim-markdown-toc GFM -->
19
-
20
- * [Features](#features)
21
- * [Future work](#future-work)
22
- * [Using the container image](#using-the-container-image)
23
- * [Using Docker](#using-docker)
24
- * [Using Podman](#using-podman)
25
- * [Extending the Docker image with additional vagrant plugins](#extending-the-docker-image-with-additional-vagrant-plugins)
26
- * [Installation](#installation)
27
- * [Possible problems with plugin installation on Linux](#possible-problems-with-plugin-installation-on-linux)
28
- * [Additional Notes for Fedora and Similar Linux Distributions](#additional-notes-for-fedora-and-similar-linux-distributions)
29
- * [Vagrant Project Preparation](#vagrant-project-preparation)
30
- * [Add Box](#add-box)
31
- * [Create Vagrantfile](#create-vagrantfile)
32
- * [Start VM](#start-vm)
33
- * [How Project Is Created](#how-project-is-created)
34
- * [Libvirt Configuration](#libvirt-configuration)
35
- * [Provider Options](#provider-options)
36
- * [Domain Specific Options](#domain-specific-options)
37
- * [Reload behavior](#reload-behavior)
38
- * [Networks](#networks)
39
- * [Private Network Options](#private-network-options)
40
- * [Public Network Options](#public-network-options)
41
- * [Management Network](#management-network)
42
- * [Additional Disks](#additional-disks)
43
- * [Reload behavior](#reload-behavior-1)
44
- * [CDROMs](#cdroms)
45
- * [Input](#input)
46
- * [PCI device passthrough](#pci-device-passthrough)
47
- * [Using USB Devices](#using-usb-devices)
48
- * [USB Controller Configuration](#usb-controller-configuration)
49
- * [USB Device Passthrough](#usb-device-passthrough)
50
- * [USB Redirector Devices](#usb-redirector-devices)
51
- * [Filter for USB Redirector Devices](#filter-for-usb-redirector-devices)
52
- * [Serial Console Devices](#serial-console-devices)
53
- * [Random number generator passthrough](#random-number-generator-passthrough)
54
- * [Watchdog device](#watchdog-device)
55
- * [Smartcard device](#smartcard-device)
56
- * [Hypervisor Features](#hypervisor-features)
57
- * [Clock](#clock)
58
- * [CPU features](#cpu-features)
59
- * [Memory Backing](#memory-backing)
60
- * [No box and PXE boot](#no-box-and-pxe-boot)
61
- * [SSH Access To VM](#ssh-access-to-vm)
62
- * [Forwarded Ports](#forwarded-ports)
63
- * [Forwarding the ssh-port](#forwarding-the-ssh-port)
64
- * [Synced Folders](#synced-folders)
65
- * [QEMU Session Support](#qemu-session-support)
66
- * [Customized Graphics](#customized-graphics)
67
- * [TPM Devices](#tpm-devices)
68
- * [Memory balloon](#memory-balloon)
69
- * [Libvirt communication channels](#libvirt-communication-channels)
70
- * [Custom command line arguments and environment variables](#custom-command-line-arguments-and-environment-variables)
71
- * [Box Formats](#box-formats)
72
- * [Version 1](#version-1)
73
- * [Version 2 (Experimental)](#version-2-experimental)
74
- * [Create Box](#create-box)
75
- * [Package Box from VM](#package-box-from-vm)
76
- * [Troubleshooting VMs](#troubleshooting-vms)
77
- * [Development](#development)
78
- * [Contributing](#contributing)
79
-
80
- <!-- vim-markdown-toc -->
81
-
82
- ## Features
83
-
84
- * Control local Libvirt hypervisors.
85
- * Vagrant `up`, `destroy`, `suspend`, `resume`, `halt`, `ssh`, `reload`,
86
- `package` and `provision` commands.
87
- * Upload box image (qcow2 format) to Libvirt storage pool.
88
- * Create volume as COW diff image for domains.
89
- * Create private networks.
90
- * Create and boot Libvirt domains.
91
- * SSH into domains.
92
- * Setup hostname and network interfaces.
93
- * Provision domains with any built-in Vagrant provisioner.
94
- * Synced folder support via `rsync`, `nfs`, `9p` or `virtiofs`.
95
- * Snapshots via [sahara](https://github.com/jedi4ever/sahara).
96
- * Package caching via
97
- [vagrant-cachier](http://fgrehm.viewdocs.io/vagrant-cachier/).
98
- * Use boxes from other Vagrant providers via
99
- [vagrant-mutate](https://github.com/sciurus/vagrant-mutate).
100
- * Support VMs with no box for PXE boot purposes (Vagrant 1.6 and up)
101
-
102
- ## Future work
103
-
104
- * Take a look at [open
105
- issues](https://github.com/vagrant-libvirt/vagrant-libvirt/issues?state=open).
106
-
107
- ## Using the container image
108
-
109
- Due to the number of issues encountered around compatibility between the ruby runtime environment
110
- that is part of the upstream vagrant installation and the library dependencies of libvirt that
111
- this project requires to communicate with libvirt, there is a docker image build and published.
112
-
113
- This should allow users to execute vagrant with vagrant-libvirt without needing to deal with
114
- the compatibility issues, though you may need to extend the image for your own needs should
115
- you make use of additional plugins.
116
-
117
- Note the default image contains the full toolchain required to build and install vagrant-libvirt
118
- and it's dependencies. There is also a smaller image published with the `-slim` suffix if you
119
- just need vagrant-libvirt and don't need to install any additional plugins for your environment.
120
-
121
- If you are connecting to a remote system libvirt, you may omit the
122
- `-v /var/run/libvirt/:/var/run/libvirt/` mount bind. Some distributions patch the local
123
- vagrant environment to ensure vagrant-libvirt uses `qemu:///session`, which means you
124
- may need to set the environment variable `LIBVIRT_DEFAULT_URI` to the same value if
125
- looking to use this in place of your distribution provided installation.
126
-
127
- ### Using Docker
128
-
129
- To get the image with the most recent release:
130
- ```bash
131
- docker pull vagrantlibvirt/vagrant-libvirt:latest
132
- ```
133
-
134
- ---
135
- **Note** If you want the very latest code you can use the `edge` tag instead.
136
-
137
- ```bash
138
- docker pull vagrantlibvirt/vagrant-libvirt:edge
139
- ```
140
- ---
141
-
142
- Running the image:
143
- ```bash
144
- docker run -i --rm \
145
- -e LIBVIRT_DEFAULT_URI \
146
- -v /var/run/libvirt/:/var/run/libvirt/ \
147
- -v ~/.vagrant.d:/.vagrant.d \
148
- -v $(realpath "${PWD}"):${PWD} \
149
- -w $(realpath "${PWD}") \
150
- --network host \
151
- vagrantlibvirt/vagrant-libvirt:latest \
152
- vagrant status
153
- ```
154
-
155
- It's possible to define a function in `~/.bashrc`, for example:
156
- ```bash
157
- vagrant(){
158
- docker run -i --rm \
159
- -e LIBVIRT_DEFAULT_URI \
160
- -v /var/run/libvirt/:/var/run/libvirt/ \
161
- -v ~/.vagrant.d:/.vagrant.d \
162
- -v $(realpath "${PWD}"):${PWD} \
163
- -w $(realpath "${PWD}") \
164
- --network host \
165
- vagrantlibvirt/vagrant-libvirt:latest \
166
- vagrant $@
167
- }
168
-
169
- ```
170
-
171
- ### Using Podman
172
-
173
- Preparing the podman run, only once:
174
-
175
- ```bash
176
- mkdir -p ~/.vagrant.d/{boxes,data,tmp}
177
- ```
178
- _N.B. This is needed until the entrypoint works for podman to only mount the `~/.vagrant.d` directory_
179
-
180
- To run with Podman you need to include
181
-
182
- ```bash
183
- --entrypoint /bin/bash \
184
- --security-opt label=disable \
185
- -v ~/.vagrant.d/boxes:/vagrant/boxes \
186
- -v ~/.vagrant.d/data:/vagrant/data \
187
- -v ~/.vagrant.d/tmp:/vagrant/tmp \
188
- ```
189
-
190
- for example:
191
-
192
- ```bash
193
- vagrant(){
194
- podman run -it --rm \
195
- -e LIBVIRT_DEFAULT_URI \
196
- -v /var/run/libvirt/:/var/run/libvirt/ \
197
- -v ~/.vagrant.d/boxes:/vagrant/boxes \
198
- -v ~/.vagrant.d/data:/vagrant/data \
199
- -v ~/.vagrant.d/tmp:/vagrant/tmp \
200
- -v $(realpath "${PWD}"):${PWD} \
201
- -w $(realpath "${PWD}") \
202
- --network host \
203
- --entrypoint /bin/bash \
204
- --security-opt label=disable \
205
- docker.io/vagrantlibvirt/vagrant-libvirt:latest \
206
- vagrant $@
207
- }
208
- ```
209
-
210
- Running Podman in rootless mode maps the root user inside the container to your host user so we need to bypass [entrypoint.sh](https://github.com/vagrant-libvirt/vagrant-libvirt/blob/master/entrypoint.sh) and mount persistent storage directly to `/vagrant`.
211
-
212
- ### Extending the Docker image with additional vagrant plugins
213
-
214
- By default the image published and used contains the entire tool chain required
215
- to reinstall the vagrant-libvirt plugin and it's dependencies, as this is the
216
- default behaviour of vagrant anytime a new plugin is installed. This means it
217
- should be possible to use a simple `FROM` statement and ask vagrant to install
218
- additional plugins.
219
-
220
- ```
221
- FROM vagrantlibvirt/vagrant-libvirt:latest
222
-
223
- RUN vagrant plugin install <plugin>
224
- ```
225
-
226
- ## Installation
227
-
228
- First, you should have both QEMU and Libvirt installed if you plan to run VMs
229
- on your local system. For instructions, refer to your Linux distribution's
230
- documentation.
231
-
232
- **NOTE:** Before you start using vagrant-libvirt, please make sure your Libvirt
233
- and QEMU installation is working correctly and you are able to create QEMU or
234
- KVM type virtual machines with `virsh` or `virt-manager`.
235
-
236
- Next, you must have [Vagrant
237
- installed](http://docs.vagrantup.com/v2/installation/index.html).
238
- Vagrant-libvirt supports Vagrant 2.0, 2.1 & 2.2. It should also work with earlier
239
- releases from 1.5 onwards but they are not actively tested.
240
-
241
- Check the [unit tests](https://github.com/vagrant-libvirt/vagrant-libvirt/blob/master/.github/workflows/unit-tests.yml)
242
- for the current list of tested versions.
243
-
244
- *We only test with the upstream version!* If you decide to install your distro's
245
- version and you run into problems, as a first step you should switch to upstream.
246
-
247
- Now you need to make sure your have all the build dependencies installed for
248
- vagrant-libvirt. This depends on your distro. An overview:
249
-
250
- * Ubuntu 18.10, Debian 9 and up:
251
- ```shell
252
- apt-get build-dep vagrant ruby-libvirt
253
- apt-get install qemu libvirt-daemon-system libvirt-clients ebtables dnsmasq-base
254
- apt-get install libxslt-dev libxml2-dev libvirt-dev zlib1g-dev ruby-dev
255
- apt-get install libguestfs-tools
256
- ```
257
-
258
- * Ubuntu 18.04, Debian 8 and older:
259
- ```shell
260
- apt-get build-dep vagrant ruby-libvirt
261
- apt-get install qemu libvirt-bin ebtables dnsmasq-base
262
- apt-get install libxslt-dev libxml2-dev libvirt-dev zlib1g-dev ruby-dev
263
- apt-get install libguestfs-tools
264
- ```
265
-
266
- (It is possible some users will already have libraries from the third line installed, but this is the way to make it work OOTB.)
267
-
268
- * CentOS 6, 7, Fedora 21:
269
- ```shell
270
- yum install qemu libvirt libvirt-devel ruby-devel gcc qemu-kvm libguestfs-tools
271
- ```
272
-
273
- * Fedora 22 and up:
274
- ```shell
275
- dnf install -y gcc libvirt libvirt-devel libxml2-devel make ruby-devel libguestfs-tools
276
- ```
277
-
278
- * OpenSUSE leap 15.1:
279
- ```shell
280
- zypper install qemu libvirt libvirt-devel ruby-devel gcc qemu-kvm libguestfs
281
- ```
282
-
283
- * Arch Linux: please read the related [ArchWiki](https://wiki.archlinux.org/index.php/Vagrant#vagrant-libvirt) page.
284
- ```shell
285
- pacman -S vagrant
286
- ```
287
-
288
- Now you're ready to install vagrant-libvirt using standard [Vagrant
289
- plugin](http://docs.vagrantup.com/v2/plugins/usage.html) installation methods.
290
-
291
- For some distributions you will need to specify `CONFIGURE_ARGS` variable before
292
- running `vagrant plugin install`:
293
-
294
- * Fedora 32 + upstream Vagrant:
295
- ```shell
296
- export CONFIGURE_ARGS="with-libvirt-include=/usr/include/libvirt with-libvirt-lib=/usr/lib64"
297
- ```
298
-
299
- ```shell
300
- vagrant plugin install vagrant-libvirt
301
- ```
302
-
303
- ### Possible problems with plugin installation on Linux
304
-
305
- In case of problems with building nokogiri and ruby-libvirt gem, install
306
- missing development libraries for libxslt, libxml2 and libvirt.
307
-
308
-
309
- On Ubuntu, Debian, make sure you are running all three of the `apt` commands above with `sudo`.
310
-
311
-
312
- On RedHat, Centos, Fedora, ...
313
-
314
- ```shell
315
- $ sudo dnf install libxslt-devel libxml2-devel libvirt-devel ruby-devel gcc
316
- ```
317
-
318
- On Arch Linux it is recommended to follow [steps from ArchWiki](https://wiki.archlinux.org/index.php/Vagrant#vagrant-libvirt).
319
-
320
- If have problem with installation - check your linker. It should be `ld.gold`:
321
-
322
- ```shell
323
- sudo alternatives --set ld /usr/bin/ld.gold
324
- # OR
325
- sudo ln -fs /usr/bin/ld.gold /usr/bin/ld
326
- ```
327
-
328
- If you have issues building ruby-libvirt, try the following:
329
- ```shell
330
- CONFIGURE_ARGS='with-ldflags=-L/opt/vagrant/embedded/lib with-libvirt-include=/usr/include/libvirt with-libvirt-lib=/usr/lib' GEM_HOME=~/.vagrant.d/gems GEM_PATH=$GEM_HOME:/opt/vagrant/embedded/gems PATH=/opt/vagrant/embedded/bin:$PATH vagrant plugin install vagrant-libvirt
331
- ```
332
- ### Additional Notes for Fedora and Similar Linux Distributions
333
-
334
- If you encounter the following load error when using the vagrant-libvirt plugin (note the required by libssh):
335
-
336
- ```shell
337
- /opt/vagrant/embedded/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require': /opt/vagrant/embedded/lib64/libcrypto.so.1.1: version `OPENSSL_1_1_1b' not found (required by /lib64/libssh.so.4) - /home/xxx/.vagrant.d/gems/2.4.6/gems/ruby-libvirt-0.7.1/lib/_libvirt.so (LoadError)
338
- ```
339
- then the following steps have been found to resolve the problem. Thanks to James Reynolds (see https://github.com/hashicorp/vagrant/issues/11020#issuecomment-540043472). The specific version of libssh will change over time so references to the rpm in the commands below will need to be adjusted accordingly.
340
-
341
- ```shell
342
- # Fedora
343
- dnf download --source libssh
344
-
345
- # centos 8 stream, doesn't provide source RPMs, so you need to download like so
346
- git clone https://git.centos.org/centos-git-common
347
- # centos-git-common needs its tools in PATH
348
- export PATH=$(readlink -f ./centos-git-common):$PATH
349
- git clone https://git.centos.org/rpms/libssh
350
- cd libssh
351
- git checkout imports/c8s/libssh-0.9.4-1.el8
352
- into_srpm.sh -d c8s
353
- cd SRPMS
354
-
355
- # common commands (make sure to adjust verison accordingly)
356
- rpm2cpio libssh-0.9.0-5.fc30.src.rpm | cpio -imdV
357
- tar xf libssh-0.9.0.tar.xz
358
- mkdir build
359
- cd build
360
- cmake ../libssh-0.9.0 -DOPENSSL_ROOT_DIR=/opt/vagrant/embedded/
361
- make
362
- sudo cp lib/libssh* /opt/vagrant/embedded/lib64
363
- ```
364
-
365
- If you encounter the following load error when using the vagrant-libvirt plugin (note the required by libk5crypto):
366
-
367
- ```shell
368
- /opt/vagrant/embedded/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require': /usr/lib64/libk5crypto.so.3: undefined symbol: EVP_KDF_ctrl, version OPENSSL_1_1_1b - /home/rbelgrave/.vagrant.d/gems/2.4.9/gems/ruby-libvirt-0.7.1/lib/_libvirt.so (LoadError)
369
- ```
370
-
371
- then the following steps have been found to resolve the problem. After the steps below are complete, then reinstall the vagrant-libvirt plugin without setting the `CONFIGURE_ARGS`. Thanks to Marco Bevc (see https://github.com/hashicorp/vagrant/issues/11020#issuecomment-625801983):
372
-
373
- ```shell
374
- # Fedora
375
- dnf download --source krb5-libs
376
-
377
- # centos 8 stream, doesn't provide source RPMs, so you need to download like so
378
- git clone https://git.centos.org/centos-git-common
379
- # centos-git-common needs its tools in PATH
380
- export PATH=$(readlink -f ./centos-git-common):$PATH
381
- git clone https://git.centos.org/rpms/krb5
382
- cd krb5
383
- git checkout imports/c8s/krb5-1.18.2-8.el8
384
- into_srpm.sh -d c8s
385
- cd SRPMS
386
-
387
- # common commands (make sure to adjust verison accordingly)
388
- rpm2cpio krb5-1.18-1.fc32.src.rpm | cpio -imdV
389
- tar xf krb5-1.18.tar.gz
390
- cd krb5-1.18/src
391
- ./configure
392
- make
393
- sudo cp -P lib/crypto/libk5crypto.* /opt/vagrant/embedded/lib64/
394
- ```
395
-
396
- ## Vagrant Project Preparation
397
-
398
- ### Add Box
399
-
400
- After installing the plugin (instructions above), the quickest way to get
401
- started is to add Libvirt box and specify all the details manually within a
402
- `config.vm.provider` block. So first, add Libvirt box using any name you want.
403
- You can find more Libvirt-ready boxes at
404
- [Vagrant Cloud](https://app.vagrantup.com/boxes/search?provider=libvirt). For
405
- example:
406
-
407
- ```shell
408
- vagrant init fedora/32-cloud-base
409
- ```
410
-
411
- ### Create Vagrantfile
412
-
413
- And then make a Vagrantfile that looks like the following, filling in your
414
- information where necessary. For example:
415
-
416
- ```ruby
417
- Vagrant.configure("2") do |config|
418
- config.vm.define :test_vm do |test_vm|
419
- test_vm.vm.box = "fedora/32-cloud-base"
420
- end
421
- end
422
- ```
423
-
424
- ### Start VM
425
-
426
- In prepared project directory, run following command:
427
-
428
- ```shell
429
- $ vagrant up --provider=libvirt
430
- ```
431
-
432
- Vagrant needs to know that we want to use Libvirt and not default VirtualBox.
433
- That's why there is `--provider=libvirt` option specified. Other way to tell
434
- Vagrant to use Libvirt provider is to setup environment variable
435
-
436
- ```shell
437
- export VAGRANT_DEFAULT_PROVIDER=libvirt
438
- ```
439
-
440
- ### How Project Is Created
441
-
442
- Vagrant goes through steps below when creating new project:
443
-
444
- 1. Connect to Libvirt locally or remotely via SSH.
445
- 2. Check if box image is available in Libvirt storage pool. If not, upload it
446
- to remote Libvirt storage pool as new volume.
447
- 3. Create COW diff image of base box image for new Libvirt domain.
448
- 4. Create and start new domain on Libvirt host.
449
- 5. Check for DHCP lease from dnsmasq server.
450
- 6. Wait till SSH is available.
451
- 7. Sync folders and run Vagrant provisioner on new domain if setup in
452
- Vagrantfile.
453
-
454
- ### Libvirt Configuration
455
-
456
- ### Provider Options
457
-
458
- Although it should work without any configuration for most people, this
459
- provider exposes quite a few provider-specific configuration options. The
460
- following options allow you to configure how vagrant-libvirt connects to
461
- Libvirt, and are used to generate the [Libvirt connection
462
- URI](http://libvirt.org/uri.html):
463
-
464
- * `driver` - A hypervisor name to access. For now only KVM and QEMU are
465
- supported
466
- * `host` - The name of the server, where Libvirtd is running
467
- * `connect_via_ssh` - If use ssh tunnel to connect to Libvirt. Absolutely
468
- needed to access Libvirt on remote host. It will not be able to get the IP
469
- address of a started VM otherwise.
470
- * `username` - Username and password to access Libvirt
471
- * `password` - Password to access Libvirt
472
- * `id_ssh_key_file` - If not nil, uses this ssh private key to access Libvirt.
473
- Default is `$HOME/.ssh/id_rsa`. Prepends `$HOME/.ssh/` if no directory
474
- * `socket` - Path to the Libvirt unix socket (e.g.
475
- `/var/run/libvirt/libvirt-sock`)
476
- * `proxy_command` - For advanced usage. When connecting to remote libvirt
477
- instances, if the default constructed proxy\_command which uses `-W %h:%p`
478
- does not work, set this as needed. It performs interpolation using `{key}`
479
- and supports only `{host}`, `{username}`, and `{id_ssh_key_file}`. This is
480
- to try and avoid issues with escaping `%` and `$` which might be necessary
481
- to the ssh command itself. e.g.:
482
- `libvirt.proxy_command = "ssh {host} -l {username} -i {id_ssh_key_file} nc %h %p"`
483
- * `uri` - For advanced usage. Directly specifies what Libvirt connection URI
484
- vagrant-libvirt should use. Overrides all other connection configuration
485
- options
486
-
487
- In the event that none of these are set (excluding the `driver` option) the
488
- provider will attempt to retrieve the uri from the environment variable
489
- `LIBVIRT_DEFAULT_URI` similar to how virsh works. If any of them are set, it
490
- will ignore the environment variable. The reason the driver option is ignored
491
- is that it is not uncommon for this to be explicitly set on the box itself
492
- and there is no easily to determine whether it is being set by the user or
493
- the box packager.
494
-
495
- Connection-independent options:
496
-
497
- * `storage_pool_name` - Libvirt storage pool name, where box image and instance
498
- snapshots (if `snapshot_pool_name` is not set) will be stored.
499
- * `snapshot_pool_name` - Libvirt storage pool name. If set, the created
500
- snapshot of the instance will be stored at this location instead of
501
- `storage_pool_name`.
502
-
503
- For example:
504
-
505
- ```ruby
506
- Vagrant.configure("2") do |config|
507
- config.vm.provider :libvirt do |libvirt|
508
- libvirt.host = "example.com"
509
- end
510
- end
511
- ```
512
-
513
- ### Domain Specific Options
514
-
515
- * `title` - A short description of the domain.
516
- * `description` - A human readable description of the virtual machine.
517
- * `disk_bus` - The type of disk device to emulate. Defaults to virtio if not
518
- set. Possible values are documented in Libvirt's [description for
519
- _target_](http://libvirt.org/formatdomain.html#elementsDisks). NOTE: this
520
- option applies only to disks associated with a box image. To set the bus type
521
- on additional disks, see the [Additional Disks](#additional-disks) section.
522
- * `disk_device` - The disk device to emulate. Defaults to vda if not
523
- set, which should be fine for paravirtualized guests, but some fully
524
- virtualized guests may require hda. NOTE: this option also applies only to
525
- disks associated with a box image.
526
- * `disk_driver` - Extra options for the main disk driver ([see Libvirt documentation](http://libvirt.org/formatdomain.html#elementsDisks)).
527
- NOTE: this option also applies only to disks associated with a box image. In all cases, the value `nil` can be used to force the hypervisor default behaviour (e.g. to override settings defined in top-level Vagrantfiles). Supported options include:
528
- * `:cache` - Controls the cache mechanism. Possible values are "default", "none", "writethrough", "writeback", "directsync" and "unsafe".
529
- * `:io` - Controls specific policies on I/O. Possible values are "threads" and "native".
530
- * `:copy_on_read` - Controls whether to copy read backing file into the image file. The value can be either "on" or "off".
531
- * `:discard` - Controls whether discard requests (also known as "trim" or "unmap") are ignored or passed to the filesystem. Possible values are "unmap" or "ignore".
532
- Note: for discard to work, you will likely also need to set `disk_bus = 'scsi'`
533
- * `:detect_zeroes` - Controls whether to detect zero write requests. The value can be "off", "on" or "unmap".
534
- * `nic_model_type` - parameter specifies the model of the network adapter when
535
- you create a domain value by default virtio KVM believe possible values, see
536
- the [documentation for
537
- Libvirt](https://libvirt.org/formatdomain.html#elementsNICSModel).
538
- * `shares` - Proportional weighted share for the domain relative to others. For more details see [documentation](https://libvirt.org/formatdomain.html#elementsCPUTuning).
539
- * `memory` - Amount of memory in MBytes. Defaults to 512 if not set.
540
- * `cpus` - Number of virtual cpus. Defaults to 1 if not set.
541
- * `cpuset` - Physical cpus to which the vcpus can be pinned. For more details see [documentation](https://libvirt.org/formatdomain.html#elementsCPUAllocation).
542
- * `cputopology` - Number of CPU sockets, cores and threads running per core. All fields of `:sockets`, `:cores` and `:threads` are mandatory, `cpus` domain option must be present and must be equal to total count of **sockets * cores * threads**. For more details see [documentation](https://libvirt.org/formatdomain.html#elementsCPU).
543
- * `nodeset` - Physical NUMA nodes where virtual memory can be pinned. For more details see [documentation](https://libvirt.org/formatdomain.html#elementsNUMATuning).
544
-
545
- ```ruby
546
- Vagrant.configure("2") do |config|
547
- config.vm.provider :libvirt do |libvirt|
548
- libvirt.cpus = 4
549
- libvirt.cpuset = '1-4,^3,6'
550
- libvirt.cputopology :sockets => '2', :cores => '2', :threads => '1'
551
- end
552
- end
553
- ```
554
-
555
- * `nested` - [Enable nested
556
- virtualization](https://docs.fedoraproject.org/en-US/quick-docs/using-nested-virtualization-in-kvm/).
557
- Default is false.
558
- * `cpu_mode` - [CPU emulation
559
- mode](https://libvirt.org/formatdomain.html#elementsCPU). Defaults to
560
- 'host-model' if not set. Allowed values: host-model, host-passthrough,
561
- custom.
562
- * `cpu_model` - CPU Model. Defaults to 'qemu64' if not set and `cpu_mode` is
563
- `custom` and to '' otherwise. This can really only be used when setting
564
- `cpu_mode` to `custom`.
565
- * `cpu_fallback` - Whether to allow Libvirt to fall back to a CPU model close
566
- to the specified model if features in the guest CPU are not supported on the
567
- host. Defaults to 'allow' if not set. Allowed values: `allow`, `forbid`.
568
- * `numa_nodes` - Specify an array of NUMA nodes for the guest. The syntax is similar to what would be set in the domain XML. `memory` must be in MB. Symmetrical and asymmetrical topologies are supported but make sure your total count of defined CPUs adds up to `v.cpus`.
569
-
570
- The sum of all the memory defined here will act as your total memory for your guest VM. **This sum will override what is set in `v.memory`**
571
- ```
572
- v.cpus = 4
573
- v.numa_nodes = [
574
- {:cpus => "0-1", :memory => "1024"},
575
- {:cpus => "2-3", :memory => "4096"}
576
- ]
577
- ```
578
- * `loader` - Sets path to custom UEFI loader.
579
- * `kernel` - To launch the guest with a kernel residing on host filesystems.
580
- Equivalent to qemu `-kernel`.
581
- * `initrd` - To specify the initramfs/initrd to use for the guest. Equivalent
582
- to qemu `-initrd`.
583
- * `random_hostname` - To create a domain name with extra information on the end
584
- to prevent hostname conflicts.
585
- * `default_prefix` - The default Libvirt guest name becomes a concatenation of the
586
- `<current_directory>_<guest_name>`. The current working directory is the default prefix
587
- to the guest name. The `default_prefix` options allow you to set the guest name prefix.
588
- * `cmd_line` - Arguments passed on to the guest kernel initramfs or initrd to
589
- use. Equivalent to qemu `-append`, only possible to use in combination with `initrd` and `kernel`.
590
- * `graphics_type` - Sets the protocol used to expose the guest display.
591
- Defaults to `vnc`. Possible values are "sdl", "curses", "none", "gtk", "vnc"
592
- or "spice".
593
- * `graphics_port` - Sets the port for the display protocol to bind to.
594
- Defaults to 5900.
595
- * `graphics_ip` - Sets the IP for the display protocol to bind to. Defaults to
596
- "127.0.0.1".
597
- * `graphics_passwd` - Sets the password for the display protocol. Working for
598
- vnc and Spice. by default working without passsword.
599
- * `graphics_autoport` - Sets autoport for graphics, Libvirt in this case
600
- ignores graphics_port value, Defaults to 'yes'. Possible value are "yes" and
601
- "no"
602
- * `graphics_gl` - Set to `true` to enable OpenGL. Defaults to `true` if
603
- `video_accel3d` is `true`.
604
- * `keymap` - Set keymap for vm. default: en-us
605
- * `kvm_hidden` - [Hide the hypervisor from the
606
- guest](https://libvirt.org/formatdomain.html#elementsFeatures). Useful for
607
- [GPU passthrough](#pci-device-passthrough) on stubborn drivers. Default is false.
608
- * `video_type` - Sets the graphics card type exposed to the guest. Defaults to
609
- "cirrus". [Possible
610
- values](http://libvirt.org/formatdomain.html#elementsVideo) are "vga",
611
- "cirrus", "vmvga", "xen", "vbox", or "qxl".
612
- * `video_vram` - Used by some graphics card types to vary the amount of RAM
613
- dedicated to video. Defaults to 16384.
614
- * `video_accel3d` - Set to `true` to enable 3D acceleration. Defaults to
615
- `false`.
616
- * `sound_type` - [Set the virtual sound card](https://libvirt.org/formatdomain.html#elementsSound)
617
- Defaults to "ich6".
618
- * `machine_type` - Sets machine type. Equivalent to qemu `-machine`. Use
619
- `qemu-system-x86_64 -machine help` to get a list of supported machines.
620
- * `machine_arch` - Sets machine architecture. This helps Libvirt to determine
621
- the correct emulator type. Possible values depend on your version of QEMU.
622
- For possible values, see which emulator executable `qemu-system-*` your
623
- system provides. Common examples are `aarch64`, `alpha`, `arm`, `cris`,
624
- `i386`, `lm32`, `m68k`, `microblaze`, `microblazeel`, `mips`, `mips64`,
625
- `mips64el`, `mipsel`, `moxie`, `or32`, `ppc`, `ppc64`, `ppcemb`, `s390x`,
626
- `sh4`, `sh4eb`, `sparc`, `sparc64`, `tricore`, `unicore32`, `x86_64`,
627
- `xtensa`, `xtensaeb`.
628
- * `machine_virtual_size` - Sets the disk size in GB for the machine overriding
629
- the default specified in the box. Allows boxes to defined with a minimal size
630
- disk by default and to be grown to a larger size at creation time. Will
631
- ignore sizes smaller than the size specified by the box metadata. Note that
632
- currently there is no support for automatically resizing the filesystem to
633
- take advantage of the larger disk.
634
- * `emulator_path` - Explicitly select which device model emulator to use by
635
- providing the path, e.g. `/usr/bin/qemu-system-x86_64`. This is especially
636
- useful on systems that fail to select it automatically based on
637
- `machine_arch` which then results in a capability error.
638
- * `boot` - Change the boot order and enables the boot menu. Possible options
639
- are "hd", "network", "cdrom". Defaults to "hd" with boot menu disabled. When
640
- "network" is set without "hd", only all NICs will be tried; see below for
641
- more detail.
642
- * `nic_adapter_count` - Defaults to '8'. Only use case for increasing this
643
- count is for VMs that virtualize switches such as Cumulus Linux. Max value
644
- for Cumulus Linux VMs is 33.
645
- * `uuid` - Force a domain UUID. Defaults to autogenerated value by Libvirt if
646
- not set.
647
- * `suspend_mode` - What is done on vagrant suspend. Possible values: 'pause',
648
- 'managedsave'. Pause mode executes a la `virsh suspend`, which just pauses
649
- execution of a VM, not freeing resources. Managed save mode does a la `virsh
650
- managedsave` which frees resources suspending a domain.
651
- * `tpm_model` - The model of the TPM to which you wish to connect.
652
- * `tpm_type` - The type of TPM device to which you are connecting.
653
- * `tpm_path` - The path to the TPM device on the host system.
654
- * `tpm_version` - The TPM version to use.
655
- * `dtb` - The device tree blob file, mostly used for non-x86 platforms. In case
656
- the device tree isn't added in-line to the kernel, it can be manually
657
- specified here.
658
- * `autostart` - Automatically start the domain when the host boots. Defaults to
659
- 'false'.
660
- * `channel` - [Libvirt
661
- channels](https://libvirt.org/formatdomain.html#elementCharChannel).
662
- Configure a private communication channel between the host and guest, e.g.
663
- for use by the [QEMU guest
664
- agent](http://wiki.libvirt.org/page/Qemu_guest_agent) and the Spice/QXL
665
- graphics type.
666
- * `mgmt_attach` - Decide if VM has interface in mgmt network. If set to 'false'
667
- it is not possible to communicate with VM through `vagrant ssh` or run
668
- provisioning. Setting to 'false' is only possible when VM doesn't use box.
669
- Defaults set to 'true'.
670
- * `serial` - [libvirt serial devices](https://libvirt.org/formatdomain.html#elementsConsole).
671
- Configure a serial/console port to communicate with the guest. Can be used
672
- to log to file boot time messages sent to ttyS0 console by the guest.
673
-
674
- Specific domain settings can be set for each domain separately in multi-VM
675
- environment. Example below shows a part of Vagrantfile, where specific options
676
- are set for dbserver domain.
677
-
678
- ```ruby
679
- Vagrant.configure("2") do |config|
680
- config.vm.define :dbserver do |dbserver|
681
- dbserver.vm.box = "centos64"
682
- dbserver.vm.provider :libvirt do |domain|
683
- domain.memory = 2048
684
- domain.cpus = 2
685
- domain.nested = true
686
- domain.disk_driver :cache => 'none'
687
- end
688
- end
689
-
690
- # ...
691
- ```
692
-
693
- The following example shows part of a Vagrantfile that enables the VM to boot
694
- from a network interface first and a hard disk second. This could be used to
695
- run VMs that are meant to be a PXE booted machines. Be aware that if `hd` is
696
- not specified as a boot option, it will never be tried.
697
-
698
- ```ruby
699
- Vagrant.configure("2") do |config|
700
- config.vm.define :pxeclient do |pxeclient|
701
- pxeclient.vm.box = "centos64"
702
- pxeclient.vm.provider :libvirt do |domain|
703
- domain.boot 'network'
704
- domain.boot 'hd'
705
- end
706
- end
707
-
708
- # ...
709
- ```
710
-
711
- #### Reload behavior
712
-
713
- On `vagrant reload` the following domain specific attributes are updated in
714
- defined domain:
715
-
716
- * `disk_bus` - Is updated only on disks. It skips CDROMs
717
- * `nic_model_type` - Updated
718
- * `memory` - Updated
719
- * `cpus` - Updated
720
- * `nested` - Updated
721
- * `cpu_mode` - Updated. Pay attention that custom mode is not supported
722
- * `graphics_type` - Updated
723
- * `graphics_port` - Updated
724
- * `graphics_ip` - Updated
725
- * `graphics_passwd` - Updated
726
- * `graphics_autoport` - Updated
727
- * `keymap` - Updated
728
- * `video_type` - Updated
729
- * `video_vram` - Updated
730
- * `tpm_model` - Updated
731
- * `tpm_type` - Updated
732
- * `tpm_path` - Updated
733
- * `tpm_version` - Updated
734
-
735
- ## Networks
736
-
737
- Networking features in the form of `config.vm.network` support private networks
738
- concept. It supports both the virtual network switch routing types and the
739
- point to point Guest OS to Guest OS setting using UDP/Mcast/TCP tunnel
740
- interfaces.
741
-
742
- http://wiki.libvirt.org/page/VirtualNetworking
743
-
744
- https://libvirt.org/formatdomain.html#elementsNICSTCP
745
-
746
- http://libvirt.org/formatdomain.html#elementsNICSMulticast
747
-
748
- http://libvirt.org/formatdomain.html#elementsNICSUDP _(in Libvirt v1.2.20 and higher)_
749
-
750
- Public Network interfaces are currently implemented using the macvtap driver.
751
- The macvtap driver is only available with the Linux Kernel version >= 2.6.24.
752
- See the following Libvirt documentation for the details of the macvtap usage.
753
-
754
- http://www.libvirt.org/formatdomain.html#elementsNICSDirect
755
-
756
- An examples of network interface definitions:
757
-
758
- ```ruby
759
- # Private network using virtual network switching
760
- config.vm.define :test_vm1 do |test_vm1|
761
- test_vm1.vm.network :private_network, :ip => "10.20.30.40"
762
- end
763
-
764
- # Private network using DHCP and a custom network
765
- config.vm.define :test_vm1 do |test_vm1|
766
- test_vm1.vm.network :private_network,
767
- :type => "dhcp",
768
- :libvirt__network_address => '10.20.30.0'
769
- end
770
-
771
- # Private network (as above) using a domain name
772
- config.vm.define :test_vm1 do |test_vm1|
773
- test_vm1.vm.network :private_network,
774
- :ip => "10.20.30.40",
775
- :libvirt__domain_name => "test.local"
776
- end
777
-
778
- # Private network. Point to Point between 2 Guest OS using a TCP tunnel
779
- # Guest 1
780
- config.vm.define :test_vm1 do |test_vm1|
781
- test_vm1.vm.network :private_network,
782
- :libvirt__tunnel_type => 'server',
783
- # default is 127.0.0.1 if omitted
784
- # :libvirt__tunnel_ip => '127.0.0.1',
785
- :libvirt__tunnel_port => '11111'
786
- # network with ipv6 support
787
- test_vm1.vm.network :private_network,
788
- :ip => "10.20.5.42",
789
- :libvirt__guest_ipv6 => "yes",
790
- :libvirt__ipv6_address => "2001:db8:ca2:6::1",
791
- :libvirt__ipv6_prefix => "64"
792
-
793
- # Guest 2
794
- config.vm.define :test_vm2 do |test_vm2|
795
- test_vm2.vm.network :private_network,
796
- :libvirt__tunnel_type => 'client',
797
- # default is 127.0.0.1 if omitted
798
- # :libvirt__tunnel_ip => '127.0.0.1',
799
- :libvirt__tunnel_port => '11111'
800
- # network with ipv6 support
801
- test_vm2.vm.network :private_network,
802
- :ip => "10.20.5.45",
803
- :libvirt__guest_ipv6 => "yes",
804
- :libvirt__ipv6_address => "2001:db8:ca2:6::1",
805
- :libvirt__ipv6_prefix => "64"
806
-
807
-
808
- # Public Network
809
- config.vm.define :test_vm1 do |test_vm1|
810
- test_vm1.vm.network :public_network,
811
- :dev => "virbr0",
812
- :mode => "bridge",
813
- :type => "bridge"
814
- end
815
- ```
816
-
817
- In example below, one network interface is configured for VM `test_vm1`. After
818
- you run `vagrant up`, VM will be accessible on IP address `10.20.30.40`. So if
819
- you install a web server via provisioner, you will be able to access your
820
- testing server on `http://10.20.30.40` URL. But beware that this address is
821
- private to Libvirt host only. It's not visible outside of the hypervisor box.
822
-
823
- If network `10.20.30.0/24` doesn't exist, provider will create it. By default
824
- created networks are NATed to outside world, so your VM will be able to connect
825
- to the internet (if hypervisor can). And by default, DHCP is offering addresses
826
- on newly created networks.
827
-
828
- The second interface is created and bridged into the physical device `eth0`.
829
- This mechanism uses the macvtap Kernel driver and therefore does not require an
830
- existing bridge device. This configuration assumes that DHCP and DNS services
831
- are being provided by the public network. This public interface should be
832
- reachable by anyone with access to the public network.
833
-
834
- ### Private Network Options
835
-
836
- *Note: These options are not applicable to public network interfaces.*
837
-
838
- There is a way to pass specific options for Libvirt provider when using
839
- `config.vm.network` to configure new network interface. Each parameter name
840
- starts with `libvirt__` string. Here is a list of those options:
841
-
842
- * `:libvirt__network_name` - Name of Libvirt network to connect to. By default,
843
- network 'default' is used.
844
- * `:libvirt__netmask` - Used only together with `:ip` option. Default is
845
- '255.255.255.0'.
846
- * `:libvirt__network_address` - Used only when `:type` is set to `dhcp`. Only `/24` subnet is supported. Default is `172.28.128.0`.
847
- * `:libvirt__host_ip` - Address to use for the host (not guest). Default is
848
- first possible address (after network address).
849
- * `:libvirt__domain_name` - DNS domain of the DHCP server. Used only
850
- when creating new network.
851
- * `:libvirt__dhcp_enabled` - If DHCP will offer addresses, or not. Used only
852
- when creating new network. Default is true.
853
- * `:libvirt__dhcp_start` - First address given out via DHCP. Default is third
854
- address in range (after network name and gateway).
855
- * `:libvirt__dhcp_stop` - Last address given out via DHCP. Default is last
856
- possible address in range (before broadcast address).
857
- * `:libvirt__dhcp_bootp_file` - The file to be used for the boot image. Used
858
- only when dhcp is enabled.
859
- * `:libvirt__dhcp_bootp_server` - The server that runs the DHCP server. Used
860
- only when dhcp is enabled.By default is the same host that runs the DHCP
861
- server.
862
- * `:libvirt__tftp_root` - Path to the root directory served via TFTP.
863
- * `:libvirt__adapter` - Number specifiyng sequence number of interface.
864
- * `:libvirt__forward_mode` - Specify one of `veryisolated`, `none`, `open`, `nat`
865
- or `route` options. This option is used only when creating new network. Mode
866
- `none` will create isolated network without NATing or routing outside. You
867
- will want to use NATed forwarding typically to reach networks outside of
868
- hypervisor. Routed forwarding is typically useful to reach other networks
869
- within hypervisor. `veryisolated` described
870
- [here](https://libvirt.org/formatnetwork.html#examplesNoGateway). By
871
- default, option `nat` is used.
872
- * `:libvirt__forward_device` - Name of interface/device, where network should
873
- be forwarded (NATed or routed). Used only when creating new network. By
874
- default, all physical interfaces are used.
875
- * `:libvirt__tunnel_type` - Set to 'udp' if using UDP unicast tunnel mode
876
- (libvirt v1.2.20 or higher). Set this to either "server" or "client" for tcp
877
- tunneling. Set this to 'mcast' if using multicast tunneling. This
878
- configuration type uses tunnels to generate point to point connections
879
- between Guests. Useful for Switch VMs like Cumulus Linux. No virtual switch
880
- setting like `libvirt__network_name` applies with tunnel interfaces and will
881
- be ignored if configured.
882
- * `:libvirt__tunnel_ip` - Sets the source IP of the Libvirt tunnel interface.
883
- By default this is `127.0.0.1` for TCP and UDP tunnels and `239.255.1.1` for
884
- Multicast tunnels. It populates the address field in the `<source
885
- address="XXX">` of the interface xml configuration.
886
- * `:libvirt__tunnel_port` - Sets the source port the tcp/udp/mcast tunnel with
887
- use. This port information is placed in the `<source port=XXX/>` section of
888
- interface xml configuration.
889
- * `:libvirt__tunnel_local_port` - Sets the local port used by the udp tunnel
890
- interface type. It populates the port field in the `<local port=XXX">`
891
- section of the interface xml configuration. _(This feature only works in
892
- Libvirt 1.2.20 and higher)_
893
- * `:libvirt__tunnel_local_ip` - Sets the local IP used by the udp tunnel
894
- interface type. It populates the ip entry of the `<local address=XXX">`
895
- section of the interface xml configuration. _(This feature only works in
896
- Libvirt 1.2.20 and higher)_
897
- * `:libvirt__guest_ipv6` - Enable or disable guest-to-guest IPv6 communication.
898
- See [here](https://libvirt.org/formatnetwork.html#examplesPrivate6), and
899
- [here](http://libvirt.org/git/?p=libvirt.git;a=commitdiff;h=705e67d40b09a905cd6a4b8b418d5cb94eaa95a8)
900
- for for more information. *Note: takes either 'yes' or 'no' for value*
901
- * `:libvirt__ipv6_address` - Define ipv6 address, require also prefix.
902
- * `:libvirt__ipv6_prefix` - Define ipv6 prefix. generate string `<ip family="ipv6" address="address" prefix="prefix" >`
903
- * `:libvirt__iface_name` - Define a name for the private network interface.
904
- With this feature one can [simulate physical link
905
- failures](https://github.com/vagrant-libvirt/vagrant-libvirt/pull/498)
906
- * `:mac` - MAC address for the interface. *Note: specify this in lowercase
907
- since Vagrant network scripts assume it will be!*
908
- * `:libvirt__mtu` - MTU size for the Libvirt network, if not defined, the
909
- created network will use the Libvirt default (1500). VMs still need to set the
910
- MTU accordingly.
911
- * `:model_type` - parameter specifies the model of the network adapter when you
912
- create a domain value by default virtio KVM believe possible values, see the
913
- documentation for Libvirt
914
- * `:libvirt__driver_name` - Define which network driver to use. [More
915
- info](https://libvirt.org/formatdomain.html#elementsDriverBackendOptions)
916
- * `:libvirt__driver_queues` - Define a number of queues to be used for network
917
- interface. Set equal to numer of vCPUs for best performance. [More
918
- info](http://www.linux-kvm.org/page/Multiqueue)
919
- * `:autostart` - Automatic startup of network by the Libvirt daemon.
920
- If not specified the default is 'false'.
921
- * `:bus` - The bus of the PCI device. Both :bus and :slot have to be defined.
922
- * `:slot` - The slot of the PCI device. Both :bus and :slot have to be defined.
923
- * `:libvirt__always_destroy` - Allow domains that use but did not create a
924
- network to destroy it when the domain is destroyed (default: `true`). Set to
925
- `false` to only allow the domain that created the network to destroy it.
926
-
927
- When the option `:libvirt__dhcp_enabled` is to to 'false' it shouldn't matter
928
- whether the virtual network contains a DHCP server or not and vagrant-libvirt
929
- should not fail on it. The only situation where vagrant-libvirt should fail is
930
- when DHCP is requested but isn't configured on a matching already existing
931
- virtual network.
932
-
933
- ### Public Network Options
934
-
935
- * `:dev` - Physical device that the public interface should use. Default is
936
- 'eth0'.
937
- * `:mode` - The mode in which the public interface should operate in. Supported
938
- modes are available from the [libvirt
939
- documentation](http://www.libvirt.org/formatdomain.html#elementsNICSDirect).
940
- Default mode is 'bridge'.
941
- * `:type` - is type of interface.(`<interface type="#{@type}">`)
942
- * `:mac` - MAC address for the interface.
943
- * `:network_name` - Name of Libvirt network to connect to.
944
- * `:portgroup` - Name of Libvirt portgroup to connect to.
945
- * `:ovs` - Support to connect to an Open vSwitch bridge device. Default is
946
- 'false'.
947
- * :ovs_interfaceid - Add Open vSwitch 'interfaceid' parameter.
948
- * `:trust_guest_rx_filters` - Support trustGuestRxFilters attribute. Details
949
- are listed [here](http://www.libvirt.org/formatdomain.html#elementsNICSDirect).
950
- Default is 'false'.
951
-
952
- ### Management Network
953
-
954
- vagrant-libvirt uses a private network to perform some management operations on
955
- VMs. All VMs will have an interface connected to this network and an IP address
956
- dynamically assigned by Libvirt unless you set `:mgmt_attach` to 'false'.
957
- This is in addition to any networks you configure. The name and address
958
- used by this network are configurable at the provider level.
959
-
960
- * `management_network_name` - Name of Libvirt network to which all VMs will be
961
- connected. If not specified the default is 'vagrant-libvirt'.
962
- * `management_network_address` - Address of network to which all VMs will be
963
- connected. Must include the address and subnet mask. If not specified the
964
- default is '192.168.121.0/24'.
965
- * `management_network_mode` - Network mode for the Libvirt management network.
966
- Specify one of veryisolated, none, open, nat or route options. Further
967
- documented under [Private Networks](#private-network-options)
968
- * `management_network_guest_ipv6` - Enable or disable guest-to-guest IPv6
969
- communication. See
970
- [here](https://libvirt.org/formatnetwork.html#examplesPrivate6), and
971
- [here](http://libvirt.org/git/?p=libvirt.git;a=commitdiff;h=705e67d40b09a905cd6a4b8b418d5cb94eaa95a8)
972
- for for more information.
973
- * `management_network_autostart` - Automatic startup of mgmt network, if not
974
- specified the default is 'false'.
975
- * `management_network_pci_bus` - The bus of the PCI device.
976
- * `management_network_pci_slot` - The slot of the PCI device.
977
- * `management_network_mac` - MAC address of management network interface.
978
- * `management_network_domain` - Domain name assigned to the management network.
979
- * `management_network_mtu` - MTU size of management network. If not specified,
980
- the Libvirt default (1500) will be used.
981
- * `management_network_keep` - Starting from version *0.7.0*, *always_destroy* is set to *true* by default for any network.
982
- This option allows to change this behaviour for the management network.
983
-
984
- You may wonder how vagrant-libvirt knows the IP address a VM received. Libvirt
985
- doesn't provide a standard way to find out the IP address of a running domain.
986
- But we do know the MAC address of the virtual machine's interface on the
987
- management network. Libvirt is closely connected with dnsmasq, which acts as a
988
- DHCP server. dnsmasq writes lease information in the `/var/lib/libvirt/dnsmasq`
989
- directory. Vagrant-libvirt looks for the MAC address in this file and extracts
990
- the corresponding IP address.
991
-
992
- It is also possible to use the Qemu Agent to extract the management interface
993
- configuration from the booted virtual machine. This is helpful in libvirt
994
- environments where no local dnsmasq is used for automatic address assigment,
995
- but external dhcp services via bridged libvirt networks.
996
-
997
- Prerequisite is to enable the qemu agent channel via ([Libvirt communication
998
- channels](#libvirt-communication-channels)) and the virtual machine image must
999
- have the agent pre-installed before deploy. The agent will start automatically
1000
- if it detects an attached channel during boot.
1001
-
1002
- * `qemu_use_agent` - false by default, if set to true, attempt to extract configured
1003
- ip address via qemu agent.
1004
-
1005
- By default if `qemu_use_agent` is set to `true` the code will automatically
1006
- inject a suitable channel unless there already exists an entry with a
1007
- `:target_name` matching `'org.qemu.guest_agent.'`.
1008
- Alternatively if setting `qemu_use_agent` but, needing to disable the addition
1009
- of the channel, simply use a disabled flag as follows:
1010
- ```ruby
1011
- Vagrant.configure(2) do |config|
1012
- config.vm.provider :libvirt do |libvirt|
1013
- libvirt.channel :type => 'unix', :target_name => 'org.qemu.guest_agent.0', :disabled => true
1014
- end
1015
- end
1016
- ```
1017
-
1018
- To use the management network interface with an external dhcp service you need
1019
- to setup a bridged host network manually and define it via
1020
- `management_network_name` in your Vagrantfile.
1021
-
1022
- ## Additional Disks
1023
-
1024
- You can create and attach additional disks to a VM via `libvirt.storage :file`.
1025
- It has a number of options:
1026
-
1027
- * `path` - Location of the disk image. If unspecified, a path is automtically
1028
- chosen in the same storage pool as the VMs primary disk.
1029
- * `device` - Name of the device node the disk image will have in the VM, e.g.
1030
- *vdb*. If unspecified, the next available device is chosen.
1031
- * `size` - Size of the disk image. If unspecified, defaults to 10G.
1032
- * `type` - Type of disk image to create. Defaults to *qcow2*.
1033
- * `bus` - Type of bus to connect device to. Defaults to *virtio*.
1034
- * `allow_existing` - Set to true if you want to allow the VM to use a
1035
- pre-existing disk. If the disk doesn't exist it will be created.
1036
- Disks with this option set to true need to be removed manually.
1037
- * `shareable` - Set to true if you want to simulate shared SAN storage.
1038
- * `serial` - Serial number of the disk device.
1039
- * `wwn` - WWN number of the disk device.
1040
-
1041
- The following disk performance options can also be configured
1042
- (see the [libvirt documentation for possible values](http://libvirt.org/formatdomain.html#elementsDisks)
1043
- or [here](https://www.suse.com/documentation/sles11/book_kvm/data/sect1_chapter_book_kvm.html) for a fuller explanation).
1044
- In all cases, the options use the hypervisor default if not specified, or if set to `nil`.
1045
-
1046
- * `cache` - Cache mode to use. Value may be `default`, `none`, `writeback`, `writethrough`, `directsync` or `unsafe`.
1047
- * `io` - Controls specific policies on I/O. Value may be `threads` or `native`.
1048
- * `copy_on_read` - Controls whether to copy read backing file into the image file. Value may be `on` or `off`.
1049
- * `discard` - Controls whether discard requests (also known as "trim" or "unmap") are ignored or passed to the filesystem. Value may be `unmap` or `ignore`.
1050
- Note: for discard to work, you will likely also need to set `:bus => 'scsi'`
1051
- * `detect_zeroes` - Controls whether to detect zero write requests. Value may be `off`, `on` or `unmap`.
1052
-
1053
- The following example creates two additional disks.
1054
-
1055
- ```ruby
1056
- Vagrant.configure("2") do |config|
1057
- config.vm.provider :libvirt do |libvirt|
1058
- libvirt.storage :file, :size => '20G'
1059
- libvirt.storage :file, :size => '40G', :bus => 'scsi', :type => 'raw', :discard => 'unmap', :detect_zeroes => 'on'
1060
- end
1061
- end
1062
- ```
1063
-
1064
- For shared SAN storage to work the following example can be used:
1065
- ```ruby
1066
- Vagrant.configure("2") do |config|
1067
- config.vm.provider :libvirt do |libvirt|
1068
- libvirt.storage :file, :size => '20G', :path => 'my_shared_disk.img', :allow_existing => true, :shareable => true, :type => 'raw'
1069
- end
1070
- end
1071
- ```
1072
-
1073
- ### Reload behavior
1074
-
1075
- On `vagrant reload` the following additional disk attributes are updated in
1076
- defined domain:
1077
-
1078
- * `bus` - Updated. Uses `device` as a search marker. It is not required to
1079
- define `device`, but it's recommended. If `device` is defined then the order
1080
- of addtitional disk definition becomes irrelevant.
1081
-
1082
- ## CDROMs
1083
-
1084
- You can attach up to four CDROMs to a VM via `libvirt.storage :file,
1085
- :device => :cdrom`. Available options are:
1086
-
1087
- * `path` - The path to the iso to be used for the CDROM drive.
1088
- * `dev` - The device to use (`hda`, `hdb`, `hdc`, or `hdd`). This will be
1089
- automatically determined if unspecified.
1090
- * `bus` - The bus to use for the CDROM drive. Defaults to `ide`
1091
-
1092
- The following example creates three CDROM drives in the VM:
1093
-
1094
- ```ruby
1095
- Vagrant.configure("2") do |config|
1096
- config.vm.provider :libvirt do |libvirt|
1097
- libvirt.storage :file, :device => :cdrom, :path => '/path/to/iso1.iso'
1098
- libvirt.storage :file, :device => :cdrom, :path => '/path/to/iso2.iso'
1099
- libvirt.storage :file, :device => :cdrom, :path => '/path/to/iso3.iso'
1100
- end
1101
- end
1102
- ```
1103
-
1104
- ## Input
1105
-
1106
- You can specify multiple inputs to the VM via `libvirt.input`. Available
1107
- options are listed below. Note that both options are required:
1108
-
1109
- * `type` - The type of the input
1110
- * `bus` - The bus of the input
1111
-
1112
- ```ruby
1113
- Vagrant.configure("2") do |config|
1114
- config.vm.provider :libvirt do |libvirt|
1115
- # this is the default
1116
- # libvirt.input :type => "mouse", :bus => "ps2"
1117
-
1118
- # very useful when having mouse issues when viewing VM via VNC
1119
- libvirt.input :type => "tablet", :bus => "usb"
1120
- end
1121
- end
1122
- ```
1123
-
1124
- ## PCI device passthrough
1125
-
1126
- You can specify multiple PCI devices to passthrough to the VM via
1127
- `libvirt.pci`. Available options are listed below. Note that all options are
1128
- required, except domain, which defaults to `0x0000`:
1129
-
1130
- * `domain` - The domain of the PCI device
1131
- * `bus` - The bus of the PCI device
1132
- * `slot` - The slot of the PCI device
1133
- * `function` - The function of the PCI device
1134
-
1135
- You can extract that information from output of `lspci` command. First
1136
- characters of each line are in format `[<domain>]:[<bus>]:[<slot>].[<func>]`. For example:
1137
-
1138
- ```shell
1139
- $ lspci| grep NVIDIA
1140
- 0000:03:00.0 VGA compatible controller: NVIDIA Corporation GK110B [GeForce GTX TITAN Black] (rev a1)
1141
- ```
1142
-
1143
- In that case `domain` is `0x0000`, `bus` is `0x03`, `slot` is `0x00` and `function` is `0x0`.
1144
-
1145
- ```ruby
1146
- Vagrant.configure("2") do |config|
1147
- config.vm.provider :libvirt do |libvirt|
1148
- libvirt.pci :domain => '0x0000', :bus => '0x06', :slot => '0x12', :function => '0x5'
1149
-
1150
- # Add another one if it is neccessary
1151
- libvirt.pci :domain => '0x0000', :bus => '0x03', :slot => '0x00', :function => '0x0'
1152
- end
1153
- end
1154
- ```
1155
-
1156
- Note! Above options affect configuration only at domain creation. It won't change VM behaviour on `vagrant reload` after domain was created.
1157
-
1158
- Don't forget to [set](#domain-specific-options) `kvm_hidden` option to `true` especially if you are passthroughing NVIDIA GPUs. Otherwise GPU is visible from VM but cannot be operated.
1159
-
1160
-
1161
- ## Using USB Devices
1162
-
1163
- There are several ways to pass a USB device through to a running instance:
1164
- * Use `libvirt.usb` to [attach a USB device at boot](#usb-device-passthrough), with the device ID specified in the Vagrantfile
1165
- * Use a client (such as `virt-viewer` or `virt-manager`) to attach the device at runtime [via USB redirectors](#usb-redirector-devices)
1166
- * Use `virsh attach-device` once the VM is running (however, this is outside the scope of this readme)
1167
-
1168
- In all cases, if you wish to use a high-speed USB device,
1169
- you will need to use `libvirt.usb_controller` to specify a USB2 or USB3 controller,
1170
- as the default configuration only exposes a USB1.1 controller.
1171
-
1172
- ### USB Controller Configuration
1173
-
1174
- The USB controller can be configured using `libvirt.usb_controller`, with the following options:
1175
-
1176
- * `model` - The USB controller device model to emulate. (mandatory)
1177
- * `ports` - The number of devices that can be connected to the controller.
1178
-
1179
- ```ruby
1180
- Vagrant.configure("2") do |config|
1181
- config.vm.provider :libvirt do |libvirt|
1182
- # Set up a USB3 controller
1183
- libvirt.usb_controller :model => "qemu-xhci"
1184
- end
1185
- end
1186
- ```
1187
-
1188
- See the [libvirt documentation](https://libvirt.org/formatdomain.html#elementsControllers) for a list of valid models.
1189
-
1190
- If any USB devices are passed through by setting `libvirt.usb` or `libvirt.redirdev`, a default controller will be added using the model `qemu-xhci` in the absence of a user specified one. This should help ensure more devices work out of the box as the default configured by libvirt is pii3-uhci, which appears to only work for USB 1 devices and does not work as expected when connected via a USB 2 controller, while the xhci stack should work for all versions of USB.
1191
-
1192
- ### USB Device Passthrough
1193
-
1194
- You can specify multiple USB devices to passthrough to the VM via
1195
- `libvirt.usb`. The device can be specified by the following options:
1196
-
1197
- * `bus` - The USB bus ID, e.g. "1"
1198
- * `device` - The USB device ID, e.g. "2"
1199
- * `vendor` - The USB devices vendor ID (VID), e.g. "0x1234"
1200
- * `product` - The USB devices product ID (PID), e.g. "0xabcd"
1201
-
1202
- At least one of these has to be specified, and `bus` and `device` may only be
1203
- used together.
1204
-
1205
- The example values above match the device from the following output of `lsusb`:
1206
-
1207
- ```
1208
- Bus 001 Device 002: ID 1234:abcd Example device
1209
- ```
1210
-
1211
- ```ruby
1212
- Vagrant.configure("2") do |config|
1213
- config.vm.provider :libvirt do |libvirt|
1214
- # pass through specific device based on identifying it
1215
- libvirt.usb :vendor => '0x1234', :product => '0xabcd'
1216
- # pass through a host device where multiple of the same vendor/product exist
1217
- libvirt.usb :bus => '1', :device => '1'
1218
- end
1219
- end
1220
- ```
1221
-
1222
- Additionally, the following options can be used:
1223
-
1224
- * `startupPolicy` - Is passed through to Libvirt and controls if the device has
1225
- to exist. Libvirt currently allows the following values: "mandatory",
1226
- "requisite", "optional".
1227
-
1228
-
1229
- ### USB Redirector Devices
1230
- You can specify multiple redirect devices via `libvirt.redirdev`. There are two types, `tcp` and `spicevmc` supported, for forwarding USB-devices to the guest. Available options are listed below.
1231
-
1232
- * `type` - The type of the USB redirector device. (`tcp` or `spicevmc`)
1233
- * `host` - The host where the device is attached to. (mandatory for type `tcp`)
1234
- * `port` - The port where the device is listening. (mandatory for type `tcp`)
1235
-
1236
- ```ruby
1237
- Vagrant.configure("2") do |config|
1238
- config.vm.provider :libvirt do |libvirt|
1239
- # add two devices using spicevmc channel
1240
- (1..2).each do
1241
- libvirt.redirdev :type => "spicevmc"
1242
- end
1243
- # add device, provided by localhost:4000
1244
- libvirt.redirdev :type => "tcp", :host => "localhost", :port => "4000"
1245
- end
1246
- end
1247
- ```
1248
-
1249
- Note that in order to enable USB redirection with Spice clients,
1250
- you may need to also set `libvirt.graphics_type = "spice"`
1251
-
1252
- #### Filter for USB Redirector Devices
1253
- You can define filter for redirected devices. These filters can be positiv or negative, by setting the mandatory option `allow=yes` or `allow=no`. All available options are listed below. Note the option `allow` is mandatory.
1254
-
1255
- * `class` - The device class of the USB device. A list of device classes is available on [Wikipedia](https://en.wikipedia.org/wiki/USB#Device_classes).
1256
- * `vendor` - The vendor of the USB device.
1257
- * `product` - The product id of the USB device.
1258
- * `version` - The version of the USB device. Note that this is the version of `bcdDevice`
1259
- * `allow` - allow or disallow redirecting this device. (mandatory)
1260
-
1261
- You can extract that information from output of `lsusb` command. Every line contains the information in format `Bus [<bus>] Device [<device>]: ID [<vendor>:[<product>]`. The `version` can be extracted from the detailed output of the device using `lsusb -D /dev/usb/[<bus>]/[<device>]`. For example:
1262
-
1263
- ```shell
1264
- # get bcdDevice from
1265
- $: lsusb
1266
- Bus 001 Device 009: ID 08e6:3437 Gemalto (was Gemplus) GemPC Twin SmartCard Reader
1267
-
1268
- $: lsusb -D /dev/bus/usb/001/009 | grep bcdDevice
1269
- bcdDevice 2.00
1270
- ```
1271
-
1272
- In this case, the USB device with `class 0x0b`, `vendor 0x08e6`, `product 0x3437` and `bcdDevice version 2.00` is allowed to be redirected to the guest. All other devices will be refused.
1273
-
1274
- ```ruby
1275
- Vagrant.configure("2") do |config|
1276
- config.vm.provider :libvirt do |libvirt|
1277
- libvirt.redirdev :type => "spicevmc"
1278
- libvirt.redirfilter :class => "0x0b", :vendor => "0x08e6", :product => "0x3437", :version => "2.00", :allow => "yes"
1279
- libvirt.redirfilter :allow => "no"
1280
- end
1281
- end
1282
- ```
1283
-
1284
- ## Serial Console Devices
1285
- You can define settings to redirect output from the serial console of any VM brought up with libvirt to a file or other devices that are listening. [See libvirt documentation](https://libvirt.org/formatdomain.html#elementCharSerial).
1286
-
1287
- Currently only redirecting to a file is supported.
1288
-
1289
- * `type` - only value that has an effect is file, in the future support may be added for virtual console, pty, dev, pipe, tcp, udp, unix socket, spiceport & nmdm.
1290
- * `source` - options pertaining to how the connection attaches to the host, contains sub-settings dependent on `type`.
1291
- `source` options for type `file`
1292
- * `path` - file on host to connect to the serial port to record all output. May be created by qemu system user causing some permissions issues.
1293
-
1294
- ```ruby
1295
- Vagrant.configure("2") do |config|
1296
- config.vm.define :test do |test|
1297
- test.vm.provider :libvirt do |domain|
1298
- domain.serial :type => "file", :source => {:path => "/var/log/vm_consoles/test.log"}
1299
- end
1300
- end
1301
- end
1302
- ```
1303
-
1304
- ## Random number generator passthrough
1305
-
1306
- You can pass through `/dev/random` to your VM by configuring the domain like this:
1307
-
1308
- ```ruby
1309
- Vagrant.configure("2") do |config|
1310
- config.vm.provider :libvirt do |libvirt|
1311
- # Pass through /dev/random from the host to the VM
1312
- libvirt.random :model => 'random'
1313
- end
1314
- end
1315
- ```
1316
-
1317
- At the moment only the `random` backend is supported.
1318
-
1319
- ## Watchdog device
1320
- A virtual hardware watchdog device can be added to the guest via the `libvirt.watchdog` element. The option `model` is mandatory and could have on of the following values.
1321
-
1322
- * `i6300esb` - the recommended device, emulating a PCI Intel 6300ESB
1323
- * 'ib700` - emulating an ISA iBase IB700
1324
- * `diag288` - emulating an S390 DIAG288 device
1325
-
1326
- The optional action attribute describes what `action` to take when the watchdog expires. Valid values are specific to the underlying hypervisor. The default behavior is `reset`.
1327
-
1328
- * `reset` - default, forcefully reset the guest
1329
- * `shutdown` - gracefully shutdown the guest (not recommended)
1330
- * `poweroff` - forcefully power off the guest
1331
- * `pause` - pause the guest
1332
- * `none` - do nothing
1333
- * `dump` - automatically dump the guest
1334
- * `inject-nmi` - inject a non-maskable interrupt into the guest
1335
-
1336
- ```ruby
1337
- Vagrant.configure("2") do |config|
1338
- config.vm.provider :libvirt do |libvirt|
1339
- # Add Libvirt watchdog device model i6300esb
1340
- libvirt.watchdog :model => 'i6300esb', :action => 'reset'
1341
- end
1342
- end
1343
- ```
1344
-
1345
- ## Smartcard device
1346
- A virtual smartcard device can be supplied to the guest via the `libvirt.smartcard` element. The option `mode` is mandatory and currently only value `passthrough` is supported. The value `spicevmc` for option `type` is default value and can be supressed. On using `type = tcp`, the options `source_mode`, `source_host` and `source_service` are mandatory.
1347
-
1348
- ```ruby
1349
- Vagrant.configure("2") do |config|
1350
- config.vm.provider :libvirt do |libvirt|
1351
- # Add smartcard device with type 'spicevmc'
1352
- libvirt.smartcard :mode => 'passthrough', :type => 'spicevmc'
1353
- end
1354
- end
1355
- ```
1356
-
1357
- ```ruby
1358
- Vagrant.configure("2") do |config|
1359
- config.vm.provider :libvirt do |libvirt|
1360
- # Add smartcard device with type 'tcp'
1361
- domain.smartcard :mode => 'passthrough', :type => 'tcp', :source_mode => 'bind', :source_host => '127.0.0.1', :source_service => '2001'
1362
- end
1363
- end
1364
- ```
1365
- ## Hypervisor Features
1366
-
1367
- Hypervisor features can be specified via `libvirt.features` as a list. The default
1368
- options that are enabled are `acpi`, `apic` and `pae`. If you define `libvirt.features`
1369
- you overwrite the defaults, so keep that in mind.
1370
-
1371
- An example:
1372
-
1373
- ```ruby
1374
- Vagrant.configure("2") do |config|
1375
- config.vm.provider :libvirt do |libvirt|
1376
- # Specify the default hypervisor features
1377
- libvirt.features = ['acpi', 'apic', 'pae' ]
1378
- end
1379
- end
1380
- ```
1381
-
1382
- A different example for ARM boards:
1383
-
1384
- ```ruby
1385
- Vagrant.configure("2") do |config|
1386
- config.vm.provider :libvirt do |libvirt|
1387
- # Specify the default hypervisor features
1388
- libvirt.features = ["apic", "gic version='2'" ]
1389
- end
1390
- end
1391
- ```
1392
-
1393
- You can also specify a special set of features that help improve the behavior of guests
1394
- running Microsoft Windows.
1395
-
1396
- You can specify HyperV features via `libvirt.hyperv_feature`. Available
1397
- options are listed below. Note that both options are required:
1398
-
1399
- * `name` - The name of the feature Hypervisor feature (see Libvirt doc)
1400
- * `state` - The state for this feature which can be either `on` or `off`.
1401
-
1402
- ```ruby
1403
- Vagrant.configure("2") do |config|
1404
- config.vm.provider :libvirt do |libvirt|
1405
- # Relax constraints on timers
1406
- libvirt.hyperv_feature :name => 'relaxed', :state => 'on'
1407
- # Enable virtual APIC
1408
- libvirt.hyperv_feature :name => 'vapic', :state => 'on'
1409
- # Enable spinlocks (requires retries to be specified)
1410
- libvirt.hyperv_feature :name => 'spinlocks', :state => 'on', :retries => '8191'
1411
- end
1412
- end
1413
- ```
1414
-
1415
- ## Clock
1416
-
1417
- Clock offset can be specified via `libvirt.clock_offset`. (Default is utc)
1418
-
1419
- Additionally timers can be specified via `libvirt.clock_timer`.
1420
- Available options for timers are: name, track, tickpolicy, frequency, mode, present
1421
-
1422
- ```ruby
1423
- Vagrant.configure("2") do |config|
1424
- config.vm.provider :libvirt do |libvirt|
1425
- # Set clock offset to localtime
1426
- libvirt.clock_offset = 'localtime'
1427
- # Timers ...
1428
- libvirt.clock_timer :name => 'rtc', :tickpolicy => 'catchup'
1429
- libvirt.clock_timer :name => 'pit', :tickpolicy => 'delay'
1430
- libvirt.clock_timer :name => 'hpet', :present => 'no'
1431
- libvirt.clock_timer :name => 'hypervclock', :present => 'yes'
1432
- end
1433
- end
1434
- ```
1435
-
1436
- ## CPU features
1437
-
1438
- You can specify CPU feature policies via `libvirt.cpu_feature`. Available
1439
- options are listed below. Note that both options are required:
1440
-
1441
- * `name` - The name of the feature for the chosen CPU (see Libvirt's
1442
- `cpu_map.xml`)
1443
- * `policy` - The policy for this feature (one of `force`, `require`,
1444
- `optional`, `disable` and `forbid` - see Libvirt documentation)
1445
-
1446
- ```ruby
1447
- Vagrant.configure("2") do |config|
1448
- config.vm.provider :libvirt do |libvirt|
1449
- # The feature will not be supported by virtual CPU.
1450
- libvirt.cpu_feature :name => 'hypervisor', :policy => 'disable'
1451
- # Guest creation will fail unless the feature is supported by host CPU.
1452
- libvirt.cpu_feature :name => 'vmx', :policy => 'require'
1453
- # The virtual CPU will claim the feature is supported regardless of it being supported by host CPU.
1454
- libvirt.cpu_feature :name => 'pdpe1gb', :policy => 'force'
1455
- end
1456
- end
1457
- ```
1458
-
1459
- ## Memory Backing
1460
-
1461
- You can specify memoryBacking options via `libvirt.memorybacking`. Available options are shown below. Full documentation is available at the [libvirt _memoryBacking_ section](https://libvirt.org/formatdomain.html#elementsMemoryBacking).
1462
-
1463
- NOTE: The hugepages `<page>` element is not yet supported
1464
-
1465
- ```ruby
1466
- Vagrant.configure("2") do |config|
1467
- config.vm.provider :libvirt do |libvirt|
1468
- libvirt.memorybacking :hugepages
1469
- libvirt.memorybacking :nosharepages
1470
- libvirt.memorybacking :locked
1471
- libvirt.memorybacking :source, :type => 'file'
1472
- libvirt.memorybacking :access, :mode => 'shared'
1473
- libvirt.memorybacking :allocation, :mode => 'immediate'
1474
- end
1475
- end
1476
- ```
1477
-
1478
- ## No box and PXE boot
1479
-
1480
- There is support for PXE booting VMs with no disks as well as PXE booting VMs
1481
- with blank disks. There are some limitations:
1482
-
1483
- * Requires Vagrant 1.6.0 or newer
1484
- * No provisioning scripts are ran
1485
- * No network configuration is being applied to the VM
1486
- * No SSH connection can be made
1487
- * `vagrant halt` will only work cleanly if the VM handles ACPI shutdown signals
1488
-
1489
- In short, VMs without a box can be created, halted and destroyed but all other
1490
- functionality cannot be used.
1491
-
1492
- An example for a PXE booted VM with no disks whatsoever:
1493
-
1494
- ```ruby
1495
- Vagrant.configure("2") do |config|
1496
- config.vm.define :pxeclient do |pxeclient|
1497
- pxeclient.vm.provider :libvirt do |domain|
1498
- domain.boot 'network'
1499
- end
1500
- end
1501
- end
1502
- ```
1503
-
1504
- And an example for a PXE booted VM with no box but a blank disk which will boot from this HD if the NICs fail to PXE boot:
1505
-
1506
- ```ruby
1507
- Vagrant.configure("2") do |config|
1508
- config.vm.define :pxeclient do |pxeclient|
1509
- pxeclient.vm.provider :libvirt do |domain|
1510
- domain.storage :file, :size => '100G', :type => 'qcow2'
1511
- domain.boot 'network'
1512
- domain.boot 'hd'
1513
- end
1514
- end
1515
- end
1516
- ```
1517
-
1518
- Example for vm with 2 networks and only 1 is bootable and has dhcp server in this subnet, for example foreman with dhcp server
1519
- Name of network "foreman_managed" is key for define boot order
1520
- ```ruby
1521
- config.vm.define :pxeclient do |pxeclient|
1522
- pxeclient.vm.network :private_network,ip: '10.0.0.5',
1523
- libvirt__network_name: "foreman_managed",
1524
- libvirt__dhcp_enabled: false,
1525
- libvirt__host_ip: '10.0.0.1'
1526
-
1527
- pxeclient.vm.provider :libvirt do |domain|
1528
- domain.memory = 1000
1529
- boot_network = {'network' => 'foreman_managed'}
1530
- domain.storage :file, :size => '100G', :type => 'qcow2'
1531
- domain.boot boot_network
1532
- domain.boot 'hd'
1533
- end
1534
- end
1535
- ```
1536
-
1537
- An example VM that is PXE booted from the `br1` device (which must already be configured in the host machine), and if that fails, is booted from the disk:
1538
-
1539
- ```ruby
1540
- Vagrant.configure("2") do |config|
1541
- config.vm.define :pxeclient do |pxeclient|
1542
- pxeclient.vm.network :public_network,
1543
- dev: 'br1',
1544
- auto_config: false
1545
- pxeclient.vm.provider :libvirt do |domain|
1546
- boot_network = {'dev' => 'br1'}
1547
- domain.storage :file, :size => '100G'
1548
- domain.boot boot_network
1549
- domain.boot 'hd'
1550
- end
1551
- end
1552
- end
1553
- ```
1554
-
1555
- ## SSH Access To VM
1556
-
1557
- vagrant-libvirt supports vagrant's [standard ssh
1558
- settings](https://docs.vagrantup.com/v2/vagrantfile/ssh_settings.html).
1559
-
1560
- ## Forwarded Ports
1561
-
1562
- vagrant-libvirt supports Forwarded Ports via ssh port forwarding. Please note
1563
- that due to a well known limitation only the TCP protocol is supported. For
1564
- each `forwarded_port` directive you specify in your Vagrantfile,
1565
- vagrant-libvirt will maintain an active ssh process for the lifetime of the VM.
1566
- If your VM should happen to be rebooted, the SSH session will need to be
1567
- restablished by halting the VM and bringing it back up.
1568
-
1569
- vagrant-libvirt supports an additional `forwarded_port` option `gateway_ports`
1570
- which defaults to `false`, but can be set to `true` if you want the forwarded
1571
- port to be accessible from outside the Vagrant host. In this case you should
1572
- also set the `host_ip` option to `'*'` since it defaults to `'localhost'`.
1573
-
1574
- You can also provide a custom adapter to forward from by 'adapter' option.
1575
- Default is `eth0`.
1576
-
1577
- **Internally Accessible Port Forward**
1578
-
1579
- `config.vm.network :forwarded_port, guest: 80, host: 2000`
1580
-
1581
- **Externally Accessible Port Forward**
1582
-
1583
- `config.vm.network :forwarded_port, guest: 80, host: 2000, host_ip: "0.0.0.0"`
1584
-
1585
- ### Forwarding the ssh-port
1586
-
1587
- Vagrant-libvirt now supports forwarding the standard ssh-port on port 2222 from
1588
- the localhost to allow for consistent provisioning steps/ports to be used when
1589
- defining across multiple providers.
1590
-
1591
- To enable, set the following:
1592
- ```ruby
1593
- Vagrant.configure("2") do |config|
1594
- config.vm.provider :libvirt do |libvirt|
1595
- # Enable forwarding of forwarded_port with id 'ssh'.
1596
- libvirt.forward_ssh_port = true
1597
- end
1598
- end
1599
- ```
1600
-
1601
- Previously by default libvirt skipped the forwarding of the ssh-port because
1602
- you can access the machine directly. In the future it is expected that this
1603
- will be enabled by default once autocorrect support is added to handle port
1604
- collisions for multi machine environments gracefully.
1605
-
1606
- ## Synced Folders
1607
-
1608
- Vagrant automatically syncs the project folder on the host to `/vagrant` in
1609
- the guest. You can also configure additional synced folders.
1610
-
1611
- **SECURITY NOTE:** for remote Libvirt, nfs synced folders requires a bridged
1612
- public network interface and you must connect to Libvirt via ssh.
1613
-
1614
- **NFS**
1615
-
1616
- `vagrant-libvirt` supports
1617
- [NFS](https://www.vagrantup.com/docs/synced-folders/nfs) as default with
1618
- bidirectional synced folders.
1619
-
1620
- Example with NFS:
1621
-
1622
- ``` ruby
1623
- Vagrant.configure("2") do |config|
1624
- config.vm.synced_folder "./", "/vagrant"
1625
- end
1626
- ```
1627
-
1628
- **RSync**
1629
-
1630
- `vagrant-libvirt` supports
1631
- [rsync](https://www.vagrantup.com/docs/synced-folders/rsync) with
1632
- unidirectional synced folders.
1633
-
1634
- Example with rsync:
1635
-
1636
- ``` ruby
1637
- Vagrant.configure("2") do |config|
1638
- config.vm.synced_folder "./", "/vagrant", type: "rsync"
1639
- end
1640
- ```
1641
-
1642
- **9P**
1643
-
1644
- `vagrant-libvirt` supports [VirtFS](http://www.linux-kvm.org/page/VirtFS) ([9p
1645
- or Plan 9](https://en.wikipedia.org/wiki/9P_\(protocol\))) with bidirectional
1646
- synced folders.
1647
-
1648
- Difference between NFS and 9p is explained
1649
- [here](https://unix.stackexchange.com/questions/240281/virtfs-plan-9-vs-nfs-as-tool-for-share-folder-for-virtual-machine).
1650
-
1651
- For 9p shares, a `mount: false` option allows to define synced folders without
1652
- mounting them at boot.
1653
-
1654
- Example for `accessmode: "squash"` with 9p:
1655
-
1656
- ``` ruby
1657
- Vagrant.configure("2") do |config|
1658
- config.vm.synced_folder "./", "/vagrant", type: "9p", disabled: false, accessmode: "squash", owner: "1000"
1659
- end
1660
- ```
1661
-
1662
- Example for `accessmode: "mapped"` with 9p:
1663
-
1664
- ``` ruby
1665
- Vagrant.configure("2") do |config|
1666
- config.vm.synced_folder "./", "/vagrant", type: "9p", disabled: false, accessmode: "mapped", mount: false
1667
- end
1668
- ```
1669
-
1670
- Further documentation on using 9p can be found in [kernel
1671
- docs](https://www.kernel.org/doc/Documentation/filesystems/9p.txt) and in
1672
- [QEMU
1673
- wiki](https://wiki.qemu.org/Documentation/9psetup#Starting_the_Guest_directly).
1674
-
1675
- Please do note that 9p depends on support in the guest and not all distros
1676
- come with the 9p module by default.
1677
-
1678
- **Virtio-fs**
1679
-
1680
- `vagrant-libvirt` supports [Virtio-fs](https://virtio-fs.gitlab.io/) with
1681
- bidirectional synced folders.
1682
-
1683
- For virtiofs shares, a `mount: false` option allows to define synced folders
1684
- without mounting them at boot.
3
+ ![Vagrant Libvirt Logo](docs/assets/images/logo.png?raw=true "Vagrant Libvirt")
1685
4
 
1686
- So far, passthrough is the only supported access mode and it requires running
1687
- the virtiofsd daemon as root.
1688
-
1689
- QEMU needs to allocate the backing memory for all the guest RAM as shared
1690
- memory, e.g. [Use file-backed
1691
- memory](https://libvirt.org/kbase/virtiofs.html#host-setup) by enable
1692
- `memory_backing_dir` option in `/etc/libvirt/qemu.conf`:
1693
-
1694
- ``` shell
1695
- memory_backing_dir = "/dev/shm"
1696
- ```
1697
-
1698
- Example for Libvirt \>= 6.2.0 (e.g. Ubuntu 20.10 with Linux 5.8.0 + QEMU 5.0 +
1699
- Libvirt 6.6.0, i.e. NUMA nodes required) with virtiofs:
1700
-
1701
- ``` ruby
1702
- Vagrant.configure("2") do |config|
1703
- config.vm.provider :libvirt do |libvirt|
1704
- libvirt.cpus = 2
1705
- libvirt.numa_nodes = [{ :cpus => "0-1", :memory => 8192, :memAccess => "shared" }]
1706
- libvirt.memorybacking :access, :mode => "shared"
1707
- end
1708
- config.vm.synced_folder "./", "/vagrant", type: "virtiofs"
1709
- end
1710
- ```
1711
-
1712
- Example for Libvirt \>= 6.9.0 (e.g. Ubuntu 21.04 with Linux 5.11.0 + QEMU 5.2 +
1713
- Libvirt 7.0.0, or Ubuntu 20.04 + [PPA
1714
- enabled](https://launchpad.net/~savoury1/+archive/ubuntu/virtualisation)) with
1715
- virtiofs:
1716
-
1717
- ``` ruby
1718
- Vagrant.configure("2") do |config|
1719
- config.vm.provider :libvirt do |libvirt|
1720
- libvirt.cpus = 2
1721
- libvirt.memory = 8192
1722
- libvirt.memorybacking :access, :mode => "shared"
1723
- end
1724
- config.vm.synced_folder "./", "/vagrant", type: "virtiofs"
1725
- end
1726
- ```
1727
-
1728
- Further documentation on using virtiofs can be found in [official
1729
- HowTo](https://virtio-fs.gitlab.io/index.html#howto) and in [Libvirt
1730
- KB](https://libvirt.org/kbase/virtiofs.html).
1731
-
1732
- Please do note that virtiofs depends on:
1733
-
1734
- - Host: Linux \>= 5.4, QEMU \>= 4.2 and Libvirt \>= 6.2 (e.g. Ubuntu 20.10)
1735
- - Guest: Linux \>= 5.4 (e.g. Ubuntu 20.04)
1736
-
1737
- ## QEMU Session Support
1738
-
1739
- vagrant-libvirt supports using QEMU user sessions to maintain Vagrant VMs. As the session connection does not have root access to the system features which require root will not work. Access to networks created by the system QEMU connection can be granted by using the [QEMU bridge helper](https://wiki.qemu.org/Features/HelperNetworking). The bridge helper is enabled by default on some distros but may need to be enabled/installed on others.
1740
-
1741
- There must be a virbr network defined in the QEMU system session. The libvirt `default` network which comes by default, the vagrant `vagrant-libvirt` network which is generated if you run a Vagrantfile using the System session, or a manually defined network can be used. These networks can be set to autostart with `sudo virsh net-autostart <net-name>`, which'll mean no further root access is required even after reboots.
1742
-
1743
- The QEMU bridge helper is configured via `/etc/qemu/bridge.conf`. This file must include the virbr you wish to use (e.g. virbr0, virbr1, etc). You can find this out via `sudo virsh net-dumpxml <net-name>`.
1744
- ```
1745
- allow virbr0
1746
- ```
1747
-
1748
- An example configuration of a machine using the QEMU session connection:
1749
-
1750
- ```ruby
1751
- Vagrant.configure("2") do |config|
1752
- config.vm.provider :libvirt do |libvirt|
1753
- # Use QEMU session instead of system connection
1754
- libvirt.qemu_use_session = true
1755
- # URI of QEMU session connection, default is as below
1756
- libvirt.uri = 'qemu:///session'
1757
- # URI of QEMU system connection, use to obtain IP address for management, default is below
1758
- libvirt.system_uri = 'qemu:///system'
1759
- # Path to store Libvirt images for the virtual machine, default is as ~/.local/share/libvirt/images
1760
- libvirt.storage_pool_path = '/home/user/.local/share/libvirt/images'
1761
- # Management network device, default is below
1762
- libvirt.management_network_device = 'virbr0'
1763
- end
1764
-
1765
- # Public network configuration using existing network device
1766
- # Note: Private networks do not work with QEMU session enabled as root access is required to create new network devices
1767
- config.vm.network :public_network, :dev => "virbr1",
1768
- :mode => "bridge",
1769
- :type => "bridge"
1770
- end
1771
- ```
1772
-
1773
- ## Customized Graphics
1774
-
1775
- vagrant-libvirt supports customizing the display and video settings of the
1776
- managed guest. This is probably most useful for VNC-type displays with
1777
- multiple guests. It lets you specify the exact port for each guest to use
1778
- deterministically.
1779
-
1780
- Here is an example of using custom display options:
1781
-
1782
- ```ruby
1783
- Vagrant.configure("2") do |config|
1784
- config.vm.provider :libvirt do |libvirt|
1785
- libvirt.graphics_port = 5901
1786
- libvirt.graphics_ip = '0.0.0.0'
1787
- libvirt.video_type = 'qxl'
1788
- end
1789
- end
1790
- ```
1791
-
1792
- ## TPM Devices
1793
-
1794
- Modern versions of Libvirt support connecting to TPM devices on the host
1795
- system. This allows you to enable Trusted Boot Extensions, among other
1796
- features, on your guest VMs.
1797
-
1798
- To passthrough a hardware TPM, you will generally only need to modify the
1799
- `tpm_path` variable in your guest configuration. However, advanced usage,
1800
- such as the application of a Software TPM, may require modifying the
1801
- `tpm_model`, `tpm_type` and `tpm_version` variables.
1802
-
1803
- The TPM options will only be used if you specify a TPM path or version.
1804
- Declarations of any TPM options without specifying a path or version will
1805
- result in those options being ignored.
1806
-
1807
- Here is an example of using the TPM options:
1808
-
1809
- ```ruby
1810
- Vagrant.configure("2") do |config|
1811
- config.vm.provider :libvirt do |libvirt|
1812
- libvirt.tpm_model = 'tpm-tis'
1813
- libvirt.tpm_type = 'passthrough'
1814
- libvirt.tpm_path = '/dev/tpm0'
1815
- end
1816
- end
1817
- ```
1818
-
1819
- It's also possible for Libvirt to start an emulated TPM device on the host.
1820
- Requires `swtpm` and `swtpm-tools`
1821
-
1822
- ```ruby
1823
- Vagrant.configure("2") do |config|
1824
- config.vm.provider :libvirt do |libvirt|
1825
- libvirt.tpm_model = "tpm-crb"
1826
- libvirt.tpm_type = "emulator"
1827
- libvirt.tpm_version = "2.0"
1828
- end
1829
- end
1830
- ```
1831
-
1832
- ## Memory balloon
1833
-
1834
- The configuration of the memory balloon device can be overridden. By default,
1835
- libvirt will automatically attach a memory balloon; this behavior is preserved
1836
- by not configuring any memballoon-related options. The memory balloon can be
1837
- explicitly disabled by setting `memballoon_enabled` to `false`. Setting
1838
- `memballoon_enabled` to `true` will allow additional configuration of
1839
- memballoon-related options.
1840
-
1841
- Here is an example of using the memballoon options:
1842
-
1843
- ```ruby
1844
- Vagrant.configure("2") do |config|
1845
- config.vm.provider :libvirt do |libvirt|
1846
- libvirt.memballoon_enabled = true
1847
- libvirt.memballoon_model = 'virtio'
1848
- libvirt.memballoon_pci_bus = '0x00'
1849
- libvirt.memballoon_pci_slot = '0x0f'
1850
- end
1851
- end
1852
- ```
1853
-
1854
- ## Libvirt communication channels
1855
-
1856
- For certain functionality to be available within a guest, a private
1857
- communication channel must be established with the host. Two notable examples
1858
- of this are the QEMU guest agent, and the Spice/QXL graphics type.
1859
-
1860
- Below is a simple example which exposes a virtio serial channel to the guest.
1861
- Note: in a multi-VM environment, the channel would be created for all VMs.
1862
-
1863
- ```ruby
1864
- vagrant.configure(2) do |config|
1865
- config.vm.provider :libvirt do |libvirt|
1866
- libvirt.channel :type => 'unix', :target_name => 'org.qemu.guest_agent.0', :target_type => 'virtio'
1867
- end
1868
- end
1869
- ```
1870
-
1871
- Below is the syntax for creating a spicevmc channel for use by a qxl graphics
1872
- card.
1873
-
1874
- ```ruby
1875
- vagrant.configure(2) do |config|
1876
- config.vm.provider :libvirt do |libvirt|
1877
- libvirt.channel :type => 'spicevmc', :target_name => 'com.redhat.spice.0', :target_type => 'virtio'
1878
- end
1879
- end
1880
- ```
1881
-
1882
- These settings can be specified on a per-VM basis, however the per-guest
1883
- settings will OVERRIDE any global 'config' setting. In the following example,
1884
- we create 3 VMs with the following configuration:
1885
-
1886
- * **master**: No channel settings specified, so we default to the provider
1887
- setting of a single virtio guest agent channel.
1888
- * **node1**: Override the channel setting, setting both the guest agent
1889
- channel, and a spicevmc channel
1890
- * **node2**: Override the channel setting, setting both the guest agent
1891
- channel, and a 'guestfwd' channel. TCP traffic sent by the guest to the given
1892
- IP address and port is forwarded to the host socket `/tmp/foo`. Note: this
1893
- device must be unique for each VM.
1894
-
1895
- For example:
1896
-
1897
- ```ruby
1898
- Vagrant.configure(2) do |config|
1899
- config.vm.box = "fedora/32-cloud-base"
1900
- config.vm.provider :libvirt do |libvirt|
1901
- libvirt.channel :type => 'unix', :target_name => 'org.qemu.guest_agent.0', :target_type => 'virtio'
1902
- end
1903
-
1904
- config.vm.define "master" do |master|
1905
- master.vm.provider :libvirt do |domain|
1906
- domain.memory = 1024
1907
- end
1908
- end
1909
- config.vm.define "node1" do |node1|
1910
- node1.vm.provider :libvirt do |domain|
1911
- domain.channel :type => 'unix', :target_name => 'org.qemu.guest_agent.0', :target_type => 'virtio'
1912
- domain.channel :type => 'spicevmc', :target_name => 'com.redhat.spice.0', :target_type => 'virtio'
1913
- end
1914
- end
1915
- config.vm.define "node2" do |node2|
1916
- node2.vm.provider :libvirt do |domain|
1917
- domain.channel :type => 'unix', :target_name => 'org.qemu.guest_agent.0', :target_type => 'virtio'
1918
- domain.channel :type => 'unix', :target_type => 'guestfwd', :target_address => '192.0.2.42', :target_port => '4242',
1919
- :source_path => '/tmp/foo'
1920
- end
1921
- end
1922
- end
1923
- ```
1924
-
1925
- ## Custom command line arguments and environment variables
1926
- You can also specify multiple qemuargs arguments or qemuenv environment variables for qemu-system
1927
-
1928
- * `value` - Value
1929
-
1930
- ```ruby
1931
- Vagrant.configure("2") do |config|
1932
- config.vm.provider :libvirt do |libvirt|
1933
- libvirt.qemuargs :value => "-device"
1934
- libvirt.qemuargs :value => "intel-iommu"
1935
- libvirt.qemuenv QEMU_AUDIO_DRV: 'pa'
1936
- libvirt.qemuenv QEMU_AUDIO_TIMER_PERIOD: '150'
1937
- libvirt.qemuenv QEMU_PA_SAMPLES: '1024', QEMU_PA_SERVER: '/run/user/1000/pulse/native'
1938
- end
1939
- end
1940
- ```
1941
-
1942
- ## Box Formats
1943
-
1944
- ### Version 1
1945
-
1946
- This is the original format that most boxes currently use.
1947
-
1948
- You can view an example box in the
1949
- [`example_box/directory`](https://github.com/vagrant-libvirt/vagrant-libvirt/tree/master/example_box).
1950
- That directory also contains instructions on how to build a box.
5
+ [![Join the chat at https://gitter.im/vagrant-libvirt/vagrant-libvirt](https://badges.gitter.im/vagrant-libvirt/vagrant-libvirt.svg)](https://gitter.im/vagrant-libvirt/vagrant-libvirt?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
6
+ [![Build Status](https://github.com/vagrant-libvirt/vagrant-libvirt/actions/workflows/unit-tests.yml/badge.svg)](https://github.com/vagrant-libvirt/vagrant-libvirt/actions/workflows/unit-tests.yml)
7
+ [![Coverage Status](https://coveralls.io/repos/github/vagrant-libvirt/vagrant-libvirt/badge.svg?branch=master)](https://coveralls.io/github/vagrant-libvirt/vagrant-libvirt?branch=master)
8
+ [![Gem Version](https://badge.fury.io/rb/vagrant-libvirt.svg)](https://badge.fury.io/rb/vagrant-libvirt)
1951
9
 
1952
- The box is a tarball containing:
10
+ This is a [Vagrant](http://www.vagrantup.com) plugin that adds a
11
+ [Libvirt](http://libvirt.org) provider to Vagrant, allowing Vagrant to
12
+ control and provision machines via Libvirt toolkit.
1953
13
 
1954
- * qcow2 image file named `box.img`
1955
- * `metadata.json` file describing box image (`provider`, `virtual_size`,
1956
- `format`)
1957
- * `Vagrantfile` that does default settings for the provider-specific
1958
- configuration for this provider
14
+ **Note:** Actual version is still a development one. Feedback is welcome and
15
+ can help a lot :-)
1959
16
 
17
+ Vagrant-libvirt Documentation is published at [https://vagrant-libvirt.github.io/vagrant-libvirt/](https://vagrant-libvirt.github.io/vagrant-libvirt/)
1960
18
 
1961
- ### Version 2 (Experimental)
19
+ ## Index
1962
20
 
1963
- Due to the limitation of only being able to handle a single disk with the version 1 format, a new
1964
- format was added to support boxes that need to specify multiple disks. This is still currently
1965
- experimental and as such support for packaging has yet to be added. There is a script in the tools
1966
- folder (tools/create_box_with_two_disks.sh) that should provide a guideline on how to create such
1967
- a box for those that wish to experiment and provide early feedback.
21
+ <!-- vim-markdown-toc GFM -->
1968
22
 
1969
- At it's most basic, it expects an array of disks to allow a specific order to be presented. Disks
1970
- will be attached in this order and as such assume device names base on this within the VM. The
1971
- 'path' attribute is required, and is expected to be relative to the base of the box. This should
1972
- allow placing the disk images within a nested directory within the box if it useful for those
1973
- with a larger number of disks. The name allows overriding the target volume name that will be
1974
- used in the libvirt storage pool. Note that vagrant-libvirt will still prefix the volume name
1975
- with `#{box_name}_vagrant_box_image_#{box_version}_` to avoid accidental clashes with other boxes.
23
+ * [Installing](#installing)
24
+ * [Running](#running)
25
+ * [Development](#development)
26
+ * [Contributing](#contributing)
1976
27
 
1977
- Format and virtual size need no longer be specified as they are now retrieved directly from the
1978
- provided image using `qemu-img info ...`.
28
+ <!-- vim-markdown-toc -->
1979
29
 
1980
- Example format:
1981
- ```json
1982
- {
1983
- 'disks': [
1984
- {
1985
- 'path': 'disk1.img'
1986
- },
1987
- {
1988
- 'path': 'disk2.img',
1989
- 'name': 'secondary_disk'
1990
- },
1991
- {
1992
- 'path': 'disk3.img'
1993
- }
1994
- ],
1995
- 'provider': 'libvirt'
1996
- }
1997
- ```
30
+ ## Installing
1998
31
 
1999
- ## Create Box
32
+ Installation typically involves a number of distribution package dependencies to ensure that Libvirt is available.
33
+ Recommend that you follow the [installation guide](https://vagrant-libvirt.github.io/vagrant-libvirt/installation.html).
2000
34
 
2001
- If creating a box from a modified vagrant-libvirt machine, ensure that
2002
- you have set the `config.ssh.insert_key = false` in the original Vagrantfile
2003
- as otherwise Vagrant will replace the default connection key-pair that is
2004
- required on first boot with one specific to the machine and prevent
2005
- the default key from working on the exported result.
2006
- ```ruby
2007
- Vagrant.configure("2") do |config|
2008
- # this setting is only recommended if planning to export the
2009
- # resulting machine
2010
- config.ssh.insert_key = false
35
+ ## Running
2011
36
 
2012
- config.vm.define :test_vm do |test_vm|
2013
- test_vm.vm.box = "fedora/32-cloud-base"
2014
- end
2015
- end
2016
- ```
37
+ Once installed, use vagrant-libvirt through vagrant.
2017
38
 
2018
- To create a vagrant-libvirt box from a qcow2 image, run `create_box.sh`
2019
- (located in the tools directory):
39
+ Locate a vagrant box containing the distribution you want to use at
40
+ [Vagrant Cloud](https://app.vagrantup.com/boxes/search?provider=libvirt) and
41
+ initialize.
2020
42
 
2021
43
  ```shell
2022
- $ create_box.sh ubuntu14.qcow2
44
+ vagrant init fedora/32-cloud-base
2023
45
  ```
2024
46
 
2025
- You can also create a box by using [Packer](https://packer.io). Packer
2026
- templates for use with vagrant-libvirt are available at
2027
- https://github.com/jakobadam/packer-qemu-templates. After cloning that project
2028
- you can build a vagrant-libvirt box by running:
47
+ Then run following command:
2029
48
 
2030
49
  ```shell
2031
- $ cd packer-qemu-templates
2032
- $ packer build ubuntu-14.04-server-amd64-vagrant.json
50
+ vagrant up --provider=libvirt
2033
51
  ```
2034
52
 
2035
- ## Package Box from VM
2036
-
2037
- vagrant-libvirt has native support for [`vagrant
2038
- package`](https://www.vagrantup.com/docs/cli/package.html) via
2039
- libguestfs [virt-sysprep](http://libguestfs.org/virt-sysprep.1.html).
2040
- virt-sysprep operations can be customized via the
2041
- `VAGRANT_LIBVIRT_VIRT_SYSPREP_OPERATIONS` environment variable; see the
2042
- [upstream
2043
- documentation](http://libguestfs.org/virt-sysprep.1.html#operations) for
2044
- further details especially on default sysprep operations enabled for
2045
- your system.
2046
-
2047
- Options to the virt-sysprep command call can be passed via
2048
- `VAGRANT_LIBVIRT_VIRT_SYSPREP_OPTIONS` environment variable.
53
+ Vagrant needs to know that we want to use Libvirt and not default VirtualBox.
54
+ That's why there is `--provider=libvirt` option specified. Other way to tell
55
+ Vagrant to use Libvirt provider is to setup environment variable
2049
56
 
2050
57
  ```shell
2051
- $ export VAGRANT_LIBVIRT_VIRT_SYSPREP_OPTIONS="--delete /etc/hostname"
2052
- $ vagrant package
58
+ export VAGRANT_DEFAULT_PROVIDER=libvirt
2053
59
  ```
2054
60
 
2055
- For example, on Chef [bento](https://github.com/chef/bento) VMs that
2056
- require SSH hostkeys already set (e.g. bento/debian-7) as well as leave
2057
- existing LVM UUIDs untouched (e.g. bento/ubuntu-18.04), these can be
2058
- packaged into vagrant-libvirt boxes like so:
2059
-
61
+ Afterwards to enter the VM simply use:
2060
62
  ```shell
2061
- $ export VAGRANT_LIBVIRT_VIRT_SYSPREP_OPERATIONS="defaults,-ssh-userdir,-ssh-hostkeys,-lvm-uuids"
2062
- $ vagrant package
63
+ vagrant ssh
2063
64
  ```
2064
65
 
2065
- ## Troubleshooting VMs
2066
-
2067
- The first step for troubleshooting a VM image that appears to not boot correctly,
2068
- or hangs waiting to get an IP, is to check it with a VNC viewer. A key thing
2069
- to remember is that if the VM doesn't get an IP, then vagrant can't communicate
2070
- with it to configure anything, so a problem at this stage is likely to come from
2071
- the VM, but we'll outline the tools and common problems to help you troubleshoot
2072
- that.
2073
-
2074
- By default, when you create a new VM, a vnc server will listen on `127.0.0.1` on
2075
- port `TCP5900`. If you connect with a vnc viewer you can see the boot process. If
2076
- your VM isn't listening on `5900` by default, you can use `virsh dumpxml` to find
2077
- out which port it's listening on, or can configure it with `graphics_port` and
2078
- `graphics_ip` (see 'Domain Specific Options' above).
2079
-
2080
- Note: Connecting with the console (`virsh console`) requires additional config,
2081
- so some VMs may not show anything on the console at all, instead displaying it in
2082
- the VNC console. The issue with the text console is that you also need to build the
2083
- image used to tell the kernel to output to the console during boot, and typically
2084
- most do not have this built in.
2085
-
2086
- Problems we've seen in the past include:
2087
- - Forgetting to remove `/etc/udev/rules.d/70-persistent-net.rules` before packaging
2088
- the VM
2089
- - VMs expecting a specific disk device to be connected
2090
-
2091
- If you're still confused, check the Github Issues for this repo for anything that
2092
- looks similar to your problem.
2093
-
2094
- [Github Issue #1032](https://github.com/vagrant-libvirt/vagrant-libvirt/issues/1032)
2095
- contains some historical troubleshooting for VMs that appeared to hang.
2096
-
2097
- Did you hit a problem that you'd like to note here to save time in the future?
2098
- Please do!
2099
-
66
+ If you can't find a box that works as you need, have a look at our documentation
67
+ on [creating boxes](https://vagrant-libvirt.github.io/vagrant-libvirt/boxes.html#creating-boxes)
68
+ on how to take existing ones, customize them and repackage.
2100
69
 
2101
70
  ## Development
2102
71
 
@@ -2104,16 +73,16 @@ To work on the `vagrant-libvirt` plugin, clone this repository out, and use
2104
73
  [Bundler](http://gembundler.com) to get the dependencies:
2105
74
 
2106
75
  ```shell
2107
- $ git clone https://github.com/vagrant-libvirt/vagrant-libvirt.git
2108
- $ cd vagrant-libvirt
2109
- $ bundle install
76
+ git clone https://github.com/vagrant-libvirt/vagrant-libvirt.git
77
+ cd vagrant-libvirt
78
+ bundle install
2110
79
  ```
2111
80
 
2112
81
  Once you have the dependencies, verify the unit tests pass with `rspec`:
2113
82
 
2114
83
  ```shell
2115
- $ export VAGRANT_HOME=$(mktemp -d)
2116
- $ bundle exec rspec --fail-fast --color --format documentation
84
+ export VAGRANT_HOME=$(mktemp -d)
85
+ bundle exec rspec --fail-fast --color --format documentation
2117
86
  ```
2118
87
 
2119
88
  If those pass, you're ready to start developing the plugin.
@@ -2125,14 +94,17 @@ Additionally if you wish to test against a specific version of vagrant you
2125
94
  can control the version using the following before running the tests:
2126
95
 
2127
96
  ```shell
2128
- $ export VAGRANT_VERSION=v2.2.14
97
+ export VAGRANT_VERSION=v2.2.14
98
+ bundle update && bundle exec rspec --fail-fast --color --format documentation
2129
99
  ```
2130
100
 
2131
101
  **Note** rvm is used by the maintainers to help provide an environment to test
2132
102
  against multiple ruby versions that align with the ones used by vagrant for
2133
103
  their embedded ruby depending on the release. You can see what version is used
2134
104
  by looking at the current [unit tests](.github/workflows/unit-tests.yml)
2135
- workflow.
105
+ workflow. By default if you have rvm installed and enabled it this project looks
106
+ to use ruby 2.6.6 and configures a separate gemset, both of which will be switched
107
+ to each time you enter the project directory.
2136
108
 
2137
109
  You can test the plugin without installing it into your Vagrant environment by
2138
110
  just creating a `Vagrantfile` in the top level of this directory (it is
@@ -2166,6 +138,7 @@ $ bundle exec vagrant up --provider=libvirt
2166
138
  **IMPORTANT NOTE:** bundle is crucial. You need to use bundled Vagrant.
2167
139
 
2168
140
  ## Contributing
141
+ [![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](https://github.com/vagrant-libvirt/vagrant-libvirt/issues)
2169
142
 
2170
143
  1. Fork it
2171
144
  2. Create your feature branch (`git checkout -b my-new-feature`)
@@ -2173,6 +146,8 @@ $ bundle exec vagrant up --provider=libvirt
2173
146
  4. Push to the branch (`git push origin my-new-feature`)
2174
147
  5. Create new Pull Request
2175
148
 
149
+ For future work take a look at [open issues](https://github.com/vagrant-libvirt/vagrant-libvirt/issues?state=open).
150
+
2176
151
  <!--
2177
152
  # styling for TOC
2178
153
  vim: expandtab shiftwidth=2