How to find partition number or starting offset given volume attributes?

To clone a partition using dd.exe which comes with MSYS2 for Windows, we require 3 pieces of information.

  1. physical drive name
  2. partition starting offset (in MiB)
  3. partition size (in MiB)
dd if=physical_drive_name of=backup.img bs=1M skip=starting_offset count=size status=progress

To list available physical disk drives, we can use the command:

wmic diskdrive get Caption,Index,MediaType

On my system, it outputs:

Caption                    Index    MediaType
PC SN530 NVMe WDC 512GB    0        Fixed hard disk media
PNY USB 3.0 FD USB Device  1        Removable Media

I am interested in my NVMe drive, so I will use its index (0) to find requirement #1 which is physical drive name:

wmic diskdrive where "Index=0" get DeviceID,Partitions,Status,MediaLoaded

it outputs:

DeviceID            MediaLoaded  Partitions  Status
\.PHYSICALDRIVE0  TRUE         8           OK

The 2 other requirements are partition starting offset and partition size. To list partitions and their attributes, I’ll use the command:

wmic partition where "DiskIndex=0" get Name,Index,Type,StartingOffset,BlockSize,NumberOfBlocks,Size

It outputs:

BlockSize  Index  Name                   NumberOfBlocks  Size          StartingOffset  Type
512        0      Disk #0, Partition #0  614400          314572800     1048576         GPT: System
512        1      Disk #0, Partition #1  727875584       372672299008  449839104       GPT: Basic Data
512        2      Disk #0, Partition #2  225282048       115344408576  373123186688    GPT: Basic Data
512        3      Disk #0, Partition #3  102400          52428800      488467595264    GPT: Basic Data
512        4      Disk #0, Partition #4  2123776         1087373312    488520024064    GPT: Unknown
512        5      Disk #0, Partition #5  2027520         1038090240    489609494528    GPT: Unknown
512        6      Disk #0, Partition #6  39032832        19984809984   490647584768    GPT: Unknown
512        7      Disk #0, Partition #7  2883584         1476395008    510633443328    GPT: Unknown

So now, we can use the starting offset and size of the partition of our choice with dd.exe to clone it. However, this output does not give us a hint on the contents of the partitions. For that, we need to list volumes so that we can view the filesystems and labels of formatted partitions:

wmic volume where "DriveType=3" get Label,DeviceID,DriveLetter,DriveType,SerialNumber,FileSystem,MaximumFileNameLength,BlockSize,Capacity,FreeSpace

It outputs:

BlockSize  Capacity      DeviceID                                           DriveLetter  DriveType  FileSystem  FreeSpace     Label        MaximumFileNameLength  SerialNumber
4096       372672294912  \?Volume{41d21340-a487-4021-9735-3e999ccfc734}  C:           3          NTFS        232339791872  OS           255                    3295242676
                         \?Volume{e5ffe5ea-3596-468c-832f-e5bcf2aeb39e}               3
512        48234496      \?Volume{5792630e-1c80-4d8a-a679-82ec4cd0ecdc}               3          FAT32       39666176      GRUBX64      255                    716055397
4096       1087369216    \?Volume{19df495f-4e17-41fb-bcb0-d33d40588153}               3          NTFS        161165312                  255                    1445116501
4096       1038086144    \?Volume{9e1ca148-9cff-4576-ba37-cad1aab53ba1}               3          NTFS        501415936     WINRETOOLS   255                    4141927052
4096       19984805888   \?Volume{0e8ffde2-0844-4d79-ada2-a3ea534dcc6b}               3          NTFS        136228864     Image        255                    3940616972
4096       1476390912    \?Volume{a847a1f9-be5e-4f38-80ff-e5617868e2a1}               3          NTFS        505286656     DELLSUPPORT  255                    1554162235
4096       310378496     \?Volume{9685da03-f3a8-4f89-88f2-1b9dafc3bd38}               3          FAT32       203812864     ESP          255                    684405683

Now if we can determine the partition number of the volume of our interest, we can refer to the partition table to find the starting offset and size to use them with dd.exe, but how can we do that?

The reliable (unique) volume attributes are serial number, deviceID and (label and drive letter if any). size in general is not reliable as 2 or more partitions may have the same size.

Suppose the volume of our interest is DELLSUPPORT, how do we find its partition number so that we can find its starting offset and size to use with dd.exe?

1

I found a solution using Powershell:

1-List physical disks:

Get-Disk

2-List partitions of disk number 0:

Get-Partition -DiskNumber 0

3-List volumes on disk number 0 partitions :

Get-Partition -DiskNumber 0 | Get-Volume

4-Include FileSystemType and FriendlyName volume attributes in the partition table:

Get-Partition -DiskNumber 0 | Select-Object PartitionNumber,DriveLetter,Offset,Size,type,
@{Name="FileSystemType";Expression={(Get-Volume -Partition $_).FileSystemType}},
@{Name="FriendlyName";Expression={(Get-Volume -Partition $_).FileSystemLabel}} | Format-Table -AutoSize

To copy disk with dd you do not need a physical drive name. You need to specify a source file, but would that be a physical drive name, logical drive name or an actual file – does not matter.

If you want to make a backup of a partition, you need to specify a logical name for that partition. To get them, you need to use a standard tool fdisk:

# to get all partitions of all physical disks:
fdisk -l 
# to get partitions just for the primary hard drive:
fdisk -l /dev/sda

Another wrong assumption about dd: You do not need to specify partition start and size. If you want a whole partition – you just need a name. If you specify start and size – you will get just a segment of that partition.
So to make a backup of the boot partition all you need is:

dd if=/dev/sda1 of=backup.img

Also it is not a good idea to mix tool chains (dd is from msys2, wmic is from windows management). Possible, but leads to a lot of confusions and unnecessary conversion of data. If you started to use msys2 tools – use them. If wmic is more to your liking – use windows’ own backup tools.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật