WMI query to select disk containing system volume - wmi

I need to get some information (model and serial) of the disk that contains the system volume (usually C:). I'm using this query:
SELECT * FROM Win32_DiskDrive WHERE Index=0
My question is, is the disk with Index=0 always the disk containing the system volume?
Edit: I added an additional query to get the index of the disk containing the boot partition:
SELECT * FROM Win32_DiskPartition WHERE BootPartition=True
Then the original query changes to
SELECT * FROM Win32_DiskDrive WHERE Index={diskIndex}
I figured I'd be pretty safe this way. Suggestions for better solutions are always welcome :)

As stated, add an extra query to get the index of the disk containing the boot partition:
{diskIndex} = SELECT * FROM Win32_DiskPartition WHERE BootPartition=True
SELECT * FROM Win32_DiskDrive WHERE Index={diskIndex}
Unfortunatly WMI doesn't seem to support JOINs, which would have made the query a little more efficient.

My question is, is the disk with Index=0 always the disk containing the system volume?
In my case the answer is No. My system disk has index 1.
Also your assumption that the system disk is always bootable is incorrect.
$ wmic os get "SystemDrive"
SystemDrive
C:
$ wmic logicaldisk where 'DeviceID="C:"' assoc /resultclass:Win32_DiskPartition
...\\DZEN\ROOT\CIMV2:Win32_DiskPartition.DeviceID="Disk #1, Partition #0"...
wmic diskdrive where 'Index=1' get "Caption"
Caption
OCZ-VERTEX4 // Yes, this is my system disk.
Also your assumpion about BootPartition usage is incorrect for cases when bootmanager is on another disk, like in my case:
wmic partition where 'DeviceID like "Disk_#1%"' get DeviceID,BootPartition
BootPartition DeviceID
FALSE Disk #1, Partition #0
wmic partition where 'BootPartition="TRUE"' get DeviceID,BootPartition
BootPartition DeviceID
TRUE Disk #4, Partition #0
TRUE Disk #3, Partition #0
As you can see, nor the system disk neither one of bootable ones do not have Index=0 for my case. Actually I have Index=0 for the one of non system and non bootable disk.

Related

Dynamo throughput not reaching provisioned level - using Hive and EMR 5.2

We're using Hive running on EMR 5.2.0 to run many many files to a Dynamo table. The provisioned throughput on the table is 3000 writes per second.
We are only able to hit 2000 writes regardless of the throughput percentage that is set in the Hive script.
The Hive execution engine is set to mr, and the dynamo.throughput.read.percent is set to 1.0.
We use the EMR to run the step using command-runner. Thus far we're unable to find any reasons why it's only using 2/3 of the provisioned writes.
Any advice or help would be greatly appreciated, thanks.
Edited to add hive script:
SET hive.execution.engine=mr;
DROP TABLE IF EXISTS s3_import;
DROP TABLE IF EXISTS dynamo_import;
CREATE EXTERNAL TABLE s3_import(fld string, dateRef string)
ROW FORMAT
DELIMITED FIELDS
TERMINATED BY ','
ESCAPED BY '\\'
LOCATION 's3n://${s3Path}';
CREATE EXTERNAL TABLE dynamo_import(fld string, dateRef string)
STORED BY 'org.apache.hadoop.hive.dynamodb.DynamoDBStorageHandler'
TBLPROPERTIES ("dynamodb.table.name" = '${tableName}',
"dynamodb.throughput.read.percent" = '${rp}',
"dynamodb.throughput.write.percent" = '${wp}',
"dynamodb.column.mapping" = "fld:fld,dateRef:dateRef");
INSERT OVERWRITE TABLE dynamo_import SELECT * FROM s3_import;
Edit:
If I run two applications in parallel that use 0.5 as the write throughput we're able to achieve the optimal writes within the provisioned amount, this leads me to think that there may be a setting o the cluster that is causing the problem?
The read and write percent settings are best effort rate limiters. The DynamoDB connector estimates the read and write capacity based on an item size heuristic and may not always get it right. That's why you can actually "over provision" reads and writes up to 1.5 (150%) so you should try that.
The other thing that can actually cause your write capacity to not hit the provisioned limit is the presence of hot-spots in the key space. If there are more items in one partition than others then the utilization will be uneven and you will hit throttling on (one or two partitions) even though you're not using the full provisioned rate for the whole table. With 3000 write capacity units and some reads, your table has at least 4 partitions so this can definitely be a factor.

How can I get volume name for EFI system partition?

