Thursday, November 12, 2026

python whole disk backup

To run the equivalent of dd on Linux on a Windows machine using an interactive python script - https://github.com/hn-88/python-interactive-hdd-restore/tree/main

Tested on a Windows 11 ARM VM with VMWare on MacOS host, similar to https://github.com/hn-88/python-interactive-hdd-restore/blob/main/test-setup-on-mac.md


For testing, the TPMS module needed to be removed for the Windows VM - otherwise, it would not allow a new existing hard disk to be added. Copy-pasting Claude's suggestions - 

Clone the VM and decrypt the clone. Shut down the Windows VM, go to Virtual Machine → Create Full Clone, then turn off encryption on the clone.

When trying to change settings on the clone, it asked for a password, which I had forgotten.

Look in Keychain Access (Spotlight → “Keychain Access”). Search for “VMware”, “Fusion”, or the VM’s name. Look for an entry that appears to belong to the VM. Double-click it, tick Show password, and authenticate with your Mac login password. Paste that into the clone’s prompt.

Then changed the settings of the cloned Windows VM - deleted the TPMS module, then it allowed the encryption setting to be changed to unencrypted. Then I could add the Linux vmdk file as another hard disk on the Windows VM.

When backing up to an image, I could connect a USB NTFS disk, and mount it directly in the Windows VM without going through MacOS - 

With the Windows VM running, go to Virtual Machine → USB & Bluetooth in the Fusion menu bar. Pick your drive from the list and choose Connect.

Using Z: mapped to the host did not work initially, because the mapping was not carried over to the Administrator shell. Moreover, that would be slower. Hence, the direct USB mapping above was the way chosen.

Z: is most likely a VMware shared folder or a mapped network drive. Windows keeps drive mappings per logon session, and an elevated (Administrator) terminal is a different session from your normal one. So Explorer can see Z:, but the admin terminal can’t, and Python reports “No such file or directory”. Either re-map the drive inside the admin terminal: 

   net use Z: "\\vmware-host\Shared Folders\MyShare"

or use the UNC path,    
python diskimage.py backup 1 "\\vmware-host\Shared Folders\MyShare\linuxim.gz"