Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: Is this compatible with m1 MacOS? #84

Open
aelbore opened this issue May 29, 2022 · 4 comments
Open

Question: Is this compatible with m1 MacOS? #84

aelbore opened this issue May 29, 2022 · 4 comments

Comments

@aelbore
Copy link

aelbore commented May 29, 2022

No description provided.

@jaraco
Copy link
Contributor

jaraco commented Jun 10, 2022

I believe it is not. The procedures herein rely on virtualbox, which doesn't support Apple Silicon. It's possible it could be made to work with VMWare or Parallels or UTM, which can run Windows VMs, but I wouldn't know how to do that.

@jaraco
Copy link
Contributor

jaraco commented Jun 10, 2022

Today I learned that UTM is backed by qemu, which has a vagrant provider. I tried spinning up the box using qemu, but without success (reasonably, because the images haven't been built):

$ brew install qemu vagrant
$ vagrant plugin install vagrant-qemu
windows-docker-machine main $ vagrant up --provider qemu 2019-box
Bringing machine '2019-box' up with 'qemu' provider...
==> 2019-box: Box 'StefanScherer/windows_2019_docker' could not be found. Attempting to find and install...
    2019-box: Box Provider: libvirt
    2019-box: Box Version: >= 0
==> 2019-box: Loading metadata for box 'StefanScherer/windows_2019_docker'
    2019-box: URL: https://vagrantcloud.com/StefanScherer/windows_2019_docker
The box you're attempting to add doesn't support the provider
you requested. Please find an alternate box or use an alternate
provider. Double-check your requested provider to verify you didn't
simply misspell it.

If you're adding a box from HashiCorp's Vagrant Cloud, make sure the box is
released.

Name: StefanScherer/windows_2019_docker
Address: https://vagrantcloud.com/StefanScherer/windows_2019_docker
Requested provider: ["libvirt"]

Maybe someone could build the box for the provider?

@libc
Copy link

libc commented Sep 5, 2022

@jaraco I sort-of made it work, it's not as easy as just building the box.

For packer-windows you need the following changes:

diff --git a/windows_2019_docker.json b/windows_2019_docker.json
index 921e1e0..e6d89f0 100644
--- a/windows_2019_docker.json
+++ b/windows_2019_docker.json
@@ -1,7 +1,6 @@
 {
   "builders": [
     {
-      "accelerator": "kvm",
       "boot_wait": "0s",
       "communicator": "winrm",
       "cpus": 2,
@@ -15,7 +14,8 @@
         "./scripts/microsoft-updates.bat",
         "./scripts/win-updates.ps1"
       ],
-      "headless": true,
+      "headless": false,
+      "display": "cocoa",
       "iso_checksum": "{{user `iso_checksum`}}",
       "iso_url": "{{user `iso_url`}}",
       "memory": "{{user `memory`}}",
@@ -25,6 +25,10 @@
           "-drive",
           "file=windows_2019_docker-qemu/{{ .Name }},if=virtio,cache=writeback,discard=ignore,format=qcow2,index=1"
         ],
+        [
+          "-drive",
+          "file=windows.iso,media=cdrom,index=2"
+        ],
         [
           "-drive",
           "file={{ user `virtio_win_iso` }},media=cdrom,index=3"
  • kvm is not supported on m1 qemu (for obvious reasons),
  • headless and display turns of headless mode for packer. Without them it's really hard to tell if it's working, the build took 12 hours on my machine, so I highly recommend enabling it
  • windows.iso is a copy of iso_url downloaded locally. Specifying any drives overrides default config, and machine won't boot (no way to tell this in headless mode), so windows iso needs to be here specifically. You can see details here Windows 10: Add VirtualBox, KVM CI packer-windows#270 (comment)

Then vagrant box add windows_2019_docker windows_2019_docker_libvirt.box will add the box.

I had to change vagrant-qemu code. These lines https://github.com/ppggff/vagrant-qemu/blob/36eb93afc951650c2bc801ec989f8c221f36f077/lib/vagrant-qemu/action/start_instance.rb#L43-L46 should be

            host_ip = ""
            # host_ip = "#{options[:host_ip]}:" if options[:host_ip]
            guest_ip = ""
            # guest_ip = "#{options[:guest_ip]}:" if options[:guest_ip]
            result.push("#{options[:protocol]}:#{host_ip}:#{options[:host]}-#{guest_ip}:#{options[:guest]}")

my version of qemu wasn't happy about host in port forwarding rules.

Vagrant file changes are:

diff --git a/Vagrantfile b/Vagrantfile
index 2a711bf..cd88469 100644
--- a/Vagrantfile
+++ b/Vagrantfile
@@ -8,7 +8,8 @@ Vagrant.configure("2") do |config|

   config.vm.synced_folder ".", "/vagrant", disabled: true
   home = ENV['HOME'].gsub('\\', '/')
-  config.vm.synced_folder home, home
+  config.vm.synced_folder home, home, type: "smb", smb_host: "10.0.2.2"
+  config.vm.network "forwarded_port", guest: 2376, host: 2376

   config.vm.define "2016", autostart: false do |cfg|
     cfg.vm.box     = "windows_2016_docker"
@@ -107,6 +108,18 @@ Vagrant.configure("2") do |config|
     v.customize ["modifyvm", :id, "--paravirtprovider", "hyperv"]
   end

+  config.vm.provider "qemu" do |v, override|
+    v.gui = false
+    v.memory = 2048
+    v.cpus = 2
+    v.linked_clone = true
+    v.arch = "x86_64"
+    v.machine = "pc"
+    v.cpu = "max"
+    v.net_device = "virtio-net-pci"
+    v.qemu_dir = "/nix/store/azrccc44b425xh1v5bk9sxi2hf15v8mj-qemu-7.0.0/share/qemu/"
+  end
+
   config.vm.provider "hyperv" do |v|
     v.cpus = 2
     v.maxmemory = 2048
  • synced_folder needs smb_host specified because ping is not implement somehow, as described in the vagrant-qemu's README
  • forwarded_port I added to easily open docker's tcp port. This wouldn't get tricky if you want to run more than one box, but also can be avoided if network is properly setup. But this was the easiest path forward for me
  • qemu_dir is set to /opt/homebrew/share/qemu by default, if you're using aarch64 homebrew, you can probably keep the default. I had to change it to my installation

I also changed .ps1 script to set machine ip to 127.0.0.1 (forwarded port):

diff --git a/scripts/create-machine.ps1 b/scripts/create-machine.ps1
index 174cacb..ab60c31 100644
--- a/scripts/create-machine.ps1
+++ b/scripts/create-machine.ps1
@@ -9,13 +9,14 @@ if (!(Test-Path $env:USERPROFILE\.docker)) {
 $ipAddresses = ((Get-NetIPAddress -AddressFamily IPv4).IPAddress) -Join ','

 if (!$machineIp) {
-  $machineIp=(Get-NetIPAddress -AddressFamily IPv4 `
-    | Where-Object -FilterScript { `
-      ( ! ($_.InterfaceAlias).StartsWith("vEthernet (") ) `
-      -And $_.IPAddress -Ne "127.0.0.1" `
-      -And $_.IPAddress -Ne "10.0.2.15" `
-      -And !($_.IPAddress.StartsWith("169.254.")) `
-    }).IPAddress
+  $machineIp="127.0.0.1"
+  # $machineIp=(Get-NetIPAddress -AddressFamily IPv4 `
+  #   | Where-Object -FilterScript { `
+  #     ( ! ($_.InterfaceAlias).StartsWith("vEthernet (") ) `
+  #     -And $_.IPAddress -Ne "127.0.0.1" `
+  #     -And $_.IPAddress -Ne "10.0.2.15" `
+  #     -And !($_.IPAddress.StartsWith("169.254.")) `
+  #   }).IPAddress
 } else {
   $ipAddresses = "$ipAddresses,$machineIp"
 }

I was able to run docker after these changes:

windows-docker-machine]$ docker context ls
NAME                TYPE                DESCRIPTION                               DOCKER ENDPOINT                                 KUBERNETES ENDPOINT   ORCHESTRATOR
2019                moby                2019 windows-docker-machine               tcp://127.0.0.1:2376

windows-docker-machine]$ docker --context 2019 run --rm -it mcr.microsoft.com/windows:1809
Microsoft Windows [Version 10.0.17763.3287]
(c) 2018 Microsoft Corporation. All rights reserved.

C:\>dir
 Volume in drive C has no label.
 Volume Serial Number is 4607-C090

 Directory of C:\

04/21/2022  06:12 PM             5,510 License.txt

I hope that helps.

@Antonytm
Copy link

@libc

And how is the performance of this setup?
Is it possible to work?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants