Tracking progress of shrinking volumes in Windows Server 2008 R2

So, yesterday, I had the requirement to shrink a partition. The partition was spanning four dynamic disks, with a total size of 7.5 TiB.

So, using Disk Management, I just go into the GUI, right-click this monster of a partition, click shrink, wait a couple of minutes for it to analyze the free space, and then to tell it to shave of a little north of 4 TB. The goal was to get rid of the two last dynamic disks to reclaim disk space. I fully expected this to take its sweet time. After all, moving data takes time, especially up to 4 TB of it. For the shrink to work, it basically has to pick up all the data past the end of the new partition, and jam it in at the start of the drive.

I was expecting like… a progress indicator which you might expect on any long-running operation? Nope. All I got was a Windows 3.11-style hourglass mouse cursor whenever my mouse is inside Disk Management. Totally useful.

So I leave it overnight, and it’s still running. Curious to see what the hell’s going on, I look at the Resource Monitor. Under Disk, I see that svchost.exe (defragsvc) is reading and writing to my disk at 20 MB/s. Not exactly high speed, but meh. Back-of-the-envelope calculation tells me that 4 TB at 20 MB/s would take 60 hours. That’s fine, it can run over the weekend (I’m not too fussy about how long this takes even though it’s dog slow), but I still wanted to find out its progress. Because I like micromanaging my computers. Like a project manager, I demand percentage-based progress reports!

The fact that it’s defragsvc doing the work is an important clue (and it makes sense too, after all, it is a kind of a full-disk defrag that has to happen). So, I go on the Googles (defragsvc progress), and I click on a random vaguely promising link and end up at the Windows Seven Forums, on a thread labeled “defrag display”. I scroll past most of the stuff that’s not relevant to my case ut then I found this one post listing a few interesting switches to defrag.exe – the command-line interface to defrag. The one that caught my eye was not the one in bold, but rather these two:

/T – Track an operation already in progress on the specified volume.
/U – Print the progress of the operation on the screen.

So… on a whim, I open up a shell and type in “defrag d: /t”. Of course, whoever installed the server made it in Swedish. I have nothing against localized operating systems, in fact I make it a point to make my own PC run in Swedish, but servers need to be installed in English, but I digress. (I’ll probably write something on that.) Anyway, this is the output I got:

PS C:\Users\Administratör> defrag d: /t
Microsoft Diskdefragmenteraren
Copyright (c) 2007 Microsoft Corp.

Spårar åtgärd på Data (D:)...

That says “Tracking operation on Data (D:)”. But there’s no actual other information. I wonder about “what’s the point of tracking an operation if you don’t see any progress?” so I Ctrl+C out of that and instead try:

PS C:\Users\Administratör> defrag d: /u
Microsoft Diskdefragmenteraren
Copyright (c) 2007 Microsoft Corp.

Anropar defragmentering på Data (D:)...

 Analys: 100 % färdigt.

Rapport före defragmentering:

 Volyminformation:
 Volymens storlek = 7,49 TB
 Ledigt utrymme = 4,94 TB
 Totalt fragmenterat utrymme = 5 %
 Storlek på största lediga utrymmet = 599,77 GB

 Obs! Filfragment som är större än 64 MB inkluderas inte i fragmenteringsstatistiken.

Utför pass 1:
 Defragmentering: 0 % färdigt...

So… it actually started a new defragment. I also got a pop-up message from Windows (probably from Disk Management) saying my shrink operation was aborted. Balls. It seems that I told it “defrag drive D, and show me the progress as you go”. Not what I wanted. I Ctrl+C’ed out of that as well. I would have been more annoyed at having the defrag aborted half-way, but the fact is that the subsequent defrag run will just have less to do anyway, and I’m not really in a rush.

So, then I thought, maybe you need both switches? Would make sense, in a perverse Microsoft way. Track the operation and show me the progress.

So, I click through starting the shrink process again, and then I try this:

PS C:\Users\Administratör> defrag d: /t /u
Microsoft Diskdefragmenteraren
Copyright (c) 2007 Microsoft Corp.

Spårar åtgärd på Data (D:)...

 Analys: 100 % färdigt.

Rapport före defragmentering:

 Volyminformation:
 Volymens storlek = 7,49 TB
 Ledigt utrymme = 4,94 TB
 Totalt fragmenterat utrymme = 5 %
 Storlek på största lediga utrymmet = 599,77 GB

 Obs! Filfragment som är större än 64 MB inkluderas inte i fragmenteringsstatistiken.
 Krymp: 53 % färdigt...

That looks promising. “Krymp” is means “shrink” in Swedish. So it’s actually showing me progress of the exising operation. Yay!

I found it interesting that it started out at 53% and not at 0% – maybe it recognised it had been aborted? Or maybe it calculates the progress from the “worst case possible” shrink operation…?

Would be nice with a decimal point or two more, so you can actually stare at it and see it moving. Or maybe a bogus ETA? Oh well, it’s a lot better better than just an hourglass. In the end, the best way for me to actually figure out how long this is going to take, is to wait a few hours, see how many percentage points it’s done in that time, and extrapolate.

So, to recap, if you have a current long-running shrink operation happening that you started from Disk Management, if you want to know what’s going on, pull up a shell, and type in:

defrag X: /t /u

Substituting the drive letter you’re shrinking for X, of course.

As a final word of warning: Do not Ctrl+C out of the progress display! If you do, it’ll actually abort the defrag operation! Which actually makes no sense, since you’re just tracking an ongoing operation… but this is what I’ve observed.

Update: A few hours after originally posting this, I decided to check on it, and see how it was doing. It was still stuck at 53% complete. I killed it and restarted it, and it came to 53% done after a minute or so, jumping there directly from 0%. It may well be that the progress indicator simply does not work for whatever reason, and that this entire post is useless.

Update 2: I discovered the same progress information can be found by opening the Disk Defragmenter UI.

Update 3: One day later, we’re at 54%. I think however that this is due to a very large inbound file transfer (on the order of 1 TB) that’s been running for over a day now to this server, at the same time as trying to shrink. So the progress is moving after all. I expect it to start moving a lot faster as soon as that large file transfer is finished.

2 thoughts on “Tracking progress of shrinking volumes in Windows Server 2008 R2”

  1. wow – the Defrag GUI has the info in it. No idea why that isn’t put into the disk management interface where I started the operation. I’m halving the size of a 4TB partition to try and resolve the WSB 2TB drive limit issue.

  2. Nice find. I tried this myself, and just in case you were wondering about the translation (my pc installed in English), this is my output screen during a shrink operation.

    C:\Windows\system32>defrag e: /t /u
    Microsoft Disk Defragmenter
    Copyright (c) 2007 Microsoft Corp.

    Tracking operation on MEDIA (E:)…

    Analysis: 100% complete.

    Pre-Defragmentation Report:

    Volume Information:
    Volume size = 929.99 GB
    Free space = 312.13 GB
    Total fragmented space = 0%
    Largest free space size = 121.00 GB

    Note: File fragments larger than 64MB are not included in
    the fragmentation statistics.
    Shrink: 15% complete…

Leave a Reply

Your email address will not be published. Required fields are marked *