Initializing disks from command line or DISKPART in Win 2008?
We have an automated process where we provision disks from our HP EVA 6000 storage array, present them to our Windows 2003 servers, then use a DISKPART script to create partitions and assign drive letters and mount points. The diskpart script goes basically like this:
RESCAN
SELECT DISK n
CREATE PART PRIMARY ALIGN=32
ASSIGN LETTER x:
EXIT

Now we've added some Windows 2008 servers, and this no longer works. Specifically, the create partition command fails, with diskpart saying the "media is write protected." Now, I know that we now have to execute ONLINE DISK, as disks initially are visible in an offline state. That's not sufficient. I can't create a partition until I go into Computer Management/Storage/Disk Management, select the new disk, and choose "initialize" from the right click menu. If I don't, the disk has no signature and the OS sees it as read only. Writing a signature always seemed to be implicit in Windows 2003, as we've run our process hundreds of times and never initialized a disk.

How can I initialize a disk within DISKPART? Alternately, is there a command line command to initialize? If we have to use a GUI tool, it will fatally break our automated process.
July 30th, 2008 5:55pm

I had the same problem when creating a cluster in Server Core. The command I used to remove the write protection wasdiskpart > select disk n > ATTRIBUTES DISK CLEAR READONLY

This should be possible to automate in your script and hence not break your automated process.
Free Windows Admin Tool Kit Click here and download it now
July 31st, 2008 8:00am

I did not find explicitly how to initialize a disk, but you might get away with writing a signature manually. Which means you need some sort of incrementing number/variable in your scripting:

RESCAN
SELECT DISK n
ONLINE DISK
UNIQUEID DISK ID=12345678

and then you partition commands

HTH,
Edwin.

PS full explanation of diskpart.exe on 2008 is here: http://technet2.microsoft.com/windowsserver2008/en/library/26a4a166-95fa-4faf-95bc-2d5345f4a57a1033.mspx?mfr=true
  • Marked as answer by David Shen Friday, August 01, 2008 7:20 AM
July 31st, 2008 11:05am

I did not find explicitly how to initialize a disk, but you might get away with writing a signature manually. Which means you need some sort of incrementing number/variable in your scripting:

RESCAN
SELECT DISK n
ONLINE DISK
UNIQUEID DISK ID=12345678

and then you partition commands

HTH,
Edwin.

PS full explanation of diskpart.exe on 2008 is here: http://technet2.microsoft.com/windowsserver2008/en/library/26a4a166-95fa-4faf-95bc-2d5345f4a57a1033.mspx?mfr=true
  • Marked as answer by David Shen Friday, August 01, 2008 7:20 AM
Free Windows Admin Tool Kit Click here and download it now
July 31st, 2008 11:05am

Joachim Nasslander said:

I had the same problem when creating a cluster in Server Core. The command I used to remove the write protection wasdiskpart > select disk n > ATTRIBUTES DISK CLEAR READONLY



As the kids say, WIN!

Given the new emphasis Windows 2008 has on everything-you-can-do-in-the-GUI-you-can-do-in-the-command-line, the omission of a well-defined method of initializing a disk within DISKPART seems particularly glaring.
  • Proposed as answer by Steve Jenness Friday, August 01, 2008 8:16 PM
July 31st, 2008 1:08pm

Joachim Nasslander said:

I had the same problem when creating a cluster in Server Core. The command I used to remove the write protection wasdiskpart > select disk n > ATTRIBUTES DISK CLEAR READONLY



As the kids say, WIN!

Given the new emphasis Windows 2008 has on everything-you-can-do-in-the-GUI-you-can-do-in-the-command-line, the omission of a well-defined method of initializing a disk within DISKPART seems particularly glaring.
  • Proposed as answer by Steve Jenness Friday, August 01, 2008 8:16 PM
Free Windows Admin Tool Kit Click here and download it now
July 31st, 2008 1:08pm

Diskpart (CLI) and Disk Management (GUI) functionality is not mapped one to one. This is by design. The GUI is designed to be easier to use for common usage patternsso it compounds fundamental operations into few clicks. Diskpart gives more granular control. So, sometimes you have to use multiple diskpart commands to get the functionality that you get from a single menu item in Disk Management.

For instance, onlining a disk in Disk Management also clears the readonly attribute. In diskpart, you have to do those two operations separately.
You don't have to explicitly set the disk signature (even on Windows Server 2008).

The suggested sequence for initializing a newly discovered disk that is offline is:

DISKPART> SELECT DISK n
DISKPART> ATTRIBUTES DISK CLEAR READONLY
DISKPART> ONLINE DISK
DISKPART> CONVERT MBR

