Jump to content

How to change CD drive letter but only when more than 1 CD drive exist


Recommended Posts

I have an unattended build that I use for installing server operating systems.

The build pauses at the disk configuraiton part of setup to manually have the user create the C: partition where the OS will be installed (I wish Microsoft would give us the ability to create a specific size partition for C rather than all or nothing in the winnt.sif answer file).

Once the OS has been installed my configuration scripts kick off. One of the scripts calculates the appropriate size for the swap file, creates a primary partition on the first disk set (mirrored) and then allocates the remainder of the drive as another primary partition for log files.

The next script forces the CDROM to operate as drive D: (I have relabeled this as Z: in a past life, but D: is our company standard drive for CDROM's at the moment).

The next script creates an E: drive on the second physical disk (RAID 5 set) for applications/data. This works very well when run on virtual machine and physical servers, but only when run locally from the CDROM drive. Unfortunately our datacenter is at a remote location and I often have to build servers via the HP iLO remote control boards by mounting an .iso across the network via the virtual media applet.

The problem I have when using the iLO boards is the Virtual Media applet creates a virtual CDROM drive that the OS sees as a second CDROM drive. Since the additional drive letters are not created prior to the OS installation, Windows assigns the physical CDROM drive as D: (which is fine) and the virtual CDROM as E:. This poses a problem later when my scripts try to create the disk drives. DiskPart will happily assign the E: drive to the disk partition that it creates, but since the OS has already assigned this drive letter to the 2nd CDROM, the OS gets confused and both the disk and CDROM become inaccessible.

Since I need to do this dynamically (ie: only when installing via an iLO) I've written some logic into the script that creates the E: drive to detect the presence of the virtual CDROM drive, but I can't figure out how to assign a different drive letter to it before my script tries to crate the E: drive as a disk drive.

I know that DiskPart sees hard drives as "Disk" and CDROM drives as "Volume". Currently I assign the CDROM drive letter by passing this text file to DiskPart:

select volume 0

assign letter=d

I was considering creating a second text file containing:

select volume 0

assign letter=d

select volume 1

assign letter=z

But I'm not sure whether the OS sees the virtual drive as a volume or a disk, so I'm not sure if this would work.

So my question is, how can I assign a drive letter from a batch script to a device that already has a drive letter assigned to it? ie: If the script detects the presence of the 2nd CDROM drive which the OS has already allocated as drive E:, how can I change this drive letter to Z: before proceeding with the DiskPart command?

Does this make sense or am I over-complicating something easy??

Cheers

Jeff

Link to comment
Share on other sites


If you hard code this option for 2 CD Drives having the same volume ID, you am going on the presumtion that this will work on every system. There may be times when the Hard Drive is not formatted yet and that is going to throw off your numbering. Also some machines see Memory Slots or Card Readers as being volumes even if there is nothing inserted. The MSI MS-163K does this and it screwed up my scripts as well.

You may be able to have a script that detects the number of CD Drives, and runs diskpart_script1 if one drive and diskpart_script2 if two drives.

AutoIT has a function called DriveGetDrive. Here is an example:

$var = DriveGetDrive( "cdrom" )
If $var[0] = 2 Then
Run( @ComSpec & " /c x:\windows\system32\diskpart.exe diskpart_script2.txt" )
ElseIf $var[0] = 1 Then
Run( @ComSpec & " /c x:\windows\system32\diskpart.exe diskpart_script1.txt" )
EndIf

This is an example, and i wrote this up real quick so I didn't test it. As the help file says, "The zeroth array element contains the number of drives".

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