
Step 1 : Update the repo for Ubuntu / Debian system.
sudo apt update
Step 2 : Install Libvirt and relevant packages: If you have not installed vagrant yet, add it in the following line. (vagrant)
sudo apt install -y libvirt-daemon-system libvirt-dev libvirt-clients virt-manager qemu-kvm ebtables libguestfs-tools ruby-fog-libvirt
Step 3 : Start the Libvirt service
sudo systemctl start libvirtd
Enable it so that it starts at boot time with your system:
sudo systemctl enable libvirtd
Verify all is well using the following. Aim for no errors or warnings:
sudo virsh list --all
Step 4 : Install vagrant plugin for Vagrant:
vagrant plugin install vagrant-libvirt
Step 5: Add your user to the libvirt group so that you won’t have to use sudo with vagrant, i.e sudo vagrant up, sudo vagrant ssh and so on.
sudo usermod -aG libvirt $(whoami)
Step 6 : Test it. Initialize a vagrantfile for Debian 11 box with libvirt as the provider. Do this in the directory where you want your machine.
# Go to your working directory cd /my/working/directory #Create a vagrant file vagrant init debian/bullseye64 #Bring up the machine vagrant up --provider=libvirt
Source :- Docs
Bonus : NFS server for syncing vagrant files
Problem : It appears your machine doesn’t support NFS, or there is not an
adapter to enable NFS on this machine for Vagrant. Please verify
that nfsd
is installed on your machine, and try again. If you’re
on Windows, NFS isn’t supported. If the problem persists, please
contact Vagrant support.
Fix:
Enable NFS on supported machines. To do this you will need to install nfsd, an implementation of NFS , which will enable you to run an NFS server in Debian.
Install nfsd on Debian, start it and enable it to start up on boot.
sudo apt-get install nfs-kernel-server && sudo systemctl start nfs-kernel-server && sudo systemctl enable nfs-kernel-server
To stop the server you can do:
sudo systemctl stop nfs-kernel-server
Job for nfs-server.service canceled
If you encounter the error, Job for nfs-server.service canceled, fix it using the steps below:
sudo apt purge nfs-kernel-server # Then reinstall and enable it again: sudo apt-get install nfs-kernel-server && sudo systemctl enable nfs-kernel-server
If your nfs server issues are due to old missing machines, recreate the /etc/exports file:
#backup the old file by renaming it
sudo mv /etc/exports /etc/exportsold
#Recreate an empty one:
sudo touch /etc/exports
# Then restart nfs-server
sudo systemctl start nfs-kernel-server