Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save githuan/e61d6e22dfb89b14b0d7f2d722b51894 to your computer and use it in GitHub Desktop.

Select an option

Save githuan/e61d6e22dfb89b14b0d7f2d722b51894 to your computer and use it in GitHub Desktop.

Revisions

  1. @skirmess skirmess revised this gist Jan 24, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion windows-10-pro-smartos-bhyve.md
    Original file line number Diff line number Diff line change
    @@ -81,7 +81,7 @@ automatically shut down.
    -rw-r--r-- 1 root root 10891713416 Jan 16 14:25 /zones/windows.zvol
    ```

    Generate a random GUID with ''uuidgen(1)'' and create the
    Generate a random GUID with `uuidgen(1)` and create the
    `windows.imgmanifest` file.

    ```json
  2. @skirmess skirmess revised this gist Jan 24, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion windows-10-pro-smartos-bhyve.md
    Original file line number Diff line number Diff line change
    @@ -81,7 +81,7 @@ automatically shut down.
    -rw-r--r-- 1 root root 10891713416 Jan 16 14:25 /zones/windows.zvol
    ```

    Generate a random GUID <https://duckduckgo.com/?q=guid> and create the
    Generate a random GUID with ''uuidgen(1)'' and create the
    `windows.imgmanifest` file.

    ```json
  3. @skirmess skirmess revised this gist Jan 16, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion windows-10-pro-smartos-bhyve.md
    Original file line number Diff line number Diff line change
    @@ -82,7 +82,7 @@ automatically shut down.
    ```

    Generate a random GUID <https://duckduckgo.com/?q=guid> and create the
    windows.imgmanifest` file.
    `windows.imgmanifest` file.

    ```json
    {
  4. @skirmess skirmess revised this gist Jan 16, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion windows-10-pro-smartos-bhyve.md
    Original file line number Diff line number Diff line change
    @@ -21,7 +21,7 @@ Download latest stable Virtio driver ISO from <https://fedorapeople.org/groups/v

    ### Create a new filesystem to install Windows

    All virtual machines created from this image will have this size. Choose a size that fits your need.
    All virtual machines created from this image will have this size. Choose a size that fits your needs.

    <code>
    # zfs create -V 80G zones/windows
  5. @skirmess skirmess created this gist Jan 16, 2021.
    163 changes: 163 additions & 0 deletions windows-10-pro-smartos-bhyve.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,163 @@
    ## Windows 10 Pro

    ### Windows 10 Pro ISO

    Create a fresh Windows 10 Pro ISO file with Microsofts Media Creation Tool. (I created a Windows 10 Pro 64 bit German ISO image)

    Save the created image on your SmartOS global zone.

    ```bash
    cp ... /zones/Windows10_64de.iso
    ```

    ### Virtio driver

    Download latest stable Virtio driver ISO from <https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/stable-virtio/> and save it in the global zone.

    ```bash
    # cd /zones
    # wget --no-check-certificate https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/archive-virtio/virtio-win-0.1.185-2/virtio-win-0.1.185.iso
    ```

    ### Create a new filesystem to install Windows

    All virtual machines created from this image will have this size. Choose a size that fits your need.

    <code>
    # zfs create -V 80G zones/windows
    </code>

    ### Install Windows 10 Pro

    ```bash
    # export WINDOWS_INSTALL_CD=/zones/Windows10_64de.iso
    # export VIRTIO_DRIVER_CD=/zones/virtio-win-0.1.185.iso

    # pfexec /usr/sbin/bhyve -c 1 -m 3G -H \
    -l com1,stdio \
    -l bootrom,/usr/share/bhyve/uefi-rom.bin \
    -s 2,ahci-cd,$WINDOWS_INSTALL_CD \
    -s 3,virtio-blk,/dev/zvol/rdsk/zones/windows \
    -s 4,ahci-cd,$VIRTIO_DRIVER_CD \
    -s 28,fbuf,vga=off,tcp=0.0.0.0:5900,w=1024,h=768,wait \
    -s 29,xhci,tablet \
    -s 31,lpc \
    windows
    ```

    Bhyve will wait until you connect with VNC to port 5900 of your global zone.
    After you connect you have a few seconds to press any key to boot from CD.

    Select the install now option and answer that you don't have a product key (license).
    Pick the Windows version you want to create the image for (Windows 10 Pro).

    When asked where to install it to, load the Virtio SCSI driver from this
    location `E:\amd64\w10\viostor.inf`.

    Whenever Windows wants to reboot the bhyve command terminates. Run the same
    ommand again but don't press any key. These times we want to boot from the
    hard disk.

    Repeat this until Windows starts to ask you questions. Press `Ctrl + Shift + F3`
    to reboot to audit mode (run the same bhyve command again). Audit mode logs
    you automatically into the Administrator account. (This takes forever, twice,
    to log you in. Just be patient.) Keep the window from `sysprep` open, do not
    click OK as this will reboot out of audit mode.

    Run `E:\virtio-win-gt-x64.msi` and install all the Virtio drivers - or at least
    the networking one.

    Click OK in the window from the `sysprep` tool and wait for the system to
    automatically shut down.

    ### Create the image

    ```bash
    # zfs send zones/windows | tee /zones/windows.zvol | digest -a sha1
    5989a20371dbb29ab7e04d32f124eccfe5749a4b
    # zfs destroy zones/windows
    # /usr/sbin/bhyvectl --destroy --vm=windows
    # ls -l /zones/windows.zvol
    -rw-r--r-- 1 root root 10891713416 Jan 16 14:25 /zones/windows.zvol
    ```

    Generate a random GUID <https://duckduckgo.com/?q=guid> and create the
    windows.imgmanifest` file.

    ```json
    {
    "v": 2,
    "uuid": "47e05f5c-a9c3-4779-b01a-a94d16f3a404",
    "name": "win-10-pro-de",
    "version": "0.0.1",
    "type": "zvol",
    "os": "windows",
    "files": [ {
    "sha1": "5989a20371dbb29ab7e04d32f124eccfe5749a4b",
    "size": 10891713416,
    "compression": "none"
    } ]
    }
    ```

    Import the image.

    ```bash
    # imgadm install -m /zones/windows.imgmanifest -f /zones/windows.zvol
    ```

    We're done, you can now create virtual machines from this image.

    ## Create a Windows 10 Pro VM

    The `vcpus` option from bhyve creates that number of CPUs, not cores.
    Unfortunately, Windows 10 Pro doesn't support more than 2 CPUs. That's
    why we only define a single `vcpus` but add multiple cores and threads
    with the `bhyve_extra_opts` option.

    The `nics` options should be adjusted to match your needs. The example
    works with an external DHCP server to automatically configure networking.

    ```json
    {
    "alias": "wintest",
    "brand": "bhyve",
    "vcpus": 1,
    "bhyve_extra_opts": "-c sockets=1,cores=4,threads=2",
    "autoboot": false,
    "ram": 8192,
    "bootrom": "uefi",
    "disks": [ {
    "boot": true,
    "model": "virtio",
    "image_uuid": "47e05f5c-a9c3-4779-b01a-a94d16f3a404",
    "image_size": 15360
    } ],
    "nics": [
    {
    "nic_tag": "admin",
    "vlan_id": 150,
    "ip": "dhcp",
    "primary": "true",
    "model": "virtio"
    }
    ]
    }
    ```

    Now we create and start the VM.

    ```bash
    # vmadm create -f wintest.json
    Successfully created VM 3f23f273-f4dc-4cab-bd8d-8aeac66fe79e
    # vmadm start 3f23f273-f4dc-4cab-bd8d-8aeac66fe79e
    # vmadm info 3f23f273-f4dc-4cab-bd8d-8aeac66fe79e vnc
    ```

    Connect with VNC and answer the questions.

    Tip: When you create an offline account, don't set a password. You can
    set the password after you log in the first time. That way you don't have
    to answer the 3 idiotic recovery questions.

    After you've set the password, enable the remote desktop and have fun.