Saturday, November 8, 2008

Extend or shrink hard disk partition in Windows with diskpart.exe

I actually didn't know it was possible to do this until I saw someone demonstrating a SAN and VMWare, and I thought it was pretty useful knowledge. If you partition a hard drive, and then want to consolidate partitions or just delete one to give more space to another, you can do that. Or if you're using virtualization software like VMWare and decide to change the size of your virtual disk, you'll need to do this as well.  You'll have to use the command prompt, and the diskpart.exe utility built into Windows. The Disk Management GUI is nice, but it doesn't allow you to do this.

1. Open the command prompt, type diskpart, then press Enter. This will start the diskpart utility, and you'll see the command prompt change to DISKPART>. 

2. Now you need to find the partition you want to extend or shrink. To do this, use the command list volume. 

3. To change the focus of the diskpart utility to the partition you want to work with, select volume #, where # stands for the number of the volume that you see listed in step #2.

4. Assuming you already have the space on the drive available to extend the partition to, just type extend and press Enter. This will expand your partition into the new free space.

You can also shrink the volume instead of extending it, or you can specify just how much to extend or shrink with additional command line parameters. I just covered the easiest, and most useful feature in my opinion. diskpart.exe has plenty of other uses too, but most of those can also be done in the Disk Management MMC. Basic vs Dynamic disks are another interesting topic, along with striped disks right from Windows. I'll leave those for another time though. diskpart.exe does have some difference between XP and Vista, but I'll let you figure those out as you go. Just know that if you have problems using it in Vista, check to make sure the command is supported.

For more information about diskpart.exe, check out these links.

No comments: