windows xp - Diskpart script to assign driver letter and create 2 partitions

20
2014-04
  • JHamill

    I'm currently deploying Windows XP (don't ask why) across a corporate environment and have a requirement to partition the disk during the unattended build. the disk must contain two partitions:

    • C: will store the OS and should fill the remainder of the disk
    • D: will be a partition for user data and should be 20GB

    Diskpart is being used to prepare the disk for OS installation. WinPE appears to be assigning the DVD-ROM drive the letter D.

    Firstly, I'm executing diskpart with the following command to re-assign the letter given to the DVD-ROM drive:

    Select volume 0
    assign letter=e
    

    This appears to work as intended. Viewing the various volumes using Diskpart shows the DVD-ROM drive to be E:

    The next diskpart script aims to create the two partitions mentioned above. Below are the commands I'm currently using:

    select disk 0
    clean
    create partition primary size=20480
    select partition 1
    assign letter="D"
    
    create partition primary
    select partition 2
    assign letter="C"
    active
    exit
    

    The above command executes correctly but Windows XP fails to load. However when telling diskpart to create a single C: partition the OS loads fine. The image was captured using ImageX and was configured to only capture the contents of C. Because of this I do not believe the issue is in anyway related to how the image was captured.

    Thanks in advance for any guidance offered.

  • Answers
  • WinOutreach4

    In addition to the suggestions by Breakthrough and Karan, you could use the Microsoft Deployment Toolkit (MDT) for your imaging and deployment needs. In the task sequence you create to deploy your OS, you can have MDT partition and format the hard drive, and set it to a percentage of the drive. For example, you can set Drive C to 80% of the available drive space and set drive D to the remaining 20% (100% of the remaining space after the first partition is created).

    There are other benefits to using MDT for your deployments, such as installing software after the OS is deployed, managing device drivers and can be used for deploying Windows XP SP3, Windows Vista SP2, Windows 7, Windows 8 and Windows Server 2003 R2, Server 2008 SP2, 2008 R2, and 2012.

    Here is a great video that shows how MDT can benefit you and your organization with imaging and deployments: Deployment Day Session 1: Introduction to MDT 2012

    One final note, Windows XP End of Support is coming April 8, 2014. There will be no new hotfixes or patches developed for Windows XP after this date, which will leave your systems vulnerable to security risks. Read more about Windows XP EOS here.

    Hope this helps


  • Related Question

    recovery - Recovering a Partially Formatted USB Thumb Drive
  • Mark Tomlin

    I have a USB Thumb Drive that I was going to use to install Windows 7 with. While formatting the drive with the Windows 7 USB/DVD download tool it failed leaving my USB drive in an unusable state.

    I can see the drive with the Windows Disk Manager, but it shows that it has a RAW file system, and any time I try to reformat it a second time, it simply says that It can't find the file or partition. Using DiskPart I've also not had very much luck as trying to use the FORMAT command results in an error. These are the commands I'm using and their output.

    Microsoft Windows [Version 6.1.7601]
    Copyright (c) 2009 Microsoft Corporation.  All rights reserved.
    
    C:\Windows\system32>diskpart
    
    Microsoft DiskPart version 6.1.7601
    Copyright (C) 1999-2008 Microsoft Corporation.
    On computer: DYGEAR-PC
    
    DISKPART> list disk
    
      Disk ###  Status         Size     Free     Dyn  Gpt
      --------  -------------  -------  -------  ---  ---
      Disk 0    Online           14 GB      0 B
      Disk 1    Online           74 GB      0 B
      Disk 2    Online          698 GB      0 B   *
      Disk 3    Online           15 GB      0 B
    
    DISKPART> select disk 3
    
    Disk 3 is now the selected disk.
    
    DISKPART> detail disk
    
    Corsair Voyager Mini USB Device
    Disk ID: 00000000
    Type   : USB
    Status : Online
    Path   : 0
    Target : 0
    LUN ID : 0
    Location Path : UNAVAILABLE
    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 4                             Removable     15 GB  Healthy
    
    DISKPART> select volume 4
    
    Volume 4 is the selected volume.
    
    DISKPART> FORMAT RECOMMENDED OVERRIDE
    
    DiskPart has encountered an error: The system cannot find the file specified.
    See the System Event Log for more information.
    
    DISKPART> FORMAT FS=NTFS LABEL="Windows7" QUICK COMPRESS
    
    DiskPart has encountered an error: The system cannot find the file specified.
    See the System Event Log for more information.
    
    DISKPART>
    
    DISKPART> list disk
    
      Disk ###  Status         Size     Free     Dyn  Gpt
      --------  -------------  -------  -------  ---  ---
      Disk 0    Online           14 GB      0 B
      Disk 1    Online           74 GB      0 B
      Disk 2    Online          698 GB      0 B   *
      Disk 3    Online           15 GB      0 B
    
    DISKPART> select disk 3
    
    Disk 3 is now the selected disk.
    
    DISKPART> clean all
    
    DiskPart has encountered an error: Incorrect function.
    See the System Event Log for more information.
    
    DISKPART> list partition
    
    There are no partitions on this disk to show.
    
    DISKPART> online disk
    
    Virtual Disk Service error:
    This disk is already online.
    
    DISKPART> attributes disk clear readonly
    
    Disk attributes cleared successfully.
    
    DISKPART> clean
    
    DiskPart has encountered an error: Incorrect function.
    See the System Event Log for more information.
    
    DISKPART> convert mbr
    
    DiskPart successfully converted the selected disk to MBR format.
    
    DISKPART> create partition primary
    
    DiskPart succeeded in creating the specified partition.
    
    DISKPART> select part 1
    
    Partition 1 is now the selected partition.
    
    DISKPART> active
    
    DiskPart marked the current partition as active.
    
    DISKPART> format fs=NTFS label=USB quick
    
    DiskPart has encountered an error: The system cannot find the file specified.
    See the System Event Log for more information.
    
    DISKPART> format quick
    
    DiskPart has encountered an error: The system cannot find the file specified.
    See the System Event Log for more information.
    
    DISKPART> assign letter F
    
    DiskPart has encountered an error: The system cannot find the file specified.
    See the System Event Log for more information.
    
    DISKPART> list volume
    
      Volume ###  Ltr  Label        Fs     Type        Size     Status     Info
      ----------  ---  -----------  -----  ----------  -------  ---------  --------
      Volume 0     V   Video        NTFS   Simple       698 GB  Healthy
      Volume 1     D   SSD          NTFS   Partition     14 GB  Healthy
      Volume 2         System Rese  NTFS   Partition    100 MB  Healthy    System
      Volume 3     C                NTFS   Partition     74 GB  Healthy    Boot
    * Volume 4                             Removable     15 GB  Healthy
    
    DISKPART>
    

  • Related Answers
  • Mark Tomlin

    To attempt to recover a USB drive back to usable state, you should try these commands.

    First it should be noted that you should have Windows 7 installed on a computer that you have access to, so that you can use the diskpart command. You'll also need to have administrator access on this computer.

    1. Click on the Start Orb.
    2. Type cmd into the search box.
    3. Shift + Right Click on the CMD icon.
    4. Click on Run as Administrator.

    From here, we are going to type in diskpart and run the following commands.

    C:\Windows\system32>diskpart
    
    Microsoft DiskPart version 6.1.7601
    Copyright (C) 1999-2008 Microsoft Corporation.
    On computer: DYGEAR-PC
    
    DISKPART>
    

    From here we are going to type list disk to find the current drives connected to the computer.

    DISKPART> list disk
    
      Disk ###  Status         Size     Free     Dyn  Gpt
      --------  -------------  -------  -------  ---  ---
      Disk 0    Online           14 GB      0 B
      Disk 1    Online           74 GB      0 B
      Disk 2    Online          698 GB      0 B   *
      Disk 3    Online           15 GB      0 B
    

    The 15GB drive is the drive we are looking for, as that's the size of our USB Thumb Drive. So to select that drive, we run the command select disk 3.

    DISKPART> select disk 3
    
    Disk 3 is now the selected disk.
    

    If you are not sure if this is your drive, you can request details about the drive by running the command detail disk after you have selected the disk.

    DISKPART> detail disk
    
    Corsair Voyager Mini USB Device
    Disk ID: 00000000
    Type   : USB
    Status : Online
    Path   : 0
    Target : 0
    LUN ID : 0
    Location Path : UNAVAILABLE
    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 4                             Removable     15 GB  Healthy
    

    After we have correct drive, we can select any partitions on the drive select by doing select volume and then the volume number like in our case select volume 4.

    DISKPART> select volume 4
    
    Volume 4 is the selected volume.
    

    From here, we will try to recover the drive to a useable state. We are going to attempt to reformat the drive first. FORMAT RECOMMENDED OVERRIDE is the safest way to format your drive back to a normal state.

    DISKPART> FORMAT RECOMMENDED OVERRIDE
    
    DiskPart has encountered an error: The system cannot find the file specified.
    See the System Event Log for more information.
    

    Should that not work, such as shown above, we can try to run a format command that tells it how to format the drive in our case we use FORMAT FS=NTFS LABEL="Windows7" QUICK COMPRESS.

    DISKPART> FORMAT FS=NTFS LABEL="Windows7" QUICK COMPRESS
    
    DiskPart has encountered an error: The system cannot find the file specified.
    See the System Event Log for more information.
    

    In our case, this still does not work. So we attempt to clean the whole drive with the command CLEAN ALL.

    DISKPART> clean all
    
    DiskPart has encountered an error: Incorrect function.
    See the System Event Log for more information.
    

    If we still are having trouble with the drive at this point. Let's try and list the partitions again, see if any changes have been made to the drive with LIST PARTITION.

    DISKPART> list partition
    
    There are no partitions on this disk to show.
    

    As there as been a change, let's see if we can get the drive online with ONLINE DISK.

    DISKPART> online disk
    
    Virtual Disk Service error:
    This disk is already online.
    

    As the driver is online we can now try and clear any attributes that might be in our way such as the read only attribute. We run ATTRIBUTES DISK CLEAR READONLY.

    DISKPART> attributes disk clear readonly
    
    Disk attributes cleared successfully.
    

    Let's see if we can put a boot record on there with CONVERT MBR.

    DISKPART> convert mbr
    
    DiskPart successfully converted the selected disk to MBR format.
    
    DISKPART> create partition primary
    
    DiskPart succeeded in creating the specified partition.
    
    DISKPART> select part 1
    
    Partition 1 is now the selected partition.
    
    DISKPART> active
    
    DiskPart marked the current partition as active.
    
    DISKPART> format fs=NTFS label=USB quick
    
    DiskPart has encountered an error: The system cannot find the file specified.
    See the System Event Log for more information.
    
    DISKPART> format quick
    
    DiskPart has encountered an error: The system cannot find the file specified.
    See the System Event Log for more information.
    
    DISKPART> assign letter F
    
    DiskPart has encountered an error: The system cannot find the file specified.
    See the System Event Log for more information.
    
    DISKPART> list volume
    
      Volume ###  Ltr  Label        Fs     Type        Size     Status     Info
      ----------  ---  -----------  -----  ----------  -------  ---------  --------
      Volume 0     V   Video        NTFS   Simple       698 GB  Healthy
      Volume 1     D   SSD          NTFS   Partition     14 GB  Healthy
      Volume 2         System Rese  NTFS   Partition    100 MB  Healthy    System
      Volume 3     C                NTFS   Partition     74 GB  Healthy    Boot
    * Volume 4                             Removable     15 GB  Healthy
    

    As noted all of these commands failed from that point. So we should try one last thing to get the drive working again. In this case, what you should do is uninstall the drivers for the USB thumb drive and then reinstall the drivers again after restarting your computer.

    ---- I'm sorry this was half assed, I will work on this some more, but the Chromebook I am suing is freaking out right now with the javascript running on here because it is VERY SLOW TO type anything right now. I can type faster then it can display it.

  • slhck

    Use the HP Drive Key Boot Utility or HP USB Disk Storage Format Tool 2.2.3, command line or GUI version.

  • James T

    You could try to recover the old partition with testdisk. It might get you back to a point where the usb drive is usable again.

    You can try to format it using gparted from the live cd.

    I fixed a similar issue once using qtparted. For some reason no other partition manager was able to fix it at the time. It would probably be somewhat difficult to find a live cd that has qtparted... I think older versions of Knoppix have it.