okibcn/wslcompact

File being used by another process error

da4089 opened this issue · 0 comments

da4089 commented

I'm getting the following error trying to compact my WSL:

C:\Users\darnold> wsl --shutdown
C:\Users\darnold> wslcompact -c Ubuntu
 WslCompact v8.7 2023.03.01
 (C) 2023 Oscar Lopez
 wslcompact -h for help. For more information visit: https://github.com/okibcn/wslcompact

 Distro's name:  Ubuntu
 Image file:     C:\Users\darnold\AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState\ext4.vhdx
 Current size:   42943 MB
 Estimated size: 2609 +/- 64 MB
 The estimated process time using an SSD is about 1 minutes.
 NOTE: You can safely cancel at any time by pressing Ctrl-C
 Move-Item : The process cannot access the file because it is being used by another process.
At C:\Users\darnold\Documents\WindowsPowerShell\Modules\WslCompact\WslCompact.psm1:99 char:25
+ ...             Move-Item "$tmp_folder/ext4.vhdx" "$tmp_folder/$wsl_distr ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : WriteError: (C:\Users\darnol...mpact\ext4.vhdx:FileInfo) [Move-Item], IOException
    + FullyQualifiedErrorId : MoveFileInfoItemIOError,Microsoft.PowerShell.Commands.MoveItemCommand

Get-Item : Cannot find path 'C:\Users\darnold\AppData\Local\Temp\wslcompact\Ubuntu.vhdx' because it does not exist.
At C:\Users\darnold\Documents\WindowsPowerShell\Modules\WslCompact\WslCompact.psm1:101 char:35
+ ...       $size2 = (Get-Item -Path "$tmp_folder/$wsl_distro.vhdx").Length ...
+                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (C:\Users\darnol...act\Ubuntu.vhdx:String) [Get-Item], ItemNotFoundExcep
   tion
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetItemCommand

 New Image compacted from 42943 MB to 0 MB
 Do you want to apply changes and use the new image (y/N): n

C:\Users\darnold>

I tried a reboot, in case something might have been using WSL, but it made no difference.

Any suggestions appreciated!