Jump to content

Diskpart recognizes disks differently


jmueske

Recommended Posts

I'm using a UFD (USB Flash Drive) with WinPE 2.0 and ImageX to deploy an XPe image. Here's what I'm doing:

1) Install UFD and SATA hard disk into system with power off.

2) Power on and boot PC to BIOS boot drive menu with F12, select UFD with WinPE 2.0 (both SATA drive and UFD are considerd hard drives by the BIOS).

3) Use diskpart to prepare hard disk:

diskpart /s d:\script.txt

select disk 0

clean

create partition primary

select partition 1

active

exit

4) format c: /fs:ntfs /y /v:harddisk

5) d:\imagex.exe /apply d:\filename.wim 1 c:

I run into a problem when using a brand new harddisk compared to a previously initialized harddisk. Diskpart sees a previously initialized harddisk as "drive 0" and the UFD is "drive 1". Diskpart sees only the UFD as a "drive 0" when a brand new empty harddisk is installed. As you can imagine this messes up my diskpart script because it wipes my UFD clean when a new hard disk is installed.

Can I get diskpart to look at both drive states the same way without externally initializing each harddisk? Ideally my scripts can "autosense" the harddisk in both drive conditions and work properly accordingly. Any ideas?

Regards,

John

Edited by jmueske
Link to comment
Share on other sites


  • 1 month later...

Thanks for the tip. I've literally searched for hours and while I can find other diskpart issues, I cannot find one similar to my own. Can someone point me in the right direction, perhaps with a specific post?

Regards,

John

Edited by jmueske
Link to comment
Share on other sites

You could use a batch or similar file to utilize diskpart scripting to find what disk # your hard drive or UFD device is and create your clean and partition script accordingly. The easiest way is if you know the size of your UFD device will always be the same. Then you could:

1. Run a diskpart script that runs the "list disk" command and read the output

2. Look for the line with the size value of your UFD device, and find the "Disk #" value for that device

3. Create the diskpart script to clean and partition using the other disk #

Here's an example of a batch file for a 256MB UFD that shows up as 246MB in diskpart:

echo list disk > X:\ListDisk.txt
FOR /F "tokens=2,4" %%i IN ('diskpart /s X:\ListDisk.txt') DO @IF /i %%j == 246 SET UFDDISK=%%i
IF DEFINED UFDDISK IF %UFDDISK%==0 SET THEDISK=1
IF DEFINED UFDDISK IF %UFDDISK%==1 SET THEDISK=0
IF DEFINED UFDDISK echo select disk %THEDISK% > X:\PartHD.txt
IF DEFINED UFDDISK echo clean >> X:\PartHD.txt
...
IF DEFINED UFDDISK diskpart /s X:\PartHD.txt

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...