Windows backup

Create installation media

Backup system partition

Shrink

Using PowerShell

In order to save space, shrinking the partition before backup is a good idea.

You may want to disable any anti-virus during the following.

Start PowerShell as administrator and run

# NOTE: The below assumes the drive you want to operate on is `C:`, change as
# necessary if that is not the case.

# Backup any BitLocker keys (since moved/changed boot files may trigger
# BitLocker to ask for them). Save the output somewhere off the device!
# https://docs.microsoft.com/en-us/windows/security/information-protection/bitlocker/bitlocker-use-bitlocker-drive-encryption-tools-to-manage-bitlocker
# https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/manage-bde
# https://docs.microsoft.com/en-us/powershell/module/bitlocker/
# & manage-bde -status
# & manage-bde -protectors -get C:
Get-BitLockerVolume
(Get-BitLockerVolume).KeyProtector

# Perform Disk Cleanup (removes files in `C:\Windows\Temp\`,
# `%HOME%\AppData\Local\Temp` among others).
# https://support.microsoft.com/en-us/windows/disk-cleanup-in-windows-10-8a96ff42-5751-39ad-23d6-434b4d5b9a68
# & cleanmgr
# & cleanmgr /d C: /verylowdisk
# & cleanmgr /d C: /autoclean

# Remove old Updates and Service Packs.
# https://docs.microsoft.com/en-us/previous-versions/windows/it-pro/windows-8.1-and-8/dn251565(v=win.10)
# & dism /online /Cleanup-Image /StartComponentCleanup /ResetBase
# & dism /online /Cleanup-Image /SPSuperseded

# Clear the Microsoft Store cache.
# & wsreset

# Disable System Protection / System Restore (removes restore points in
# `C:\System Volume Information\`).
# https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/enable-computerrestore
# https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/disable-computerrestore
& SystemPropertiesProtection
& rstrui
Disable-ComputerRestore -Drive C:

# Disable page file (removes `C:\pagefile.sys` after restart).
# & SystemPropertiesPerformance
& wmic computersystem get AutomaticManagedPagefile /value
& wmic computersystem set AutomaticManagedPagefile=False
& wmic pagefileset where name=`"C:\\pagefile.sys`" delete

# Disable hibernation (removes `C:\hiberfil.sys` and `C:\swapfile.sys` after
# restart).
# https://docs.microsoft.com/en-us/windows-hardware/design/device-experiences/powercfg-command-line-options
& powercfg /hibernate off

# Enable Safe Mode (after restart).
# NOTE: Safe Mode does not appear to support the PowerShell needed.
# & bcdedit /enum
# & bcdedit /set `{default`} safeboot minimal

# Restart.
# https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/shutdown
# https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/restart-computer
# & shutdown /r
Restart-Computer

# Resize.
# NOTE: It may prove useful to perform this step several times with decreasing
# size.
# https://docs.microsoft.com/en-us/windows-server/storage/disk-management/overview-of-disk-management
# https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/diskpart
# https://docs.microsoft.com/en-us/powershell/module/storage/resize-partition
# https://docs.microsoft.com/en-us/powershell/module/storage/get-partitionsupportedsize
# & diskmgmt.msc
# & diskpart
#   list volume
#   select volume <volume number>
#   shrink [desired=<desiredsize>] [minimum=<minimumsize>]
#   exit
Resize-Partition -DriveLetter C -Size ((Get-PartitionSupportedSize -DriveLetter C).SizeMin + 2GB)

# Check Event Log for unmovable files.
# https://docs.microsoft.com/en-us/windows-server/storage/disk-management/shrink-a-basic-volume#additional-considerations
# https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/get-eventlog
# https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.diagnostics/get-winevent
# & eventvwr.msc
# Get-EventLog -LogName Application | Where-Object { $_.EventID -eq 259 }
Get-WinEvent -LogName Application | Where-Object { $_.Id -eq 259 }

# Disable Safe Mode (after restart).
# NOTE: Safe Mode does not appear to support the PowerShell needed.
# & bcdedit /deletevalue `{default`} safeboot

# Enable hibernation.
& powercfg /hibernate on

# Enable page file.
& wmic pagefileset create name=`"C:\\pagefile.sys`"
& wmic computersystem set AutomaticManagedPagefile=True

# Enable System Protection / System Restore.
Enable-ComputerRestore -Drive C:

# Restart.
Restart-Computer

Third party solutions

All of these are freeware (at the time of writing).

MiniTool Partition Wizard Free
AOMEI Partition Assistant

References:

EaseUS Partition Master

References

Backup

Boot Linux from other media and use dd.