# 準備 ## 安裝 incus 根據 https://linuxcontainers.org/incus/docs/main/installing/#installing 的說明,Ubuntu 22.04 還沒辦法使用 apt 來安裝,因此依照 https://github.com/zabbly/incus 的說明來安裝: ```shell curl -fsSL https://pkgs.zabbly.com/key.asc | gpg --show-keys --fingerprint mkdir -p /etc/apt/keyrings/ sudo curl -fsSL https://pkgs.zabbly.com/key.asc -o /etc/apt/keyrings/zabbly.asc sudo sh -c 'cat < /etc/apt/sources.list.d/zabbly-incus-stable.sources Enabled: yes Types: deb URIs: https://pkgs.zabbly.com/incus/stable Suites: $(. /etc/os-release && echo ${VERSION_CODENAME}) Components: main Architectures: $(dpkg --print-architecture) Signed-By: /etc/apt/keyrings/zabbly.asc EOF' sudo apt update sudo apt install incus ``` ## 設定 incus 使用 `sudo incus admin init` 來設定,會問一堆問題,如下: ``` Would you like to use clustering? (yes/no) [default=no]: Do you want to configure a new storage pool? (yes/no) [default=yes]: no Would you like to create a new local network bridge? (yes/no) [default=yes]: no Would you like to use an existing bridge or host interface? (yes/no) [default=no]: yes Name of the existing bridge or host interface: enp3s0 Would you like the server to be available over the network? (yes/no) [default=no]: yes Address to bind to (not including port) [default=all]: Port to bind to [default=8443]: Would you like stale cached images to be updated automatically? (yes/no) [default=yes]: Would you like a YAML "init" preseed to be printed? (yes/no) [default=no]: ``` 大部分都預設就可以。 ## 建立 pool ```shell sudo incus storage create vmpool dir source=/lvm1/lxd_storage ``` ## 建立 profile ```shell sudo incus profile copy default windows ``` 編輯profile,內容如下: ``` config: limits.cpu: "16" limits.memory: 16GiB raw.qemu: -device intel-hda -device hda-duplex -audio spice description: 'Windows: 16CPU, 16GB RAM, 1024GB DISK' devices: eth0: name: eth0 nictype: macvlan parent: br0 type: nic root: path: / pool: vmpool type: disk vtpm: path: /dev/tpm0 type: tpm name: windows used_by: [] ``` ## 安裝需要的套件 ```shell sudo apt-get install genisoimage libguestfs-tools wimtools --yes sudo snap install distrobuilder --classic ``` ## 轉換 ISO 我們需要把Windows ISO轉換為lxc可用的ISO,先準備好原本的Windows ISO,這裡的檔名是 `Win11_23H2_Chinese_Traditional_x64v2.iso`,記得換成你自己的檔名。 命令如下: ```shell sudo distrobuilder repack-windows Win11_23H2_Chinese_Traditional_x64v2.iso Win11_23H2_Chinese_Traditional_x64v2.lxd.iso ``` 我們把 `Win11_23H2_Chinese_Traditional_x64v2.iso` 轉為 `Win11_23H2_Chinese_Traditional_x64v2.lxd.iso`。 等一下 `Win11_23H2_Chinese_Traditional_x64v2.lxd.iso` 就是要餵給虛擬機安裝的檔案。