Skip to content

Instantly share code, notes, and snippets.

@x86-39
Last active October 30, 2022 21:11
Show Gist options
  • Save x86-39/f4a2016e8cc3f5487167cf9f513d6c93 to your computer and use it in GitHub Desktop.
Save x86-39/f4a2016e8cc3f5487167cf9f513d6c93 to your computer and use it in GitHub Desktop.
Fedora in Vagrant with GUI

Steps

Replace X with major version in this guide
  1. Download Fedora DVD Image (Tested with 36 KDE)
  2. Create a QEMU/KVM libvirt VM (I use virt-manager) Attach this boot image as boot disk. I used 20GB as the disk size. Name this VM fedoraX
  3. Set installation destination to the local drive
  4. configure networking so that you have internet access (Should work out of the box with DHCP)
  5. Create a user "vagrant" with password "vagrant"
  6. Select minimal installation
  7. Proceed with installation
  8. After installation is complete, reboot
  9. Log in as vagrant user and elevate to root sudo su
  10. Install necessary packages yum install -y openssh wget gcc
  11. Enable SSH server systemctl enable --now sshd
  12. Configure sudoers visudo Add a line vagrant ALL=(ALL) NOPASSWD: ALL
  13. Shut down the VM
  14. Create a directory for the box and navigate to it
    mkdir fedoraX && cd fedoraX
  15. Compress the disk image to this directory sudo qemu-img convert -c -O qcow2 /var/lib/libvirt/images/rhelX.Y.qcow2 box.img
  16. Make your user owner of this file sudo chown USER:USER box.img
Replace USER with your username
  1. Create a file metadata.json with the content
{
  "provider"     : "libvirt",
  "format"       : "qcow2",
  "virtual_size" : 20
}
  1. Create a file Vagrantfile with the content
Vagrant.configure("2") do |config|
  config.ssh.username = "vagrant"
  config.ssh.password = "vagrant"
  config.vm.provider :libvirt do |libvirt|
    libvirt.driver = "kvm"
    libvirt.host = 'localhost'
    libvirt.uri = 'qemu:///system'
  end
  config.vm.define "new" do |custombox|
    custombox.vm.box = "fedoraX"       # REPLACE THIS!!!
    custombox.vm.provider :libvirt do |virt|
      virt.memory = 2048
      virt.cpus = 2
    end
  end
end
  1. Create Vagrant box file tar cvzf fedoraX.box ./metadata.json ./Vagrantfile ./box.img
  2. Import box into Vagrant vagrant box add --name fedoraX fedoraX.box

You can now use the box with

  host.vm.box = "fedoraX"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment