Last active
June 16, 2024 20:50
-
-
Save beauwilliams/69eabc42e540a309f53d55c4b8e6ffe3 to your computer and use it in GitHub Desktop.
Run x86 VM's on Mac M1 arm using vagrant with qemu hypervisor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@electropolis I had this, you can try
vagrant global-status
and thenvagrant 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.