I am trying to setup Vagrant in Fedora 23 with libvirt. It boots and everything looks fine until I get asked for "sudo password: Preparing to edit /etc/exports. Administrator privileges will be required".

I run Vagrant as a normal user and do not want to run it as root, nor add myself to the sudoers file. Just to test, I have run vagrant up as root and everything worked, but I am not comfortable with running Vagrant like this.

I found something while googling for fixes and that was to change the permissions of the /etc/exports file. This works and let me run vagrant up as a normal user, but it feels like a dirty fix to me. What is the downside with changing the permissions of the /etc/exports file? I would really like to get Vagrant running as a normal user without having to affect security.

Virtualbox is not an alternative due to the kernel updates. I do not want to risk anything breaking or wait for Oracle or rpmfusion updating the kernel modules for Virtualbox.

I have followed these instructions from Fedora Developer portal:

$ sudo dnf install vagrant-libvirt
$ sudo systemctl enable libvirtd
$ lsmod | grep kvm

lsmod | grep kvm does not return anything, so I have edit the Vagrantfile to use the qemu driver:

Vagrant.configure("2") do |config|
  config.vm.provider :libvirt do |libvirt|
    libvirt.driver = "qemu"

Using libvirt from Vagrant without password prompts

$ sudo gpasswd -a ${USER} libvirt
$ newgrp libvirt
Synced folders with NFS

$ sudo dnf install nfs-utils && sudo systemctl enable nfs-server

Afterwards enable nfs, rpc-bind and mountd services for firewalld:

$ sudo firewall-cmd --permanent --add-service=nfs &&
  sudo firewall-cmd --permanent --add-service=rpc-bind &&
  sudo firewall-cmd --permanent --add-service=mountd &&
  sudo firewall-cmd --reload

Using NFS shares from Vagrant without password prompts

$ sudo visudo

add this:

# Allow Vagrant to manage /etc/exports
Cmnd_Alias VAGRANT_EXPORTS_ADD = /usr/bin/tee -a /etc/exports
Cmnd_Alias VAGRANT_NFSD_CHECK = /usr/bin/systemctl status nfs-server.service
Cmnd_Alias VAGRANT_NFSD_START = /usr/bin/systemctl start nfs-server.service
Cmnd_Alias VAGRANT_NFSD_APPLY = /usr/sbin/exportfs -ar
Cmnd_Alias VAGRANT_EXPORTS_REMOVE = /bin/sed -r -e * d -ibak /etc/exports

Afterwards add yourself to the vagrant group if you are not there already by running:

$ sudo getent group vagrant >/dev/null || sudo groupadd -r vagrant
$ sudo gpasswd -a ${USER} vagrant
$ newgrp vagrant

Get Vagrant up and running:

$ vagrant init rboyer/ubuntu-trusty64-libvirt 
$ vagrant up

I have tried two different libvirt boxes from Vagrant box site: here and here

Help on this matter is very appreciated.Thanks.

  • Do you need synced folders in the first place? – techraf May 14 '16 at 7:01
  • It's not trying to run your VM or even Vagrant as Root, it's simply trying to edit /etc/exports so as to implemented a synced directory between the host and the VM. Do to this, you need root privileges to make the change. You will get the same prompt for vagrant destroy when you are done, to remove the selfsame edits to /etc/exports. – DopeGhoti May 14 '16 at 7:11
  • Thanks for replying. Sorry upfront for being somewhat noob (are starting on a computer degree this fall and are trying to learn as much as possible). I understand that I need to give root privileges to make the change, but when I run as a normal user and get this prompt, my password do not work since I am not in the sudoers file and I can't change to root in the boot process. I tought the section "Using NFS shares from Vagrant without password prompts" was supposed to take care of this. Do I have to use vagrant up from root or can I fix this so that I can run vagrant up as a normal user? – nan0s May 14 '16 at 13:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.