27 December 2020

Intel x86_64 Windows (not Arm Windows) successfully runs on Apple Silicon M1 MacBook Air - how to

Some articles started to report about Arm Windows running on Apple Silicon Mac, but Arm Windows is not major in industry yet.

I thought a different story.

The macOS itself provides Virtualization Framework to execute Linux virtual machine guest OS easily on macOS, and it is the same on Apple Silicon
Therefore Apple Silicon Mac can execute Arm Linux guest OS.
Linux OS provides QEMU virtualization that can use both KVM (hardware-based kernel virtualization) and software-based CPU emulation.
It means Intel Linux can execute Intel Linux and Arm Linux guest, and Arm Linux can execute Arm/Intel guest.
QEMU is flexible enough to execute Windows guest, so Arm Linux will be able to execute Intel Windows guest.

Following is how to execute Intel x86 Windows on Apple Silicon M1 Mac.

  1. Download a pre-build Arm Ubuntu image and virtualization app for Apple Silicon Mac.
    One of the examples is @mibosshard work at https://twitter.com/mibosshard/status/1331558536728506368
    It is a package of Arm Ubuntu Linux and SimpleVM tool.
    Download it, and extract.
  2. I was not able to customize/build the code of SimpleVM, and found other virtualization app vftool at https://github.com/evansm7/vftool
    Download the source code.
  3. Pre-build Ubuntu does not have enough disk space, so I changed the vftool code as that CD drive will be assumed to disk drive (replace readOnly:true to false), and build.
    Open the vftool project with Xcode, locate readOnly and replace "true" with "false", and do build.
  4. Xcode places the built app at a temporary path. So, I find it by [Show in Finder].
  5. Open macOS terminal and create an empty HDD image by command:
    % cd <<to where Ubuntu_SimpleVM was extracted>>
    % dd if=/dev/zero of=ext4fs-data03.img bs=20g count=0 seek=6

  6. Execute the guest OS by:
    % /Users/xxx/Library/Developer/Xcode/xxx/Products/Debug/vftool -k vmlinuz -i initrd -a "console=hvc0 root=dev/vda" -d image  -m 9000 -c ext4fs-data03.img -net -p 8
  7. Open another terminal and connect to the guest by:
    % screen /dev/ttys001
  8. Ubuntu Linux boot messages and Login prompt will be appeared.
    The root password is described in README.txt of Ubutu_SimpleVM.
    Login as root.
  9. Initialize the filesystem (we will store Windows image at /Data) and mount it by:
    # ls -l /dev/vd*
    # mkfs.ext4 /dev/vdb
    # mkdir /Data
    # mount /dev/sdb /Data
  10. Install QEMU by:
    # apt-get install qemu binfmt-support qemu-user-static docker.io
  11. Install qemu x86_64 from https://github.com/dbhi/qus and https://hub.docker.com/r/aptman/qus/ by:
    # docker run --rm --privileged aptman/qus -s -- -p x86_64
  12. Download a pre-build Intel Windows 10 image from https://app.vagrantup.com/peru/boxes/windows-10-enterprise-x64-eval by (will download 7.5GB, and the password is described at the site):
    # cd /Data
    # wget https://app.vagrantup.com/peru/boxes/windows-10-enterprise-x64-eval/versions/20201203.01/providers/libvirt.box
  13. Extract disk image by (results 15GB):
    # mv libvirt.box w10-box.tar.gz
    # tar xzvf w10-box.tar.gz box.img
    # mv box.img w10-box.img
  14. Before start the guest, check the Ubuntu IP address of emp0s1 interface (will be used for vnc connection) by:
    # ip a
  15. Then, start the Intel Windows by:
    # qemu-system-x86_64 w10-box.img -m size=6000 -vnc :0,password  -monitor stdio -usb -device usb-tablet -accel tcg,thread=multi  -cpu qemu64 -smp 8,maxcpus=8,sockets=2
  16. A prompt (qemu) will be appeared, then set your favorite password for vnc by:
    (qemu) change vnc password
  17. Return to macOS Finder and [Go] => [Connect to Server...], and specify following as Server Address and enter your password:
    vnc://192.168.64.xxx
  18. Finally, QEMU window will be appeared to display the progress of the Intel Windows boot.
    It takes about 30 minutes for the first time and consumes 100% of 8 cores even on Apple M1, because this is software emulation.

This is just an experimental work as beginning.
I will post the performance comparison later.
If you have interest, leave your comment or say Like at my twitter post.

[2021-01-17] UTM app is easy way to execute Arm and Intel guest operating system, so I wrote a post about it.