How are phyical disks allocated their Disk Numbers?


  1. Posts : 221
    Windows 10 Pro 64 bit (22H2)
       #1

    How are phyical disks allocated their Disk Numbers?


    I think this might be a hardware issue which is why I have posted here, but happy for a mod or admin to move it somewhere else for appropriate if necessary.

    First an explanation... I am trying to arrange things so that a specific, permanently connected USB-HDD is not visible in to users during the day, only coming online after-hours to run a backup, then going offline again. For this I am using two batch files to run Diskpart to online or offline the disk as required. These batch files are run using the Task Scheduler with Admin privileges.

    DiskOn.bat contains the line... diskpart /s C:\DriveOnOff\diskpart-on.txt and the text file diskpart-on.txt is in the same folder. That text file contains the lines select disk 5 and online disk (off-lining the disk is a similar but reversed process).

    The physical disk numbers are almost always...
    Disk 0 is C:\ (250GB HDD)
    Disk 1 is D:\ (500GB HDD)
    Disk 2 is A:\ (500GB HDD)
    Disk 3 is F:\ (1TB HDD)
    Disk 4 is G:\ (1TB HDD)
    Disk 5 is B:\ (4TB USB-HDD)

    Most times this works perfectly, but the problem is, while disks 0 to 4 are always the same disks with the same physical disk numbers, sometimes the 4TB HDD comes up as Disk 10, with all the other physical disk numbers between 4 and 9 empty.

    Microsoft DiskPart version 10.0.19041.964
    Copyright (C) Microsoft Corporation.
    On computer: HOME
    DISKPART> list disk
    Disk ### Status Size Free Dyn Gpt
    -------- ------------- ------- ------- --- ---
    Disk 0....Online..........232 GB 2048 KB
    Disk 1....Online..........465 GB 1024 KB
    Disk 2....Online..........465 GB 1024 KB
    Disk 3....Online..........931 GB.....0 B
    Disk 4....Online..........931 GB.....0 B
    Disk 5....No Media............0 B.....0 B
    Disk 6....No Media............0 B.....0 B
    Disk 7....No Media............0 B.....0 B
    Disk 8....No Media............0 B.....0 B
    Disk 9....No Media............0 B.....0 B
    Disk 10..Offline........3726 GB 1024 KB
    DISKPART>

    I have been unable to replicate this issue. Having another USB stick plugged in on restart doesn't cause the issue, it just comes up as Disk 11.

    AIUI the physical disk numbers are are allocated by Windows during boot up - with available fixed disks being numbered first, followed by removable disks, so since I have five fixed disks (0 to 4) the removable disk should always be the sixth disk (Disk 5). I can't understand why it would skip over empty spaces and enumerate the USB-HHD as Disk 10.

    Does anyone have any clues as to what might be happening?

    Does anyone have a better way of trying to do what I am attempting?
      My Computers


  2. Posts : 43,014
    Win 10 Pro (22H2) (2nd PC is 22H2)
       #2

    Hi, if it helps, you can assign a given drive letter (rather than number) to a single particular external disk e.g. using Disk Management. If you make that letter late in the alphabet, it will always be available to that disk.

    Maybe using that drive letter offers a way forward.

    You might also consider a method using the device hardware id:
    https://www.techwalla.com/articles/h...on-my-computer
    https://docs.microsoft.com/en-us/win...torage-devices

    Macrium Reflect, for example, offers this as an option when specifying the backup disk.

    This includes an example using Powershell:
    https://docs.microsoft.com/en-us/mem...ot/add-devices

    FWIW I came across this:
    https://docs.microsoft.com/en-us/win...-container-ids
    - but I don't know what a container id is... but may show assigning a disk number might not be so straightforward.
    Last edited by dalchina; 04 Jul 2022 at 07:53.
      My Computers


  3. Posts : 16,956
    Windows 10 Home x64 Version 22H2 Build 19045.4170
       #3

    You could output the DiskPart results to a text file and then use a For cmd to read each line of the file until it finds the 3726 GB entry and then, for that line, it saves the first section Disk 10 as a variable to be used in your further processing.

    Personally, I'd want to add in a further check by making the For cmd keep reading for other 3726 GB entries in case you ever have another disk of the same capacity connected. I would also give my backup disk a unique label so I could also use a wmic command to check that it was connected and to abort if it was not.

    All the best,
    Denis
      My Computer


  4. Posts : 4,595
    several
       #4

    something along these lines might give you an idea that you could adapt

    findphysical.cmd
    Code:
    @For /F Tokens^=2Delims^=^" %%A In ('WMIC LogicalDisk Where "DeviceID='%~d0'"^
     Assoc /AssocClass:Win32_LogicalDiskToPartition 2^>Nul^|Find "n."'
    )Do @For /F Tokens^=2Delims^=^" %%B In ('WMIC Path^
     Win32_DiskDriveToDiskPartition 2^>Nul^|Find "%%A"')Do echo %%B
     
     pause
      My Computer


  5. Posts : 1,770
    Windows 10 Pro (+ Windows 10 Home VMs for testing)
       #5

    Or perhaps use USBDeview's commandline options to disable/enable USB mass storage devices by drive letter, drive serial no, vendor ID/product ID, etc.?

    IMO using the drive's serial no. offers an immutable identification method.

    The commandline options also allows tests to determine availability of the drive (again by drive letter, drive serial no, vendor ID/product ID, etc.).

    Hope this helps...
      My Computer


  6. Posts : 221
    Windows 10 Pro 64 bit (22H2)
    Thread Starter
       #6

    Thank you all for the replies... there is a lot of food for thought.

    I hadn't realized it was possible to specify a drive by things such as serial numbers and device IDs etc. The Nirsoft USBDeview looks like a promising avenue to pursue first.
      My Computers


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 03:47.
Find Us




Windows 10 Forums