Jump to content

DiskPart Logic?


Coucher

Recommended Posts

Guys, I've run into a problem that I need some help with. I'm not using an image server to do imaging. I use an image hdd (80gb hdd with WinPE and all my WIMs on it). All of my imaging is done on laptops (IBM/Lenovo Thinkpads to be exact). I put the image hdd in an ultrabay tray (removable hdd tray that goes into the CD/DVD bay) and into the Thinkpad. F12, select hdd1 as the boot device, and boot into PE. Works great and is VERY fast. Once PE loads I of course am at an X: prompt. I change to a C: prompt which is my PE hdd and then execute a CMD file(partition.cmd) which starts diskpart /s partition.txt which does the following:

select disk 0
clean
create partition primary size=10000
select partition 1
active
format FS=ntfs label="C_Drive" quick
exit

Now I'm back at my PE hdd C: prompt. I then have several CMD files for automating the image process based on the specific model of the machine.

The problem I'm running into is that it's a 50/50 shot once you're actually in PE as to how PE see's the hdd's, regardless of how the BIOS saw them. For instance the WinPE hdd is always hdd1 in the BIOS boot list, however sometimes once booted into PE, PE see's the hdd's the opposite way. The Thinkpad's hdd is hdd1 according to PE, and the image hdd is now hdd0, so when I execute the script to clean and format "hdd0" it ends up wiping the image disk if on that particular boot PE sees it as hdd0 rather than hdd1. I'm wanting to try to write some logic to do some fashion of check first before invoking the disk part command, but not really sure at which point to do so, or what information I can use to key off of. Thoughts?

Thanks in advance.

Link to comment
Share on other sites


pe does mix up the partitioning. When running diskpart, select drive 1 partition 1 and assign a new drive letter except c: then assign disk 0 partition 1 as c:.

As a check, in your cmd file, do if exist c:\*.* or c:\[Wim Directory]\*.* goto blah blah if it contains data then do it for the other partition, if it finds a blank drive then use that drive letter to deploy your image to.

Link to comment
Share on other sites

pe does mix up the partitioning. When running diskpart, select drive 1 partition 1 and assign a new drive letter except c: then assign disk 0 partition 1 as c:.

As a check, in your cmd file, do if exist c:\*.* or c:\[Wim Directory]\*.* goto blah blah if it contains data then do it for the other partition, if it finds a blank drive then use that drive letter to deploy your image to.

I follow your logic above and agree with it. However the difficult thing is the drive letter never changes. Whether the "PE hdd" shows up in PE as hdd0 or hdd1, it still shows up as C: drive letter. So whatever error checking I do has to somehow identify whether it's hdd0 or hdd1. :wacko:

Link to comment
Share on other sites

Well the way I would do it is either through WMI or some file parsing. I don't know exactly what to query with WMI off the top of my head, so I'll explain the file parsing. Your PE HDD should have a unique disk ID that never changes. So I would use diskpart to get the device id of disk 0. Something like, diskpart /s gethdd0id.txt > output.txt:

select disk 0
detail disk

Parse through output.txt to see if the disk id matches your PE HDD. If it does then the local hdd is disk 1, if not its disk 0. Then create a new diskpart script based off your results from the parsing of output.txt.

Edited by zorphnog
Link to comment
Share on other sites

for /f "tokens=1,2 delims=:" %%a in ('diskpart /s disk.txt') do (
if "%%a"=="Disk ID" (
if NOT "%%b"=="YOUR DISK ID" (
diskpart /s wipedisk0.txt
) else (
diskpart /s wipedisk1.txt
)

disk.txt

select disk 0
detail disk

wipedisk0.txt

select disk 0
clean
create partition primary size=10000
select partition 1
active
format FS=ntfs label="C_Drive" quick
exit

wipedisk1.txt

select disk 1
clean
create partition primary size=10000
select partition 1
active
format FS=ntfs label="C_Drive" quick
exit

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