I have a Windows machine with GPT drives.
I have a DOS device name of EFI system partition as output from bcdedit.
I want to open handle for this partition and get DOS name by QueryDosDevice() to compare with DOS name which I already have.
I tried to use FindFirstVolume/FindNextVolume to find volume name to get DOS name from QueryDosDevice, but I didn't find volume for EFI system partition. WMI also doesn't have volume for this partition.
How can I get volume name of EFI system partition from C++ code to use it in QueryDosDevice?
Try this. Download and install WinObj (from MS technet). Look through the \Device directory for the logical device name of the EFI system partition. Note that logical device names in the \Device directory are of the form \Device\Harddisk<N>\Partition<M> where N is the harddisk number and M is the partition number. Note M equal to zero means whole harddisk, and M > 0 refers to individual partitions. THe number N is the same number you will see in disk manager (diskmgmt.msc) and in diskpart.
Once you get the logical device name look in the \GLOBAL?? directory for an alias to that name. If you find an alias, then you're good to go. If you don't find an alias, then you'll need to use a Win32 API that can access \Device names. I think there is at least one such API, because I wrote a program many years ago that took \Device names as an argument.

Get the partition type of a specific partition in C++, on a GPT disk

I'm working on a project which requires me to operate at a low level on Windows drives, and am doing so primarily using Windows API calls. But before I can operate on the drive, I need to know the types of partitions present on it.
This is fairly simple on a disk formatted by MBR, because
DeviceIoControl(...,IOCTL_DISK_GET_DRIVE_LAYOUT_EX,...);
returns a structure in format DRIVE_LAYOUT_INFORMATION_EX, which contains an array of PARTITION_INFORMATION_EX. On an MBR disk, the PARTITION_INFORMATION_EX.Mbr.PartitionType element contains a unique identifier for the partition type, e.g. for NTFS it is 0x07, for Extended it is 0x05.
However, this isn't so simple on a GPT disk. I know that I can read the identifier off of the beginning of the partition, but I'd prefer to handle this with API calls, such as DeviceIoControl. When I run DeviceIoControl on a GPT disk, the PARTITION_INFORMATION_EX.Mbr.PartitionType contains completely different values than those which would be normally there.
Note that the GUID is useless to me because that only tells me the purpose of the partition, not what type of partition it is. I'm trying to figure out if the drive is NTFS, FAT, etc.
For GPT partition in your code when you call DeviceIoControl(), this call will return the Partition information in the object of PARTITION_INFORMATION_EX. If you see the PARTITION_INFORMATION_EX structure, there are two separate structure for MBR and GPT disk. So when you get the information in PARTITION_INFORMATION_EX object, you'll have to first confirm that whether the disk type is GPT or MBR, if GPT you can get the specific partition type by comparing it's GUID.
Look at Microsoft's PARTITION_INFORMATION_GPT struct for GPT partitions.
Instead of going through PARTITION_INFORMATION_EX, I found the best way to find the filesystem of a volume is to call GetVolumeInformation. On Vista+, this seems to be just a wrapper for GetVolumeInformationByHandleW. The later might be the best for you if you already have a volume handle.
Both work well with either MBR or GPT disks. The result is the filesystem name string instead of a type ID, but should be easy to adapt.

how to differentiate between GPT dynamic and GPT basic disk in a virtual machine programatically

Recently I had to find out a way to differentiate what partition type the virtual machine used,Reading the raw data from the virtual disk I was able to find it by checking with offset 1C2 (EE in case of GPT), in case of MBR disk if the disk is dynamic the offset at 1C2 had 42 and in case of basic disk the same 1C2 offset had 07 which means basic disk , now If it is a GPT disk how do I differentiate between basic and dynamic disks.
Thanks in Advance.
While iterating the GPT partition table entries for a GPT disk, search for an entry with "Partition type GUID" set to 5808C8AA-7E8F-42E0-85D2-E1E90434CFB3 and the corresponding hidden "attribute" (bit 62) for this entry should be set. This PTE would be for the LDM database. Besides this, there should be one more partition table entry for LDM itself. So in all, there'd be 2 partition table entries for this scenario, one for LDM database (hidden partition) and the other of LDM.

Read Extended Boot Record in windows c++

I am trying to read the extended boot record. The location of the extended boot record is i suppose at the first sector from absolute start offset.
First i read the MBR (Master Boot Record) to get the partition info i get the extended partition start offset,partition number and total length of partition.
I want to know how to figure out which partition is the first logical drive for that extended partition and in case of the partition being extended partition is there any metadeta stored after the MBR as well??
Is there a way i can get this information ??
Thanks
Is there a way