Saturday, December 01, 2007

Command-Line Voodoo: from fdisk to diskpart

I'm getting pretty comfortable now wiping volumes out to the bare-naked goodness.

Then creating new volumes and formatting them.

This is because I've been doing some heavy work with ImageX at work and one of the prerequisites to applying an image is making sure the drive partition is fresh and clean.  Since ImageX will overlay any existing files and file structure remaining on a drive, it is important to make sure it is prepped and clean before the image is restored.

So since I am working with Windows PE 2.0 now, I've become good friends with a new disk management tool from Microsoft; Diskpart.

But first a brief timeline for memory's sake.

First there were two friends, Fdisk and Format

When I first got started in Windows desktop support, we used Fdisk and Format commands to prep a hard-drive.

We would boot the system with a DOS 6.22 boot floppy with a few "extra" utilities copied to it and run FDISK. Stepping through the menu we would walk through the steps of creating the primary DOS partition, size it, set it active, and maybe create an extended partition.

Once done, we would then reboot the system with the boot floppy and format the partitions.

At that point we would copy the system files over to the active boot partition and work on building the DOS based system, loading network applications and software, etc.

Windows 95/98 machines followed a pretty similar process, only we would then run a Win 9x setup disk after manually prepping the drive, then do the system setup.

By the time we progressed to Windows 2000, the process had been made much simpler.  We were using Ghost/Acronis images at this point, so it was pretty much monkey places the boot image cd in the pc, presses "YES" and the image is on the drive.  Sure we could still do a manual disk partition and Windows 2000 setup from scratch, by why bother when we had pre-formatted images to use?

Windows XP came along and we were still using pre-created system images. They are big time savers.  Sure, we have XP Pro setup disks.  When ran we can follow the prompts to repartition the drive and then format it before loading XP on from scratch.  But why re-invent the wheel?

Time to make a new friend: DiskPart

What happens when a new hard drive gets replaced, but XP setup continually fails while creating the partition?  What do you do when you have acquired a new ImageX image, but need to put it on a bare drive or virtual hard drive?  If you have Windows XP or Vista PE, time to make friends with DiskPart.

Assuming you have the bare-drive ready and have a bootable Vista PE or XP disk, time to create an active partition.  In the command-line interface start typing and press <enter> after each line (assuming you don't get any errors.

  • diskpart
  • select disk 0
  • clean
  • create partition primary
  • select partition 1
  • active
  • assign letter = C
  • exit

What we have just done is ran the diskpart utility, selected the master drive (0), cleaned it, created a primary partition on it, selected it, set it to be the active (boot) volume, assigned letter "C" to it, and jumped out.

Now we just format the active partition that we created above. Type the following and <enter>

  • format C: /fs:ntfs /q /y

Now your drive is formatted with NTFS and ready to go.

Of course, the diskpart and format commands have a whole-lot more complexity than just this, but this is the quick and easy way to get a single partition ready to put an ImageX image on it.

What?

Don't have DiskPart because you have Windows 2000? Go download it from free direct from Microsoft: Download: DiskPart.exe

More Helpful Links

How to partition and format a hard disk in Windows XP - KB313348 explains how to use the XP setup disk to partition and format the hard-drive.

Microsoft Windows XP - Format - Microsoft XP Pro documentation on the format command. Note the undocumented format argument we used "/y" is not listed.  I believe it suppresses the usual confirmation request before formatting begins.

Blog - A geeks guide for building and deploy the perfect Vista image - Nice how-to on how to make a WinPE 2.0 boot disk with ImageX, capture a Vista image, then deploy it to a fresh drive.  Can be "tweaked" to capture other systems such as an XP or Windows 2000 system quite easily.

Known issues that occur when you create custom Windows PE images from Windows Server 2003 Service Pack 2 by using the Windows Server 2003 Service Pack 1 version of the OPK tools - Microsoft KB933510 touches on many of the things we have already covered.

Microsoft Windows XP - DiskPart - Microsoft XP Pro documentation on the DiskPart command. Lots of good and helpful stuff here.

A Description of the Diskpart Command-Line Utility - Microsoft KB300415 in all its illustrative glory.

Using Diskpart to create, extend or delete a disk partition - Great post by Tim Fenner of WinComputing on using Diskpart to create a partition, extend a partition, delete a partition, and finally, wiping (zeroing out) a disk with diskpart.

Kinda-Related Links -- Good to know

Oscdimg Command-Line Options - Microsoft TechNet info on the Oscdimg command. This is the one used to build the ISO image file for the WinPE 2.0 disk you must make.  TIP: if you try to burn a DVD sized ISO with the normal instructions it will error out.  You must use the undocumented "-m" argument in your string to force it to build the ISO over the normal CD-sized ISO size.  Use the -m switch to override the creation of ISO images larger than 700 MB

Example:

oscdimg -n -h -m -bc:\winpe\etfsboot.com c:\winpe\iso c:\winpe\winpe.iso

Why would this be important?

Well, if your imagex wim image is about 3.4 GB or less, you can actually include it in the WinPE 2.0 ISO build process and have your image on the same DVD as your WinPE boot disk with ImageX.  Great time saver. 

I'll have to do a walkthrough guide on this soon as it is pretty easy and really cool once you got the steps in front of you.

Repair XP - Tons of XP Repair "How To" resources and links for doing just about all kinds of repairs on an XP system.  Great stuff to bookmark.

--Claus

1 comment:

Anonymous said...

WOW! Claus, once again you have put me in overdrive to check out all these great tools. I'm in Linux most of the time now but I return to WinXP every now and then so I'll be check out these tools. Thanks for all you do to help us out here!!!

Harmon