Skip navigation
Initializing Windows Disks with DiskPart

Initializing Windows Disks with DiskPart

This oft-forgotten tool is indispensable when you’re building systems

One of Windows' essential command-line utilities is Diskpart, the successor to Fdisk that appeared first in Windows XP. The tool lets you partition, format, initialize, and resize drives, set up RAID, and more—and in Windows 7 and Windows Server 2008 R2, it lets you work with virtual disks. I find Diskpart indispensable when building systems, so I’m often surprised to hear that many IT pros don’t know much about it. So, let's dig in and see how to use Diskpart to wipe a hard disk clean, partition the disk, and format it.

At the command line, type diskpart and press Enter. Once you’re in the tool, your Diskpart has its own command prompt. What you're seeing is that Diskpart is essentially its own command environment—sort of a command line interface (CLI) inside a CLI. Typing help (or any invalid command) and pressing Enter causes Diskpart to display about three dozen commands, but don't let the prospect of learning 37 commands scare you away from Diskpart because you'll actually perform 99 percent of your Diskpart work with about eight commands.

As you know, if you've ever initialized a disk from the Logical Disk Manager GUI, you first click on the physical disk drive, then create a partition (or partitions) on it, then format those partitions and typically give them letters. Diskpart follows the same pattern, requiring you to select a disk before you create partitions on it, then requiring you to select a partition before formatting it, and so on. To select a particular disk, you type a command that looks like

select disk <disknumber> 

but which number is the disk you want to work on? Find out by typing list disk, which gives you output that looks like Figure 1. Diskpart numbers disks starting from zero rather than one, and you can see that both drives store their partition information on the master boot record (MBR) rather than a GUID partition table (GPT), and both disks are basic rather than dynamic.

Disk ###  Status  Size   Free     Dyn  Gpt
--------  ------  -----  -------  ---  ---
Disk 0    Online  24 GB  1024 KB
Disk 1    Online  24 GB  0 B

Now, I’ll complicate the problem by saying that this system has two 24GB drives—one holds the OS and applications, and the other is just an extra drive for holding data. Clearly, you don’t want to accidentally wipe the OS’s drive, so how do you know which is which? You use select disk, along with detail disk. Let's start with disk 0 and see what’s on it:

select disk 0

detail disk

That provides output that looks like Figure 2. Disk 0, then, is—surprisingly—the data disk, and therefore disk 1 must be the OS disk. So, you've got your sights on the correct disk (disk 0). Next, let's wipe the disk clean by typing clean. Doing so doesn't really wipe a disk clean by overwriting all of its data; rather, clean erases the MBR, which is essentially the disk’s “table of contents.” The old data is still on the disk, but the OS doesn't know how to get to it anymore, so that data will end up being slowly overwritten as we build a new disk structure atop the old one and start putting files on that new disk structure.

VMware Virtual IDE Hard Drive ATA Device
Disk ID: F1B17FB3
Type   : ATA
Status : Online
Path   : 0
Target : 0
LUN ID : 0
Location Path : PCIROOT(0)#PCI(0701)#ATA(C00T00L00)
Current Read-only State : No
Read-only  : No
Boot Disk  : No
Pagefile Disk  : No
Hibernation File Disk  : No
Crashdump Disk  : No
Clustered Disk  : No

Volume ### Ltr Label      Fs    Type      Size  Status  Info
---------- --- ---------- ----- --------- ----- ------  --------
Volume 1   E   New Volume NTFS  Partition 23 GB Healthy

Next, the newly cleaned disk needs at least one new disk partition. The simplest method is to make the drive into one big partition with command create partition primary. If, however, you want to chop the drive into multiple partitions, you’d add the size= parameter, followed by the desired size in megabytes. If I wanted to create two partitions—one 10GB and another 14GB—I'd create the first one by typing

create partition primary size=10240

(Remember, there are 1024MB in a gigabyte, not 1000.) Then, I could create the second partition by just typing create partition primary, as the create partition command without a size= parameter tells Diskpart to use all the remaining space on the hard disk. I can see the result of my work by typing list partition, which results in the data that Figure 3 shows.

Partition ###  Type     Size   Offset
 -------------  -------  -----  -------
 Partition 1    Primary  10 GB  1024 KB
*Partition 2    Primary  13 GB  10 GB

Now, we've got our partitions, but they still need drive letters and formatting. Now learn how to do that in, " Formatting and Resizing Partitions with Diskpart ."

Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish