![]() |
![]() |
![]() |
![]() |
![]() |
kpartx serves as an advanced counterpart to losetup. For instance, if you've created an image file with the contents of an entire disk (including multiple partitions) using the dd command, you can use kpartx to access the contents of the original disk without having to restore the image file back to a physical disk.
The usage of kpartx is similar to losetup. The syntax is kpartx [-adv] image-file. The "-a" option associates the image file with loop devices, the "-d" option removes loop device associations, and the "-v" option displays detailed loop device mapping.
# dd if=/dev/zero of=1g-image bs=1G count=1 ←Create a 1GB image file "1g-image" add map loop1p1 (253:0): 0 1046528 linear /dev/loop1 2048 add map loop1p2 (253:1): 0 1046528 linear /dev/loop1 1048576 |
The final step in the above sequence demonstrates how to use kpartx to access the content of the original disk through the image file. After these operations, "/dev/loop1p1" corresponds to the original disk's first partition, and "/dev/loop1p2" corresponds to the second partition.
For more operations, examples, and explanations, you can refer to this link.