在macos使用qemu安裝windows

安裝Qemu

brew install qemu

建立硬碟

qemu-img create -f raw ~/qemu/disk.img 20G
qemu-img info ~/qemu/disk.img

修正Qemu錯誤

原生安裝好的qemu執行虛擬機時,會出現qemu-system-x86_64: Error: HV_ERROR的錯誤,
修正方式如下:

# 參考 https://stackoverflow.com/a/64993771/4802467
cat << EOF > app.entitlements
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>com.apple.security.hypervisor</key>
    <true/>
</dict>
</plist>
EOF
md5 $(which qemu-system-x86_64)
codesign -s - --entitlements app.entitlements --force $(which qemu-system-x86_64)
md5 $(which qemu-system-x86_64)
rm -f app.entitlements

開啟虛擬機

qemu-system-x86_64 \
  -m 4G \
  -vga virtio \
  -display default,show-cursor=on \
  -usb \
  -device usb-tablet \
  -machine type=q35,accel=hvf \
  -smp 2 \
  -drive file=/Users/slanla/qemu/disk.img,index=0,format=raw,if=virtio \
  -drive file=windows.iso,index=1,media=cdrom \
  -drive file=virtio-win-drivers-20120712-1.iso,index=2,media=cdrom \
  -cpu Nehalem

資源下載

virtio-win-drivers-20120712-1.iso

miniconda 安裝

安裝 miniconda

wget https://repo.anaconda.com/miniconda/Miniconda3-latest-MacOSX-x86_64.sh -O ~/miniconda.sh
bash ~/miniconda.sh -b -p $HOME/miniconda

路徑設定

echo 'PATH="$HOME/miniconda/bin:$PATH"' >> ~/.bash_profile 
chmod +x ~/.bash_profile
PATH="$HOME/miniconda/bin:$PATH"

install nodejs on macos with nvm

#安裝nvm
brew install nvm

#設定路徑
echo "source $(brew --prefix nvm)/nvm.sh" >> ~/.bash_profile
. ~/.bash_profile

#查看版本
nvm ls-remote

#安裝8.x
nvm install v8.15.1

#顯示已安裝版本
nvm ls

#切換版本
nvm use v8.15.1

#設定PATH
echo "PATH=$PATH:$(dirname $(nvm which v8.15.1))" >> ~/.bash_profile
. ~/.bash_profile

k375s在macos下的建議設定

個人因為已經習慣Windows鍵盤,
因此鍵盤排列方式會是: Ctrl/Command/Option
而K375s鍵盤有幾種選擇方式:

  • Fn+P(3秒): Windows模式,也就是 Ctrl/Command/Option
  • Fn+I(3秒): iOS模式,也就是 Ctrl/Option/Command
  • Fn+O(3秒): MacOS模式,也就是 Ctrl/Option/Command

因此我會用Fn+P(3秒)強制設定為Windows模式,以便符合我的習慣.

另外,鍵盤預設F1~F12是必須要搭配Fn才能使用的.
這邊則是要透過Fn+Esc(3秒)來將鍵盤設定為標準鍵盤.

移除XQuartz

launchctl unload /Library/LaunchAgents/org.macosforge.xquartz.startx.plist && \
sudo launchctl unload /Library/LaunchDaemons/org.macosforge.xquartz.privileged_startx.plist && \
sudo rm -rf /opt/X11* /Library/Launch*/org.macosforge.xquartz.* /Applications/Utilities/XQuartz.app /etc/*paths.d/*XQuartz  && \
sudo pkgutil --forget org.macosforge.xquartz.pkg  && \
rm -rf ~/.serverauth* && rm -rf ~/.Xauthorit* && rm -rf ~/.cache && rm -rf ~/.rnd && \
rm -rf ~/Library/Caches/org.macosforge.xquartz.X11 && rm -rf ~/Library/Logs/X11

refer: https://gist.github.com/pwnsdx/d127873e24cef159d4d603accaf37ee4

經測試,可移除使用dmg安裝的XQuartz