Migrating (+etc) Win10 virtualbox VM to vmware

## Preamble

- as virtualbox Windows10 guest does not support WSL2, I had to migrate to vmware.
    - it seems that the license is about to be changed to subscription, <font color="red">so I had to buy it before vmware 17 is out.</font>
- just a memorandum.

## Installing vmware

- Go to https://www.vmware.com/products/workstation-pro/workstation-pro-evaluation.html, Download "Workstation 16 Pro for Linux"
- execute that file with sudo.

## Compiling kernel modules

```sh
sudo CPATH=/usr/src/linux-headers-$(uname -r|sed s/amd64/common/)/include/linux vmware-modconfig --console --install-all
```

acknowledgement: https://redtm.com/blog/vmware-workstation-on-kernel-5.16.0-1debian-testing/

If it even does not work, use https://github.com/mkubecek/vmware-host-modules/

## Migrate VM

- on virtualbox, "File -> Export Appliance"
- on vmware, open the ova.
    - Hardware -> Processors -> Virtualize VT-x and IOMMU
    - Options -> General -> Guest Operating System -> Microsoft Windows

## Start Windows

- <font color="red">Here Windows could be unstable for a while. Remove virtualbox guest addition as soon as possible and install vmware tools.</font> Then shutdown.

## Configure VM

### Configure ethernet

- add `ethernet0.virtualDev = "vmxnet3"` to vmx conf
- "Custom: Specific virtual network", input `/dev/vmnet8`
- check /etc/vmware/vmnet8/nat/nat.conf ip and netmask. start windows again and configure NIC's IP to that.

### Configure Display

- Accelerate 3D, ~~video memory 128GB(?)~~
    - Without this, your VM will freeze so often...

should not need so much video memory after disabling memory page trimming

### Configure CPU

- If somehow your VM is slow, set CPU "Number of processors: 2, Number of cores per processor: 2". Because somehow Number of processors is not recognized properly here...

### Disable Drag-and-Drop and Copy-paste

- Seems they cause freeze...
- (from options -> guest isolation)

### Disable memory page trimming

- (from options -> advanced)

acknowledgement: https://qwerty.work/blog/2015/03/vmwarefreeze.php#toc0

## Convert to WSL2

- Install (WSL and) virtualization platform components.

```powershell
#Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux # Should be already there right?
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V-All
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V
Enable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform
Enable-WindowsOptionalFeature -Online -FeatureName HypervisorPlatform
```

- Convert by `wsl --set-version Debian 2`

Note that from now on this wsl will not boot on virtualbox :(

Optionally set this to %USERPROFILE%\.wslconfig (of course double-check about memory size)

```
[wsl2]
memory=8GB
swap=0
```

exclude Windows PATH by /etc/wsl.conf

```
[interop]
appendWindowsPath=false
```

## Convert from MBR to GPT

(Do not perform this if you are booting UEFI or your disk is already GPT)

- Prepare **Windows ISO media** and [GParted ISO](https://gparted.org/download.php). Note that Windows installation does not work during rebuilding boot record.
- Boot from GParted ISO, move the Windows partition to the right about 300MB.
    - If you cannot, you have to `Expand Disk` in VM settings.
- Boot from Windows ISO media, Troubleshoot -> Advanced options -> Command Prompt.

```
bootrec /fixmbr
bootrec /rebuildbcd
# here you could see strange drive letter but seems you can proceed.
```

- Boot Windows, run command prompt as admin

```
mbr2gpt /convert /allowFullOS
```

- VM setting -> Options -> Advanced -> Firmware type -> UEFI

- Optionally, you can reextend EFI partition. Unfortunately gparted cannot extend fat32 volumes, but temporarily you can use EaseUS Partition Master free.

## Upgrade to Win11

- Before beginning this phase, do backup your machine. You cannot go back.
    - Also (sadly) **this is the final state that you can backup your machine.**
- We need to install TPM. We should already be using UEFI, so all we have to do is to encrypt the disk (on Linux, `managedvm.autoAddVTPM = "software"` does not work).
- Then download Windows 11 Installation Assistant from https://www.microsoft.com/software-download/windows11 and proceed.

## Installing WSA

_This does not work here somehow, so I don't recommend..._

### Recognize as SSD

(admin)

```powershell
Set-PhysicalDisk -FriendlyName "Vmware Virtual SATA Hard Drive" -MediaType SSD
```

acknowledgement: https://superuser.com/questions/1634106/in-a-virtual-machine-with-ssd-solid-state-hard-drive-how-can-create-a-hdd-hard/1634148#1634148

### Install WSA

Somehow Amazon Appstore is still grayed out...

1. open ttps://store.rg-adguard.net/
2. "ProductID", 9P3395VX91NR, "Slow"
3. Look for MicrosoftCorpolationII.WindowsSubsystemForAndroid.Msixbundle
4. `Add-AppPackage -Path ...Msixbundle` as admin

## Install docker

- Follow https://docs.docker.com/engine/install/debian/
- `sudo update-alternatives --config iptables /usr/sbin/iptables-legacy`

## X11

Somehow WSLg is too slow, so perhaps mobaxterm is better...

.wslconfig

```
[wsl2]
guiApplications=false
```

.profile

```
export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2}'):0.0
echo SYSTEM_DISPLAY=$DISPLAY | tee -a conf # if some system app use it in background
```

## License

Bought in yahoo store. Hope it is not pirated (lol)