Skip to content

Instantly share code, notes, and snippets.

@Jeket
Forked from niw/README.en.md
Created April 7, 2021 09:45
Show Gist options
  • Save Jeket/e40073e8e3ad9fee8e28ec5c25c7c0ee to your computer and use it in GitHub Desktop.
Save Jeket/e40073e8e3ad9fee8e28ec5c25c7c0ee to your computer and use it in GitHub Desktop.
How to run Windows 10 on ARM or Ubuntu for ARM64 in QEMU on Apple Silicon Mac

ARM 版 Windows 10 を Hypervisor.framework のパッチをあてた QEMU を使って Apple Silicon な Mac で動かす

ARM 版 Windows 10 を Apple Silicon な Mac で動かす簡単な方法です。

メモ: 2020年11月30日現時点での方法で、今後おおきく改善されていくと思います(だといいな。)

手順

  1. Xcode を App Store で、あるいは Command Line Tools を Apple Silicon な Mac にインストール

    xcode-select --install
    
  2. MacPorts で QEMU の依存ライブラリをインストール

    https://www.macports.org/install.php

    sudo port install ninja pkgconfig texinfo libtool glib2 libpixman
    

    sudo とか使いたくない場合は、/opt/local$USER:staff で作って、MacPorts をソースコードからインストールすれば可能です。

  3. QEMU のソースコードをとってくる

    git clone https://git.qemu.org/git/qemu.git
    
  4. ローカルブランチを作って、@_AlexGraf氏がつくった Hypervisor.framework のパッチをあてる

    cd qemu
    git checkout 944fdc5 -b wip/hvf # これは現時点での `origin/master` のコミット。
    curl https://patchwork.kernel.org/series/392975/mbox/|git am
    
  5. QEMU をビルドする

    mkdir build
    cd build
    ../configure --target-list=aarch64-softmmu --enable-cocoa
    make -j
    
    • x86_64 な Homebrew などを使っている場合は問題がおこるので、PATH などを書き換えるなどして無効にしておくこと。
    • Intel な Mac と比べて、めっちゃ速い。
  6. Windows 10 on ARM Insider Preview をダウンロードする

    https://www.microsoft.com/en-us/software-download/windowsinsiderpreviewARM64

  7. QEMU 用の xHCI 無効化済み EDK II OVMF EFI イメージをダウンロードする。

    https://gist.github.com/niw/4f1f9bb572f40d406866f23b3127919b/raw/d3dc861d1c8578f996bbfcd0e014586a2eb52d8c/QEMU_EFI-8c552e8.tar.gz

    ソースコードからビルドする場合は以下を参照のこと。

  8. Windows 10 を起動する

    ./qemu-system-aarch64 \
      -monitor stdio \
      -M virt,highmem=off \
      -accel hvf \
      -cpu cortex-a72 \
      -smp 4 \
      -m 4096 \
      -bios ~/Downloads/QEMU_EFI.fd \
      -device ramfb \
      -device qemu-xhci \
      -device usb-kbd \
      -device usb-mouse \
      -nic user,model=virtio \
      -drive file=~/Downloads/Windows10_InsiderPreview_Client_ARM64_en-us_20231.VHDX,if=none,id=boot,cache=writethrough \
      -device nvme,drive=boot,serial=boot
    

    イメージへのパスなどは適宜修正してください。

インターネットに接続する

