How to empty and delete a partition?

Situation

Last year I have created an Ubuntu Virtual Machine I don't want to use anymore. I allocated 195 Go to a partition (D) for the VM. I have already uninstalled the VM. Now I want to delete D so I have deleted all the files on it and when I enter the partition with the explorer, it says the partition is empty.

Problems

  • When I look at the page listing all my drives and partitions, the explorer says D contains 16.9 Go of datas.
  • When I try to format D, I have a message saying D is opened in another application or process, but all my applications are closed. I also try to reboot the computer then format D but it still shows the same message.
  • I tried to use the disk manager and right click on D but the option "Delete volume" is not available : Disk management
  • So I clicked on the option "Shrink volume" and I reduced D to the maximum. I hoped I could reduce it to 0 Go but it doesn't want to go below 24.8 Go. Moreover I now have a 170.51 Go non allocated partition which is the remaining space of the 195 Go I have shrinked before. I thought this non allocated memory would be added to the C partition but it didn't. I tried to right click on C and choose "Extend volume" but the option is not available.
  • I found this https://www.windowscentral.com/how-delete-drive-partition-windows-10. So with the PowerShell, I executed commands to delete D but it didn't work : PowerShell 1 PowerShell 2

Questions

  • Does D still contains remaining files (e.g. system files or files created by the VM) I have to delete ? Is it dangerous for my computer or my datas if I don't delete them correctly ?
  • How can I delete D ?
  • How can I allocate the non allocated memory to C ?
  • I have WSL 2 installed. Can it help to format D ?

Solution 1:

From the Disk Management screenshot is now clear why the partition is in use: It contains a paging file.

Disable it and you will be able to delete the partition. Go to the settings app, SystemAbout on the left → System info on the right → Advanced system settings on the left → Advanced tab → Change under Virtual memory. From there, you will be able to manipulate the settings. I recommend using System managed size on C: and None for all other partitions. You will have to reboot for the change to take effect.