Jump to content

Diskpart In WinPE


gadget

Recommended Posts

Sorry if I am in the wrong place...

I am using PE2005 as a primary deployment tool for our puters over here. Most options are fine and covered. Came across a scenario today that has stumped me.

I want to split a hard disk into 2 seperate primary partitions. The second partition needs to be 4096mb in size and reside at the end of the disk. The disks are of different sizes so I need to create the partition at the end of the drive first.

Previously we used gdisk in dos but the 32 bit version does not create new partitions.

As I said, this would be nice to follow our processes and run through winpe, I know about diskpart but I cannot find a way of creating the second partition first unless I work out the exact offset to start the partition from....

ANy help would be appreciated...

Link to comment
Share on other sites


Didnt take long.

Run a script to locate the size of the hdd in mb, took away 4096 and put in a dos variable %offsetsize% and run the diskpart command

create partition primary size=4096 offset=%offsetsize%

then created the first partition....

Link to comment
Share on other sites

Didnt take long.

Run a script to locate the size of the hdd in mb, took away 4096 and put in a dos variable %offsetsize% and run the diskpart command

create partition primary size=4096 offset=%offsetsize%

then created the first partition....

sorry to be a pest, but, could we view this script you used to find the size of the hdd? :thumbup

Link to comment
Share on other sites

this is one way

Const HARD_DISK = 3

strComputer = "."

Set objWMIService = GetObject("winmgmts:" _

& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colDisks = objWMIService.ExecQuery _

("Select * from Win32_LogicalDisk Where DriveType = " & HARD_DISK & "")

For Each objDisk in colDisks

msgbox "DeviceID: " & objDisk.DeviceID

msgbox "Disk Size: " & objDisk.size/1024/1024

Next

Link to comment
Share on other sites

Exactly the way we do it here.

Diskpart.txt would look like this:

select disk=0
clean
create partition primary size=<main>
assign letter=c
create partition primary size=<data>
select volume 0
select disk = 0
select partition 2
assign letter=d
remove noerr
select partition 1
active

Sizepart.vbs

Const ForReading = 1, ForWriting = 2, ForAppending = 3 
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
Const OPEN_FILE_FOR_APPENDING = 8
Set fso = CreateObject("Scripting.fileSystemObject")
Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_DiskDrive",,48)

For Each objItem in colItems
HD = int(objItem.Size/1000000000)
DATA = 4
MAIN = HD - DATA
DATA = ActualSize(DATA*1000)
MAIN = ActualSize(MAIN*1000)
Exit For
next

Set f = fso.GetFile("z:\diskpart.txt")
Set ts = f.OpenAsTextStream(ForReading, Tristatefalse)
t = ts.ReadAll
ts.Close
t = replace(t, "<main>", MAIN, 1, -1, 1)
t = replace(t, "<data>", DATA, 1, -1, 1)
Set objOutputFile = fso.OpenTextFile("z:\diskpart.txt", ForWriting)
objOutputFile.Write t
objOutputFile.Close


Function ActualSize(Size)
ActualSize=int(Size/1.024)
End Function

Function TheoreticalSize(Size)
TheoreticalSize = int(Size*1.024)
End Function

STARTNET.CMD would then contain:

copy x:\files\diskpart.txt z: > nul
cscript x:\files\sizepart.vbs
diskpart /s z:\diskpart.txt > nul
format c: /FS:NTFS /V:MAIN /q /y > nul
format d: /FS:NTFS /V:DATA /q /y > nul

You'll have to forgive my code.. I modified it for your scenario. Our situation is a little more complicated since depending on the size of the HD, our 3rd partition can either be 2GB or 40% of the drive.

Link to comment
Share on other sites

  • 4 weeks later...

ok, i finally found how to add a writable RAMdisk (and get my own little Z: drive)

(customized my PE : adding WMI support + script support + RAM disk support)

i am trying to use the vbs script above but i am stuck on the fifth line (GetObject)

> sizepart.vbs(5, 1) Microsoft VBScript runtime error: The remote server machine does not exist or is unavailable: 'GetObject'

What i have missed...?

Forget it I have completely restart the RAMdisk integration with the Johan Arwidmark procedure and now it is ok (with Christiaan Ghijselinck's RAMdisk files)

Edited by xponard
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...