This makes the disk read/write, online and with aMBR partition layout. The "CONVERT" command is equivalent to the "Initialize Disk" Operation in the Disk Management GUI.

If you use"DISKPART> CREATE PARTITION PRIMARY" in the place of "DISKPART> CONVERT MBR", the MBR initialization is done implicitly.


The equivalent Disk Management operations would be:

Right click on the disk in the bottom pane (click where it shows "Disk 1")
Select "Online"
(This brings the disk online and clears the readonly attribute making the disk read/write)
Right click in the same place again
Select "Initialize Disk"
Select the "MBR (Master Boot Record)" radio button and the "OK" button
(This creates the MBR partition layout)


Also, on Windows Server 2008, I'd suggest not specifying the ALIGN parameter on the CREATE PARTITION command unless you really need to. Windows Server 2008 has much better default alignment rules that prior releases. The default for most partitions is to create them on 1Mbyte alignment boundaries. This default alignment is good for all of the performance and large sector alignment scenarios that we currently know about.

Steve

  • Proposed as answer by Steve Jenness Friday, August 01, 2008 8:39 PM
  • Marked as answer by Malu Menezes Friday, August 01, 2008 11:19 PM
August 1st, 2008 8:39pm

Diskpart (CLI) and Disk Management (GUI) functionality is not mapped one to one. This is by design. The GUI is designed to be easier to use for common usage patternsso it compounds fundamental operations into few clicks. Diskpart gives more granular control. So, sometimes you have to use multiple diskpart commands to get the functionality that you get from a single menu item in Disk Management.

For instance, onlining a disk in Disk Management also clears the readonly attribute. In diskpart, you have to do those two operations separately.
You don't have to explicitly set the disk signature (even on Windows Server 2008).

The suggested sequence for initializing a newly discovered disk that is offline is:

DISKPART> SELECT DISK n
DISKPART> ATTRIBUTES DISK CLEAR READONLY
DISKPART> ONLINE DISK
DISKPART> CONVERT MBR

This makes the disk read/write, online and with aMBR partition layout. The "CONVERT" command is equivalent to the "Initialize Disk" Operation in the Disk Management GUI.

If you use"DISKPART> CREATE PARTITION PRIMARY" in the place of "DISKPART> CONVERT MBR", the MBR initialization is done implicitly.


The equivalent Disk Management operations would be:

Right click on the disk in the bottom pane (click where it shows "Disk 1")
Select "Online"
(This brings the disk online and clears the readonly attribute making the disk read/write)
Right click in the same place again
Select "Initialize Disk"
Select the "MBR (Master Boot Record)" radio button and the "OK" button
(This creates the MBR partition layout)


Also, on Windows Server 2008, I'd suggest not specifying the ALIGN parameter on the CREATE PARTITION command unless you really need to. Windows Server 2008 has much better default alignment rules that prior releases. The default for most partitions is to create them on 1Mbyte alignment boundaries. This default alignment is good for all of the performance and large sector alignment scenarios that we currently know about.

Steve

  • Proposed as answer by Steve Jenness Friday, August 01, 2008 8:39 PM
  • Marked as answer by Malu Menezes Friday, August 01, 2008 11:19 PM
Free Windows Admin Tool Kit Click here and download it now
August 1st, 2008 8:39pm

I am just adding to this just in case some people have not tried it out or the write-protected attributes clear didn't work for the disk.

In multiple attempts to "Attributes disk clear readonly" the disk never cleared the flag...  So i did:

DISKPART> List Volume
DISKPART> Select VOLUMENAME
DISKPART>Attributes Volume Clear Readonly


After doing that, the volume & not disk cleared the read only attribute and fixed my write-protected problem.  Good luck to all.
February 2nd, 2010 11:54pm

Followed the "equivalent Disk Management operations" verbatim.

When it comes to the section "Select "Initialize Disk""...there is no command "initialize" in the right click menu.  The command is not "grayed-out" either.  I am running Windows 2008 STD build and it is patched up to SP2.  I was in "dsikpart" but did not see a similar command.

This makes me curious if I missed something in the initial installation of the OS on the system.  Is this usnique to the differences of 2008 and 2008 R2?

Free Windows Admin Tool Kit Click here and download it now
October 8th, 2010 1:41pm

Hi Steve, 

I have a similar case here. I have 5 disk's mapped to the host all the disk are in Offline state. I was supposed to bring all the disk online one by one. I tried to set the SAN POLICY onlineall. But this is not working for me. 

 

Is it possible to bring all the disk's mapped to the host to online with out doing it manually. Can you add your comments on this.

 

Thanks

Elangovv

June 6th, 2011 6:33am

Just a heads up, we use EVA's as well (5000, 8000, 8100, 8400) and everything I have been told has been to do align=64, not align=32.

 

I didnt read the whole thread, but the diskpart command for initializing a disk is select disk x then ONLINE disk, then create partition primary align=64 (or 32 if you want)

Free Windows Admin Tool Kit Click here and download it now
June 6th, 2011 9:22pm

Son.Le almost has the answer above. However you need to use the command -

Attributes disk clear readonly

This will clear the readonly attribute equivelant of an initilise, you are then free to partition, format and do what ever, enjoy :o)

  • Proposed as answer by FurryMonkey Tuesday, May 01, 2012 8:23 AM
May 1st, 2012 8:22am

Son.Le almost has the answer above. However you need to use the command -

Attributes disk clear readonly

This will clear the readonly attribute equivelant of an initilise, you are then free to partition, format and do what ever, enjoy :o)

  • Proposed as answer by FurryMonkey Tuesday, May 01, 2012 8:23 AM
Free Windows Admin Tool Kit Click here and download it now
May 1st, 2012 8:22am

if you set

diskpart> san onlineall

it should by default online the disk

you can use

diskpart> online disk

to online the disk. you can create a batch script to do the same.

Regards

satish

May 1st, 2012 9:45am

Does this work for Windows 7 and 8?

I need a DOS script that will initialize and format up to 6 external USB drives at a time to NTFS. And, I need a similar script for exFAT. 

Currently, I am using the following for exFAT;

<<drive letter>>: /y/q/fs:exFAT/v:<<drive name>> && label <<drive letter>>: <<label name>> & <<drive letter>>: /y/q/fs:exFAT/v:<<drive name>> && label <<drive letter>>: <<label name>> & <<drive letter>>: /y/q/fs:exFAT/v:<<drive name>> && label <<drive letter>>: <<label name>> & <<drive letter>>: /y/q/fs:exFAT/v:<<drive name>> && label <<drive letter>>: <<label name>> & <<drive letter>>: /y/q/fs:exFAT/v:<<drive name>> && label <<drive letter>>: <<label name>> & <<drive letter>>: /y/q/fs:exFAT/v:<<drive name>> && label <<drive letter>>: <<label name>> & <<drive letter>>: /y/q/fs:exFAT/v:<<drive name>> && label <<drive letter>>: <<label name>> & <<drive letter>>: /y/q/fs:exFAT/v:<<drive name>> && label <<drive letter>>: <<label name>> & <<drive letter>>: /y/q/fs:exFAT/v:<<drive name>> && label <<drive letter>>: <<label name>> 

Is there a way to condense this redundant code to maybe some like the following?

<<drive letter through drive letter>>: /y/q/fs:exFAT/v:<<drive name-drive name>> && label <<drive letter through drive letter>>: <<label name>>

Thank you!!


Free Windows Admin Tool Kit Click here and download it now
March 16th, 2015 8:22pm

Does this work for Windows 7 and 8?

I need a DOS script that will initialize and format up to 6 external USB drives at a time to NTFS. And, I need a similar script for exFAT. 

Currently, I am using the following for exFAT;

<<drive letter>>: /y/q/fs:exFAT/v:<<drive name>> && label <<drive letter>>: <<label name>> & <<drive letter>>: /y/q/fs:exFAT/v:<<drive name>> && label <<drive letter>>: <<label name>> & <<drive letter>>: /y/q/fs:exFAT/v:<<drive name>> && label <<drive letter>>: <<label name>> & <<drive letter>>: /y/q/fs:exFAT/v:<<drive name>> && label <<drive letter>>: <<label name>> & <<drive letter>>: /y/q/fs:exFAT/v:<<drive name>> && label <<drive letter>>: <<label name>> & <<drive letter>>: /y/q/fs:exFAT/v:<<drive name>> && label <<drive letter>>: <<label name>> & <<drive letter>>: /y/q/fs:exFAT/v:<<drive name>> && label <<drive letter>>: <<label name>> & <<drive letter>>: /y/q/fs:exFAT/v:<<drive name>> && label <<drive letter>>: <<label name>> & <<drive letter>>: /y/q/fs:exFAT/v:<<drive name>> && label <<drive letter>>: <<label name>> 

Is there a way to condense this redundant code to maybe some like the following?

<<drive letter through drive letter>>: /y/q/fs:exFAT/v:<<drive name-drive name>> && label <<drive letter through drive letter>>: <<label name>>

Thank you!!


March 17th, 2015 12:19am

Hai , am try to initialize my new 500GB 7200 RPM HDD but unfortunatly cant initialize and showing 2048 gb only , in cmd promt showing an encountered incorrect function. please solve
Free Windows Admin Tool Kit Click here and download it now
March 21st, 2015 8:07am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics