Want to move from two partitions to one as part of your OS deployment?

In the Microsoft Deployment Toolkit refresh scenario (back up user state from current OS, boot to PE, wipe old OS from disk, install new OS image, boot into new OS, restore user state) we normally don't support any type of disk repartitioning or reformatting because we are actively running from the disk.  But there is a scenario that can be done successfully: remove a second partition and go back to having a single-partition setup.  So how would you do that?  It's really not too difficult:

  • Add a new custom task sequence "Run Command Line" step that executes DISKPART.EXE to process a script such as this:

    SELECT DISK 0
    SELECT PARTITION 2
    DELETE PARTITION
    EXIT

  • Ensure that the sysprep.inf is configured to specify ExtendOemPartition=1 (we do this by default in MDT 2008), or if deploying Windows Vista ensure that unattend.xml specifies ExtendOSPartition in the Microsoft-Windows-Deployment component, specialize phase:

    <ExtendOSPartition>
    <Extend>true</Extend>
    </ExtendOSPartition>

The custom DISKPART script removes the second partition (make sure there's nothing on it you want to keep first), and then the Windows XP mini-setup or Windows Vista specialize process takes care of extending the OS partition to take up the remainder of the disk.

On a slightly-related topic, it's actually this extension process that causes the issues described in KB 931760 (the uberbug).  If you deploy Windows XP with a sysprep.inf that doesn't specify ExtendOemPartition=1 you probably won't see any issues and won't have to do any of the workarounds described in the KB article.

If you want to move the other direction (from a single partition to two partitions) let me try to talk you out of it :-)  (I'm not a big fan of multiple-partition configurations, e.g. one partition for the OS and one partition for user data.)  It is possible to move from one to two, but it is more difficult.  The basic process would be to defragment the disk (in case there is something at the end of the partition), boot into Windows PE 2.0 (running from a RAMdisk so that the existing partition isn't in use), and then run DISKPART to shrink the current partition:

SELECT DISK 0
SELECT PARTITION 1
SHRINK QUERYMAX
SHRINK DESIRED=10000 MINIMUM=5000

In this case, the "QUERYMAX" statement would tell you how much you can shrink the partition, while the DESIRED and MINIMUM parameters specify how much to actually do (in MB).  (The SHRINK command was added in the Windows Vista/Windows PE 2.0 version of DISKPART, in case you missed it.)