-
-
Save beauwilliams/69eabc42e540a309f53d55c4b8e6ffe3 to your computer and use it in GitHub Desktop.
brew install vagrant qemu | |
#Due to dependency errors, we must install vbguest first.. | |
vagrant plugin install vagrant-vbguest | |
vagrant plugin install vagrant-qemu | |
#cd to working dir you like to keep your vagrant files | |
cd ~/VM-and-containers/VagrantMachines/M1-vagrantfiles/ubuntu18-generic-64/ | |
#Create a vagrant file | |
$EDITOR Vagrantfile | |
#Paste into the vagrantfile the recipe below used to launch the VM | |
#Setting qemu as hypervisor and importing a ubuntu image with support for libvrt | |
Vagrant.configure("2") do |config| | |
config.vm.box = "generic/ubuntu1804" | |
config.vm.provider "qemu" do |qe| | |
qe.arch = "x86_64" | |
qe.machine = "q35" | |
qe.cpu = "max" | |
qe.net_device = "virtio-net-pci" | |
end | |
end | |
#Save ./Vagrantfile | |
#Launch the VM, note, you can specify provider if using a Vagrantfile with mulltiple providers with vagrant up --provider qemu | |
vagrant up | |
#Get a shell inside the VM | |
vagrant ssh | |
#Check your VM is running x86 | |
vagrant@ubuntu-1204:~$ uname -a | |
Linux ubuntu1804.localdomain 4.15.0-193-generic #204-Ubuntu SMP Fri Aug 26 19:20:21 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux | |
#Success! | |
#FAQ | |
#ERROR | |
#If you face this error after running vagrant up | |
Vagrant SMB synced folders require the account password to be stored | |
in an NT compatible format. Please update your sharing settings to | |
enable a Windows compatible password and try again. | |
#SOLUTION | |
# Visit System Preferences -> Sharing -> File Sharing -> Options | |
# Tick to enable file sharing, see here -> https://i.ibb.co/F4ZwF4V/Screen-Shot-2022-09-29-at-10-49-21-am.png | |
#ERROR | |
#If you face this error after running vagrant up | |
default: SSH username: vagrant | |
default: SSH auth method: private key | |
default: Warning: Connection reset. Retrying... | |
default: Warning: Remote connection disconnect. Retrying... | |
#SOLUTION | |
#You can hit ctrl+c here, and attempt to run vagrant ssh and it should work despite the apparent error. | |
I received the first error, the one about the password being in an NT-compatible format. I did exactly as was told, and matched the screenshot. Still receiving the error. I can't get past it no matter what I do. Is there an alternate way to troubleshoot that error? I need this up by TOMORROW, or I won't be ready for the biggest interview of my life, they sprung this on me.
How's your interview @jairenee
Vagrant cannot forward the specified ports on this VM, since they
would collide with some other application that is already listening
on these ports. The forwarded port to 50022 is already in use
on the host machine.
To fix this, modify your current project's Vagrantfile to use another
port. Example, where '1234' would be replaced by a unique host port:
config.vm.network :forwarded_port, guest: 22, host: 1234
Sometimes, Vagrant will attempt to auto-correct this for you. In this
case, Vagrant was unable to. This is usually because the guest machine
is in a state which doesn't allow modifying port forwarding. You could
try 'vagrant reload' (equivalent of running a halt followed by an up)
so vagrant can attempt to auto-correct this upon booting. Be warned
that any unsaved work might be lost.
Nah every time it tries to that port
@electropolis I had this, you can try vagrant global-status
and then vagrant destroy 7f0829b
or whatever ID's you find, but it didn't work for me, there's a bunch of stuff in ~/.vagrant.d/boxes
and some of those have includes that pull from other files, the port is likely being reserved from these files.
If you're precious about what's in ~/.vargant.d
then you may need to go through them, try to find what it is that's blocking that port from being used.
I'm just messing with building things so I just blew the whole directory away and it worked for me.
Vagrant cannot forward the specified ports on this VM, since they would collide with some other application that is already listening on these ports. The forwarded port to 50022 is already in use on the host machine. To fix this, modify your current project's Vagrantfile to use another port. Example, where '1234' would be replaced by a unique host port: config.vm.network :forwarded_port, guest: 22, host: 1234 Sometimes, Vagrant will attempt to auto-correct this for you. In this case, Vagrant was unable to. This is usually because the guest machine is in a state which doesn't allow modifying port forwarding. You could try 'vagrant reload' (equivalent of running a halt followed by an up) so vagrant can attempt to auto-correct this upon booting. Be warned that any unsaved work might be lost.
Nah every time it tries to that port
Add qe.ssh_port
to your provider conifg.
eg:
config.vm.provider "qemu" do |qe|
qe.ssh_port = "54321"
qe.arch = "x86_64"
qe.machine = "q35"
qe.cpu = "max"
qe.net_device = "virtio-net-pci"
end
Vagrant cannot forward the specified ports on this VM, since they would collide with some other application that is already listening on these ports. The forwarded port to 50022 is already in use on the host machine. To fix this, modify your current project's Vagrantfile to use another port. Example, where '1234' would be replaced by a unique host port: config.vm.network :forwarded_port, guest: 22, host: 1234 Sometimes, Vagrant will attempt to auto-correct this for you. In this case, Vagrant was unable to. This is usually because the guest machine is in a state which doesn't allow modifying port forwarding. You could try 'vagrant reload' (equivalent of running a halt followed by an up) so vagrant can attempt to auto-correct this upon booting. Be warned that any unsaved work might be lost.
Nah every time it tries to that port
Add
qe.ssh_port
to your provider conifg.eg:
config.vm.provider "qemu" do |qe| qe.ssh_port = "54321" qe.arch = "x86_64" qe.machine = "q35" qe.cpu = "max" qe.net_device = "virtio-net-pci" end
That doesn't seem to help at all. Whatever port I set it's the same error just with a different port.
I ended up Quiting M1 and going back to windows
I was facing the problem on a M3 Mac. I was trying vagrant-libvirt
originally, and some web search led me to this document.
Trying vagrant-qemu
got me a step further but vagrant up
failed with the network port error.
the qe.ssh_port
hint by @szilvesztercsab now seems to have solved it for me.
Strangely though, after some time of progressing, vagrant up
hung indefinitely until I interrupted it with Control-C
.
After that the vm was reported in running state by vagrant status
. And vagrant ssh
did work! ๐
So I do seem to finally have a working setup now. ๐ Thanks a lot, @beauwilliams and @szilvesztercsab !
This worked for me :)
Is there any way to add additional disks to box?
I tried vm.disk but it doesn't work, I could find references for virtulabox but nothing specific for qemu
This works for me too, thanks.
Does it possible to find any doc for this or any other qemu attributes?
qe.arch = "x86_64"
qe.machine = "q35"
qe.cpu = "max"
qe.net_device = "virtio-net-pci"
Thanks for this. I have UTM installed, can the
vagrant up
spin up a virtual machine inUTM