VirtIO NIC は標準では有効にならないので、デバイスドライバを入れる必要がある。

  1. VirtIO デバイスドライバの ISO を Fedora Project からダウンロード。

    https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/stable-virtio/virtio-win.iso

  2. デバイスドライバの ISO をマウント

    qemu-system-aarch64 のオプションに以下を追加する。

    -drive file=~/Downloads/virtio-win-0.1.190.iso,media=cdrom,if=none,id=drivers \
    -device usb-storage,drive=drivers
    

    イメージへのパスなどは適宜修正してください。

  3. デバイスドライバの署名検証を無効にする

    Windows を起動して Windows スタートボタン を右クリック、Command Prompt (Admin) を選択。

    BCDEdit を使ってテスト署名されたデバイスドライバを有効にする。

    Bcdedit.exe -set TESTSIGNING ON
    

    このあと Windows を再起動すること。

    詳細はこちらを参照のこと。

  4. デバイスドライバのインストール

    Windows が再度起動したら Windows スタートボタン を右クリック、Device Manager を選択。

    Device Manager のウィンドウで、View メニューの Devices by Connection を選択。

    デバイスのツリーから, ACPU ARM64-based PC, Microsoft ACPI-Compliant System, PCI Express Root Complex と選択してその中にある Unknown device を探す。 (Unknown device はデバイスのツリーに沢山あるけれど、PCI Express Root Complexの下にあるのが、VirtIO NIC。)

    該当の Unknown device を右クリックして、Update Drivers を選択、Browse my computer for drivers を選んで、D:\NetKVM\w10\ARM64 を指定。

    Next をクリックして Red Hat VertIO Ethernet Adapter をインストール。

EDK2 の OVMF EFI イメージをビルドする

OVMF EFI イメージをソースコードから作る場合、とりあえず簡単にビルドするには、まず VMWare Fusion とか、VirtualBox とかを Intel Mac (そう、Intel Mac が必要)にインストールして、Ubuntu などの Linux が必要になります。

  1. EDK II のソースコードを取ってくる。

    git clone https://github.com/tianocore/edk2.git
    cd edk2
    git checkout edk2-stable202008 # stable ってタグされてるやつがいい
    git submodule update --init --recursive
    
  2. Hypervisor.framework パッチの制限で xHCI を無効にする必要がある。

    /ArmVirtPkg/ArmVirtQemu.dsc/ArmVirtPkg/ArmVirtQemuFvMain.fdf.inc にある MdeModulePkg/Bus/Pci/XhciDxe/XhciDxe.inf の行をコメントアウト。

  3. で、ビルド。

    apt install install iasl python3 python3-distutils uuid-dev gcc-aarch64-linux-gnu
    source edksetup.sh
    make -C BaseTools
    env GCC5_AARCH64_PREFIX=aarch64-linux-gnu- build -a AARCH64 -t GCC5 -p ArmVirtPkg/ArmVirtQemu.dsc
    

    Build/ArmVirtQemu-AARCH64/DEBUG_GCC5/FVQEMU_EFI.fd とかができるはず。

メモ

  • CPU 使用率が指定したコア数 × 100% で張り付くのは Hypervisor.framework パッチの仕様です。 Patch 2 でなおった
  • 同様の手順で Ubuntu Server for ARM も動きます。こっちはより安定している。 https://ubuntu.com/download/server/arm
  • 8GB の Apple Silicon Mac だとメモリが厳しいかもしれない。4096 から減らしても問題ない。

How to run Windows 10 on ARM in QEMU with Hypervisor.framework patches on Apple Silicon Mac

Here is easy steps to try Windows 10 on ARM on your Apple Silicon Mac. Enjoy!

NOTE: that this is current, 11/30/2020 state. It will be improved a lot in upcoming a few months... (I hope.)

