[[http://vagrantup.com|Vagrant]] is an application that manages virtualized environments (boxes) allowing to control the creation and provisionning of virtual machines, which may share some resources (folders) with the host. Vagrant supports different virtualization engines (providers), among which [[VirtualBox]] is historically the most popular. <> == Installation == === Installation with libvirt === [[libvirt|Libvirt]] is a good provider for Vagrant because it's faster than [[VirtualBox]] and it's in the main repository. Install it as follow: {{{ sudo apt install vagrant-libvirt libvirt-daemon-system }}} Ensure your user is a member of the libvirt group (this is needed to manage libvirt via the qemu:///system uri, which is the default for vagrant-libvirt) {{{ sudo usermod --append --groups libvirt $USER }}} logout and login so that your group membership applies {{{ # should return libvirt groups | grep -o libvirt }}} start your first vagrant environment {{{ vagrant init debian/buster64 vagrant up --provider=libvirt vagrant ssh }}} == Debian Vagrant base box == There is an ongoing effort to provide [[Teams/Cloud/VagrantBaseBoxes]] for Vagrant's cloud backend. == Creating Debian vagrant boxes == You also may wish to create your own Debian boxes, Debian currently uses [[DebianMan:fai-diskimage]] to build the boxes hosted on the Vagrant cloud. == Troubleshooting == === Vagrant cannot be installed with Virtualbox 7 on Debian 11 === If you use VirtualBox 7 (currently available from https://fasttrack.debian.net/ ), you need to install the vagrant package available in the bullseye-proposed-updates repository (version 2.2.14+dfsg-2), which includes a compatibility fix for VirtualBox 7. === Vagrant from Debian 11 or previous versions hang on "default: Waiting for SSH to become available..." === This is caused by a bug in Vagrant in the handling of ssh-rsa keys: Vagrant always try to connect to the VM using SHA-1 algorithm, although this algorithm has been removed from OpenSSH in version 8.8 (see [[https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1011756#15|that comment in the Debian Bug Tracker System ]]). Workarounds (as of 2022-05-30) are: * install the vagrant version from testing / Debian 12 * install ruby-net-ssh version 1:6.1.0-2+deb11u1 from stable-proposed-updates * install ruby-net-ssh version 1:6.3.0~beta1+git20220405.dd7f11a-1~bpo11+1 (or higher) from bullseye-backports === Errors on NFS mount on Debian 8 and 9 boxes === During the `vagrant up` process you can get this error on Debian 8 as well as in Debian 9: {{{ The following SSH command responded with a non-zero exit status. Vagrant assumes that this means the command failed! mount -o vers=4 192.168.121.1:/home/jhon/projects/foo /vagrant result=$? if test $result -eq 0; then if test -x /sbin/initctl && command -v /sbin/init && /sbin/init 2>/dev/null --version | grep upstart; then /sbin/initctl emit --no-wait vagrant-mounted MOUNTPOINT=/vagrant fi else exit $result fi Stdout from the command: Stderr from the command: mount.nfs: access denied by server while mounting 192.168.121.1:/home/jhon/projects/foo }}} First of all ensure that your NFS daemon is running: {{{ sudo systemctl status nfs-common sudo systemctl status nfs-kernel-server }}} Then copy from the above error the `mount` command and try running it on yourself, but downgrading the NFS version (the `vers`): {{{ vagrant ssh sudo mount -o vers=3 192.168.121.1:/home/jhon/projects/foo /vagrant }}} If it works manually, than you can fix it adding this line into your `Vagrantfile`: {{{ config.vm.synced_folder ".", "/vagrant", nfs_version: "3" }}} === Hang on "Waiting for domain to get an IP address..." === If vagrant seems to hang forever on this step: {{{ Waiting for domain to get an IP address... }}} it might be worth killing that process (with `control-c`), then destroying the VM and starting again: {{{ vagrant destroy vagrant up }}} It's unclear why, but sometimes this process doesn't succesfully complete in libvirt. It might be worth starting `virt-manager` to confirm the VM is running. === Failure to start on NFS === If you get this error message: {{{ 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. }}} It's possible (and understandable) you haven't setup NFS (or haven't set it up correctly). A fairly simple workaround is to use *another* folder sharing plugin. There are multiple [[https://www.vagrantup.com/docs/synced-folders|synced folder mechanisms]] in Vagrant. Unfortunately, changing the plugin requires you to edit the Vagrantfile (as opposed to just using a commandline argument). To switch to `rsync`, for example, you can simply use: {{{ config.vm.synced_folder ".", "/vagrant", type: "rsync" }}} in your Vagrantfile. Note that this will not reflect changes in realtime between the VM and the host until you run the [[http://web.archive.org/web/20170707201620/https://www.vagrantup.com/docs/cli/rsync.html|vagrant rsync]] command. The [[http://web.archive.org/web/20170707201903/https://www.vagrantup.com/docs/cli/rsync-auto.html|vagrant rsync-auto]] command can also do that in the background. You can also use the "9p" (and virtiofs) module with: {{{ config.vm.synced_folder './', '/vagrant', type: '9p', disabled: false, accessmode: "squash", owner: "1000" }}} See also the [[https://github.com/vagrant-libvirt/vagrant-libvirt#synced-folders|libvirt synced folders documentation]].