Windows – Map drive letter to VolumeID

amazon ec2amazon-ebswindows

I've received the complaint…

Help! My I drive filled up on EC2-Server-1! Please give moar space!

However, when I remote on the the server before extending the volume, I find I cannot easily figure out which EBS volume I will need to extend.

When I run aws ec2 describe-instances --filters "Name=tag:Name,Values=EC2-Server-1", the relevant info found in $.Reservations.Instances.BlockDeviceMappings shows…

DeviceName Ebs
---------- ---
/dev/sda1  @{VolumeId=vol-0123;...}
xvdf       @{VolumeId=vol-0456;...}
xvdj       @{VolumeId=vol-0789;...}
xvdg       @{VolumeId=vol-0abc;...}
...

Following this guidance, I can see in Disk Management under Properties > General for Disk 2 (Drive Letter I) the Location value is Bus Number 0, Target Id 6, LUN 0. Looking this value up on the windows volume mapping table from the same page, we see the corresponding DeviceName is xvdg, which maps to vol-0abc.

So… great… now I just need to click through about 5 dialogue boxes every time I need to do this (or just fuzzy match on size from the AWS Console and Windows Explorer).

Is there terminal command (or series of commands) I can execute to retrieve this mapping quickly & reliably?

I'm currently rubber ducking my way through various wmic iterations, but… any chance this is a solved problem?

Best Answer

Yes, there is. PowerShell (with WMI) to the rescue:

Get-WmiObject Win32_DiskDrive | select-object DeviceID,size,scsiport,scsibus,scsitargetid,scsilogicalunit

This will leave you with:

DeviceID        : \\.\PHYSICALDRIVE9
size            : 234362882560
scsiport        : 3
scsibus         : 0
scsitargetid    : 2
scsilogicalunit : 4
Related Topic