Steps

  1. Install Xcode from App Store or install Command Line Tools on your Mac running on Apple Silicon.

    xcode-select --install
    
  2. Install MacPorts and QEMU dependencies.

    https://www.macports.org/install.php

    sudo port install ninja pkgconfig texinfo libtool glib2 libpixman
    

    Don’t want to use sudo with MacPorts? Create /opt/local as $USER:staff and install MacPorts from the source code.

  3. Clone QEMU source code.

    git clone https://git.qemu.org/git/qemu.git
    
  4. Create a local branch then apply Hypervisor.framework patches that @_AlexGraf made.

    cd qemu
    git checkout 944fdc5 -b wip/hvf # This is current `origin/master` when this document is written.
    curl https://patchwork.kernel.org/series/392975/mbox/|git am
    
  5. Build QEMU

    mkdir build
    cd build
    ../configure --target-list=aarch64-softmmu --enable-cocoa
    make -j
    
    • Please disable any x86_64 tools such as the one installed by Homebrew, please rewrite PATH etc to disable them.
    • This is surprisingly fast on Apple Silicon Mac, compare to Intel Mac...
  6. Download Windows 10 on ARM Insider Preview

    https://www.microsoft.com/en-us/software-download/windowsinsiderpreviewARM64

  7. Download prebild, xHCI disabled version of EDK II OVMF EFI image for QEMU.

    https://gist.github.com/niw/4f1f9bb572f40d406866f23b3127919b/raw/d3dc861d1c8578f996bbfcd0e014586a2eb52d8c/QEMU_EFI-8c552e8.tar.gz

    To build it from the source code, see the following section.

  8. Run Windows 10

    ./qemu-system-aarch64 \
      -monitor stdio \
      -M virt,highmem=off \
      -accel hvf \
      -cpu cortex-a72 \
      -smp 4 \
      -m 4096 \
      -bios ~/Downloads/QEMU_EFI.fd \
      -device ramfb \
      -device qemu-xhci \
      -device usb-kbd \
      -device usb-mouse \
      -nic user,model=virtio \
      -drive file=~/Downloads/Windows10_InsiderPreview_Client_ARM64_en-us_20231.VHDX,if=none,id=boot,cache=writethrough \
      -device nvme,drive=boot,serial=boot
    

    Please modify each path to the image depends on your environment.

Enable the internet

VirtIO NIC is not enabled by default. To make it works, you need to install device driver.

  1. Download VirtIO device drivers ISO from Fedora Project.

    https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/stable-virtio/virtio-win.iso

  2. Mount device drivers ISO

    Add next options to qemu-system-aarch64.

    -drive file=~/Downloads/virtio-win-0.1.190.iso,media=cdrom,if=none,id=drivers \
    -device usb-storage,drive=drivers
    

    Please modify each path to the image depends on your environment.

  3. Disable device driver signature enforcement

    Boot Windows, then right click Windows Start button, then select Command Prompt (Admin).

    Use BCDEdit to enable test-signed device drivers.

    Bcdedit.exe -set TESTSIGNING ON
    

    Then reboot Windows.

    See here for the details.

  4. Install driver

    Once Windows booted again, then right click Windows Start button, then select Device Manager.

    In Device Manager, select View menu then Devices by Connection.

    Navigate in the device tree, select ACPU ARM64-based PC, Microsoft ACPI-Compliant System, PCI Express Root Complex, then you will see one Unknown device there. (There are many Unknown device in tree but the one under PCI Express Root Complex is the VirtIO NIC.)

    Right click Unknown device then select Update Drivers, then Browse my computer for drivers, then select D:\NetKVM\w10\ARM64.

    Click Next to install Red Hat VertIO Ethernet Adapter.

Build EDK2 OVMF EFI Image from the source code

To build this from the source code, you may need to setup Linux environment. Install VMWare Fusion or VirtualBox on your Intel Mac (Yes, Intel Mac.) and install Ubuntu.

  1. Checkout EDK II source code.

    git clone https://github.com/tianocore/edk2.git
    cd edk2
    git checkout edk2-stable202008 # or any stable tagged commit
    git submodule update --init --recursive
    
  2. Then you need to disable xHCI due to current Hypervisor.framework patch limitation.

    Comment out MdeModulePkg/Bus/Pci/XhciDxe/XhciDxe.inf in /ArmVirtPkg/ArmVirtQemu.dsc and /ArmVirtPkg/ArmVirtQemuFvMain.fdf.inc.

  3. Then, build it.

    apt install install iasl python3 python3-distutils uuid-dev gcc-aarch64-linux-gnu
    source edksetup.sh
    make -C BaseTools
    env GCC5_AARCH64_PREFIX=aarch64-linux-gnu- build -a AARCH64 -t GCC5 -p ArmVirtPkg/ArmVirtQemu.dsc
    

    Then, you will get QEMU_EFI.fd in Build/ArmVirtQemu-AARCH64/DEBUG_GCC5/FV.

Note

  • It is Hypervisor.framework patch’s known issue that CPU usage keeps about number of cores x 100%. It's fixed now.
  • You can run Ubuntu Server for ARM in same way, which is stabler than that. https://ubuntu.com/download/server/arm
  • You may need to reduce memory from 4096, if you’re using 8GB Apple Silicon Mac.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment