Vagrant libvirt allows the user to customize the virtual machines to add features and use QEMU options that are not exposed via the plugin itself. For this it uses the libvirt's custom QEMU arguments options which appends the args at the very end of the command line. This allows you to not only add new arguments, it allows you to also override the plugin constructed defaults.
In the snippet below the
- machine and memory default plugin arguments are over-ridden
- an additional NVDIMM device is created and added to the machine
config.vm.define vm_name do |c|
c.vm.hostname = vm_name
c.vm.network :private_network, ip: ip, autostart: true
c.vm.provider :libvirt do |lv|
lv.qemuargs :value => '-machine'
lv.qemuargs :value => 'pc,accel=kvm,nvdimm=on'
lv.qemuargs :value => '-m'
lv.qemuargs :value => '2G,slots=2,maxmem=34G'
lv.qemuargs :value => '-object'
lv.qemuargs :value => 'memory-backend-file,id=mem1,share=on,mem-path=/dev/shm,size=32768M'
lv.qemuargs :value => '-device'
lv.qemuargs :value => 'nvdimm,id=nvdimm1,memdev=mem1,label-size=2097152'
lv.cpu_mode = "host-passthrough"
lv.nested = true
lv.loader = $loader
lv.cpus = $cpus
#lv.memory = $memory
(1..$disks).each do |d|
lv.storage :file, :device => "hd#{$driveletters[d]}", :path => "disk-#{$disk_prefix}-#{vm_name}-#{d}.disk", :size => $disk_size, :type => "raw"
end
end
Note: In the above example /dev/shm cannot be accessed due to libvirt's security policies. Hence you need to currently set
in /etc/libvirt/qemu.conf