I came by looking for a possible explanation or easier (read: automated/scripted) way to clear this “lock” on the MFT/TxF/NTFS metadata. Thought I’d throw this out there, as I have a solution that has worked for me in countless situations. I have used it to remove all manner of USB and eSATA drives that get stuck like this. The issue does seem to be primarily removable drives that mount as fixed drives, such as those in an eSATA dock or USB enclosure. USB thumb drives generally don’t seem to exhibit this issue for me.
An item of note on this last distinction: the Sandisk Extreme USB 3.0, an odd beast comprised of an SSD controller in a USB key’s body, also shows up as a fixed drive, though it does seem to have no issue being pulled unceremoniously and without any safe removal being done, so I’m guessing it at least turns off any write caching due to its speed and potentially something else as well, as it never seems to have this issue, always retaining its instant removability. Not necessarily a perfect example, as I haven’t been thorough in my testing (this is just anecdotal) but it may shed a little light on this due to its “fixed” nature, yet apparent lack of susceptibility to this issue. Just food for thought.
<– The Solution –>
Anyways, simply put, you need to offline the drive. You can do this in one of two ways. Note: There are slightly shorter ways to do this, but here are the ridiculously thorough steps because I don’t know my audience. The GUI method is by far the fastest, owing to the fact that diskpart.exe doesn’t take switches or in-line commands/arguments.
- GUI: Run -> “diskmgmt.msc” -> Find your drive in the physical disk list (bottom pane) -> right-click the drive (the left-most part), not the partition -> Click “Offline”
- CLI: Run -> “cmd.exe” -> type “diskpart” -> type “list disk”, find your disk # -> type “select disk x”, where x is your disk’s # from the last step -> type “offline disk”. Now you can exit the command prompt or just type “exit” at diskpart, then close the prompt.
All that’s important should be to offline the volume as this will remove NTFS’ hold on the drive, but offlining the disk is simpler and more thorough.
The disk #s are always identical between diskpart.exe and diskmgmt.msc because they’re pulling the info from the same place, just in case you’re curious/worried/cautious.
Today, it occured to me to look in the event log. I found this right after the removal attempt:
log: System, source: Kernel-PnP, event ID: 225, level: warning
The application \Device\HarddiskVolume2\Windows\System32\Taskmgr.exe with process id 6436 stopped the removal or ejection for the device […]
So I closed Task Manager and Safe Remove worked.
I created this batch script to “unlock” any volume. Just run the .bat script as administrator, select the volume, and press ENTER. After it you should be able to use “Safe remove” as usual to detach the unit.
@echo off @cls set tempfile="%TEMP%\diskscrp.dsk" echo. echo === Disk removal tool === echo. echo Select the disk volume number echo (if the disk has multiple volumes, select any of them) echo. echo list volume | diskpart | findstr /C:Volume /C:--- echo. set /p volume=" Selected volume: " echo. echo select volume %volume% >>%tempfile% echo offline disk >>%tempfile% echo online disk >>%tempfile% diskpart /s %tempfile% | findstr /C:"not valid" if "%ERRORLEVEL%"=="1" ( echo Disk has been unlocked successfully. Try to safely remove it now. ) del /F %tempfile%
This script is based on @Rook suggestion, so it uses
diskpart to make the disk offline. When this is done, all handles are forcibly closed. The difference in this script is that it automatically make the disk back online, so it can be recognized the next time it is connected to the system.
A large fraction of external drive/Windows OS combos have this problem, maybe most.
What I do is sleep my box (a laptop) and wait the ten seconds it takes for the external drive to power down (I can hear it). Then unplug.
If the system is asleep then all I/O operations are complete & the I/O bus is quiesced. Waiting for the drive to power down is “belt and suspenders” on top of that.
(Note that if one is too paranoid for that approach, doing a hibernate should be fully sufficient. Full power off should not be required.)
For now you can just attempt to disconnect the external by shutting the computer down and then unplugging it, therefore attempting data loss and then setting it up for easy removal as to prevent data loss when simply unplugging it without unmounting it.
To be honest it sounds sort of like a MBR error where the drive is stuck seeing itself as always plugged in, in which case if you were to unplug the drive while powered on you could damage the MBR and leave you with 2 options, manually repairing the MBR or attempting to use software like MBR repair to be able to access the drive again, or use software like gparted to format the disk again and set a new partition table where the error most likely occurred.
I believe these files belong to the Transactional NTFS (TxF).
I hear Transactional NTFS is used by autoupdate, but have no clue why the system would want to place this on an external disk and then be unable to stop it upon safe removal request.
Fsutil resource info doesn’t show any activity.
Try in the cmd console:
fsutil resource stop E:
or, if it doesn’t help,
fsutil resource setautoreset true
You can also try stopping a TxF-related service in Computer Management / Services
I had the same thing happening with a flash drive recently. Like you, I kept showing active $Extend handles and assumed they were preventing me from removing the drive safely. I stumbled across this question and tried Sem’s
fsutil suggestion to no effect. What did work for me was manually unmounting the drive. Since my flash drive was mounted as F:, I ran:
mountvol f: /d
I then unplugged the drive, plugged it back in, remounted it using
mountvol f: <volumename> and used it for a while. When I was finished, I checked the active handles and saw the same $Extend entries I noticed previously. When I tried to do the ‘normal’ safe removal though, it succeeded despite the active handles.
I don’t know if it was sheer chance that this worked for me, but I’m adding it here in case it helps anyone else.