Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mcastelino/d7477dd6183244c5fe64c17c9b4c2c88 to your computer and use it in GitHub Desktop.
Save mcastelino/d7477dd6183244c5fe64c17c9b4c2c88 to your computer and use it in GitHub Desktop.
Vagrant Libvirt - Custom QEMU Argument to support NVDIMM and other features

Vagrant-libvirt QEMU customization

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
@mcastelino
Copy link
Author

Note: In the above example /dev/shm cannot be accessed due to libvirt's security policies. Hence you need to currently set

security_driver = "none"

in /etc/libvirt/qemu.conf

@mcastelino
Copy link
Author

mcastelino commented Jun 6, 2019

Alternately on ubuntu the user should be able to just modify the apparmour profile to allow access to /dev/shm

By updating /etc/apparmor.d/abstractions/libvirt-qemu to include

/dev/shm/* rw,

Someone who knows selinux can tell me how to do this with selinux :)

@electrocucaracha
Copy link

/dev/shm/* rw,

In my ubuntu server this entry like this one:

/{dev,run}/shm rw,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment