Jump to content

Diskpart error when imaging Win7

Recommended Posts

I am attempting to run a light-touch to unattended imaging process from a USB, however i run into an error.

I am running an error during the assignment of a drive letters several lines into my batch script.

I have a 2 part imaging system that i call a batch file, and it runs through and is supposed to apply my wim as an image.

During the part that it calls to for diskpart as part of my imaging i get an error.

The initial batch is as follows:

diskpart /s part2.txt

copy u:\test.wim d:

x:\imagex.exe /apply d:\test.wim 1 d:

d:\windows\system32\bcdboot d:\windows


During the diskpart it calls to a text file for the diskpart commands noting:

select disk 0


create partition primary size=80

select partition 1

format fs=ntfs label="system" quick

assign letter=C


create partition primary

select partition 2

format fs=ntfs label="windows" quick

assign letter=D

select disk 1

select partition 1

assign letter=U


It goes throught the script all the way until it tries to assign drive letter D, then it throws an error.

Virtual Disk Service error:

The specified drive letter is not free to be assigned.

Thusly bunking my entire automation.

Everything works flawlessly if i run the entire diskpart section by hand, however it will not work in a diskpart batch.


Link to comment
Share on other sites

It is not at all clear to me your setup and the actual disk order.

And it seems to me like you are installing the Windows to the D: drive (while normally this is done to the C: one).

Can you try to explain/detail the general idea and setup?

If you boot from the USB, normally that device would be disk 0 (first disk) and the internal disk would be "shifted" to disk 1 but disk order in PE's is somewhat not "reliable", disk order (and consequently drive lettering) may change.

It is very possible that this happens, as a rule of thumb it would be "better" to check the environment (and disk order and drive letters already assigned) at the time you run diskpart.exe.

Something *like* this:



is normally useful.

As a side note (and only marginal) there is no need to have a separate diskpart script, it is possible to embed it in the same batch file, see (JFYI):




Link to comment
Share on other sites

I'll clarify...

I created a WAIK-based WINPE bootable UDF to USB, i placed my two scripts onto the USB, along with my image (captured) WIM file.

So i'm booting to the USB, and by default from what i'm seeing on 5 different computers, is that setting the booting the USB as DISK 1, by the configs of the WINPE.

I run the batch at launch by typing in "part1" which executes the batch file.

Line 1 of the file calls to the DISKPART script, but by the time it attempt to quick format the drive and assign it as "D", it reboots.

(I have no idea why, as i've not called to do so in the script)

If i follow the scripts line for line, it works perfectly. If i execute the batch, it blows up and reboots to the computers.

I REALLY don't want to have to do this manually, as everything i've seen online says you can do this through scripts.

I'm just not seeing it.


Link to comment
Share on other sites

Good, but still you didn't answer my questions.

Is there a specific reason why you want/need to install the windows on "D:"?

Anyway, when you have this kind of strange issues, try to separate things as much as possible (there will be time enough later to re-assemple them together) and insert in the middle some checks.


diskpart /s clean.txtECHO clean.txt ranmountvol | FIND ":\"PAUSEdiskpart /s part11.txtECHO part11.txt ranmountvol | FIND ":\"PAUSEdiskpart /s part01.txtECHO part01.txt ranmountvol | FIND ":\"PAUSEdiskpart /s part02.txtECHO part02.txt ranmountvol | FIND ":\"PAUSEcopy u:\test.wim d:x:\imagex.exe /apply d:\test.wim 1 d:d:\windows\system32\bcdboot d:\windowsexit


select disk 0cleanexit


select disk 1select partition 1assign letter=Uexit


select disk 0create partition primary size=80select partition 1format fs=ntfs label="system" quickassign letter=Cactiveexit


select disk 0create partition primaryselect partition 2format fs=ntfs label="windows" quickassign letter=Dexit

And see what happens.

Notwithstanding your successful experiments, if not downright criminal :w00t::ph34r: I find EXTREMELY dangerous to select a disk and "clean" it with diskpart in an automated setup without first checking if it is the "right" disk :whistle:.


Link to comment
Share on other sites

  • 1 month later...

Good, but still you didn't answer my questions.

Is there a specific reason why you want/need to install the windows on "D:"?

Hi! I allways install Windows in C:, never did de system part.

Basicaly, i do this:


sel disk 0


create part pri

sel part 1

assign letter c:



format c: /q /y /fs:ntfs /v:Windows

imagex /apply x:\windows.wim 1 c:

c:\windows\system32\bcdboot c:\windows /s c:


Work great, never had a problem. I just have another script more complex because many notebooks have cdrom like disk 1 or some card reader also.


Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    • No registered users viewing this page.

  • Create New...