Building an Ubuntu Vagrant box

Within the VM run this to 'pre-configure' it, ready for booting in Vagrant

1wget --no-check-certificate \\
2    https://raw.githubusercontent.com/hashicorp/vagrant/main/keys/vagrant.pub \\
3    -O /home/vagrant/.ssh/authorized_keys
4
5sudo rm -f /etc/machine-id
6sudo dbus-uuidgen --ensure=/etc/machine-id
7sudo rm /var/lib/dbus/machine-id
8sudo dbus-uuidgen --ensure
9reboot

You can also try this parameter in the Ubuntu netplan configuration file:

dhcp4: yes dhcp-identifier: mac

sudo qemu-img convert -f qcow2 -O qcow2 /nvmedata2/test1_default.img ~/.vagrant.d/boxes/betterubuntu-VAGRANTSLASH-1804-1/0/libvirt/box.img

File contents of ~/.vagrant.d/boxes/betterubuntu-VAGRANTSLASH-1804-1/0/libvirt/Vagrantfile

 1# The contents below were provided by the Packer Vagrant post-processor
 2
 3Vagrant.configure("2") do |config|
 4config.vm.provider :libvirt do |libvirt|
 5libvirt.driver = "kvm"
 6end
 7end
 8
 9
10# The contents below (if any) are custom contents provided by the
11# Packer template during image build.
12# -*- mode: ruby -*-
13# vi: set ft=ruby :
14
15Vagrant.configure(2) do |config|
16
17config.vm.boot_timeout = 1800
18config.vm.synced_folder ".", "/vagrant", disabled: true
19
20config.vm.box_check_update = true
21
22# config.vm.post_up_message = ""
23config.vm.boot_timeout = 1800
24# config.vm.box_download_checksum = true
25config.vm.boot_timeout = 1800
26# config.vm.box_download_checksum_type = "sha256"
27
28# config.vm.provision "shell", run: "always", inline: <<-SHELL
29# SHELL
30
31# Adding a second CPU and increasing the RAM to 2048MB will speed
32# things up considerably should you decide to do anythinc with this box.
33config.vm.provider :hyperv do |v, override|
34v.maxmemory = 2048
35v.memory = 2048
36v.cpus = 2
37end
38
39config.vm.provider :libvirt do |v, override|
40v.disk_bus = "virtio"
41v.driver = "kvm"
42v.video_vram = 256
43v.memory = 2048
44v.cpus = 2
45end
46
47config.vm.provider :parallels do |v, override|
48v.customize ["set", :id, "--on-window-close", "keep-running"]
49v.customize ["set", :id, "--startup-view", "headless"]
50v.customize ["set", :id, "--memsize", "2048"]
51v.customize ["set", :id, "--cpus", "2"]
52end
53
54config.vm.provider :virtualbox do |v, override|
55v.customize ["modifyvm", :id, "--memory", 2048]
56v.customize ["modifyvm", :id, "--vram", 256]
57v.customize ["modifyvm", :id, "--cpus", 2]
58v.gui = false
59end
60
61["vmware_fusion", "vmware_workstation", "vmware_desktop"].each do |provider|
62config.vm.provider provider do |v, override|
63v.whitelist_verified = true
64v.gui = false
65v.vmx["cpuid.coresPerSocket"] = "1"
66v.vmx["memsize"] = "2048"
67v.vmx["numvcpus"] = "2"
68end
69end
70
71end

File contents of ~/.vagrant.d/boxes/betterubuntu-VAGRANTSLASH-1804-1/0/libvirt/metadata.json

1{"format":"qcow2","provider":"libvirt","virtual_size":128}