Date: 2025-10-27 Status: Ready to Execute
✅ Backed up Vagrantfile → Vagrantfile.virtualbox.backup
✅ Updated Vagrantfile to use libvirt provider with optimal settings
✅ Verified syntax of the new Vagrantfile
Run these commands in order. I've organized them into logical steps:
You mentioned you're about to run this - go ahead and run it now:
cd /home/jpoley/vagrant-linux && ./switch-to-kvm.shWhat this does:
- Unloads VirtualBox kernel modules
- Loads KVM kernel modules (kvm_intel or kvm_amd)
- Starts libvirt services
- Verifies KVM is functional
Expected output: Should complete successfully with green checkmarks
After the kernel switch completes, install the remaining build dependencies:
sudo apt-get update
sudo apt-get install -y libxslt-dev libxml2-dev libguestfs-toolsWhat this does:
- Installs XML processing libraries (libxslt, libxml2)
- Installs guest filesystem tools (libguestfs-tools)
- These are needed to compile the vagrant-libvirt plugin
Expected output: Package installation messages, should complete without errors
Check that you're in the libvirt group (the script should have already done this):
groups | grep libvirtExpected output: Should show "libvirt" in your groups
If NOT in the group, run:
sudo usermod -aG libvirt $USERTo verify it worked after re-login:
virsh list --all # Should work without sudoNow install the Vagrant plugin for libvirt:
vagrant plugin install vagrant-libvirtWhat this does:
- Downloads and compiles the vagrant-libvirt plugin
- This may take a few minutes as it compiles native extensions
Expected output: Progress messages, should end with "Installed the plugin 'vagrant-libvirt'"
Verify installation:
vagrant plugin listShould show something like:
vagrant-libvirt (0.x.x, global)
Download the libvirt version of the Ubuntu box:
vagrant box add bento/ubuntu-24.04 --provider=libvirtWhat this does:
- Downloads the libvirt-compatible version of bento/ubuntu-24.04
- This is a different format than the VirtualBox version (.qcow2 vs .vmdk)
- Download size: ~500MB-1GB
Expected output: Progress bar, download and import messages
Verify:
vagrant box listShould show:
bento/ubuntu-24.04 (libvirt, <version>)
bento/ubuntu-24.04 (virtualbox, <version>) # Old one, if still there
Before starting with libvirt, clean up any old VirtualBox VMs:
vagrant destroy -fWhat this does:
- Removes any existing VirtualBox VMs from previous runs
- Required because we're switching providers
Expected output: Messages about destroying VMs, or "VM not created" if already clean
Now for the moment of truth - start the cluster with libvirt:
# Optional: Set default provider to avoid typing --provider every time
export VAGRANT_DEFAULT_PROVIDER=libvirt
# Start the control plane first
vagrant up k8s-cp --provider=libvirtWhat this does:
- Creates a new VM using libvirt/KVM
- Boots Ubuntu 24.04
- Runs all the Ansible provisioning (common, binaries, containerd, control-plane, calico, untaint)
- Initializes Kubernetes
Expected output:
- VM creation messages from libvirt
- Ansible playbook execution
- Should complete successfully
Verify:
# Check vagrant status
vagrant status
# Should show: k8s-cp running (libvirt)
# Check with virsh
virsh list
# Should show the VM running
# SSH and check Kubernetes
vagrant ssh k8s-cp -c "kubectl get nodes"If the control plane works, start the workers:
vagrant up k8s-node-1 k8s-node-2 --provider=libvirtVerify full cluster:
vagrant ssh k8s-cp -c "kubectl get nodes -o wide"All nodes should show STATUS: Ready
Run the cluster verification script:
./verify-cluster.shExpected output: All checks should pass with green checkmarks
ls -la /dev/kvm
# Should show your user has access via libvirt group
# If not, check group membership and re-loginsudo systemctl status libvirtd
# Should show "active (running)"
# If not:
sudo systemctl start libvirtd# Check if box downloaded
vagrant box list | grep libvirt
# If not present, retry download
vagrant box add bento/ubuntu-24.04 --provider=libvirt# Check you have all build dependencies
dpkg -l | grep -E "(libxslt-dev|libxml2-dev|ruby-dev|build-essential)"
# If any missing, install them first
sudo apt-get install -y libxslt-dev libxml2-dev libguestfs-tools build-essential ruby-dev
# Retry plugin installation
vagrant plugin install vagrant-libvirtOld VirtualBox Provider:
node_config.vm.provider "virtualbox" do |vb|
vb.name = node[:name]
vb.memory = node[:memory]
vb.cpus = node[:cpus]
vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
vb.customize ["modifyvm", :id, "--natdnsproxy1", "on"]
endNew libvirt Provider:
node_config.vm.provider "libvirt" do |libvirt|
libvirt.cpus = node[:cpus]
libvirt.memory = node[:memory]
libvirt.cpu_mode = "host-passthrough" # Better performance
libvirt.default_prefix = "k8s_" # VM name prefix
endKey differences:
- Removed VirtualBox-specific DNS workarounds (not needed in libvirt)
- Added
cpu_mode = "host-passthrough"for better performance - Added VM name prefix for easier identification in virsh
If anything goes wrong, you can rollback:
# Destroy libvirt VMs
vagrant destroy -f
# Restore original Vagrantfile
cp Vagrantfile.virtualbox.backup Vagrantfile
# Switch back to VirtualBox modules
./switch-to-virtualbox.sh
# Start with VirtualBox
vagrant up --provider=virtualboxOnce everything is working:
-
Optional: Remove old VirtualBox boxes to save space:
vagrant box remove bento/ubuntu-24.04 --provider=virtualbox
-
Optional: Set default provider permanently in your shell profile:
echo 'export VAGRANT_DEFAULT_PROVIDER=libvirt' >> ~/.bashrc source ~/.bashrc
-
Optional: Update other documentation files (README.md, CLAUDE.md, etc.)
You're almost there! The configuration is ready. Just run the commands above in order and you'll be running on libvirt/KVM. The hard work is done - now it's just execution.
Estimated time: 20-30 minutes (mostly waiting for downloads and VM boot)
Let me know once you've completed the steps and I can help with verification or troubleshooting!