gparted - Any way to make partitioning tools see kpartx-created devices?

05
2014-04
  • Harry

    I have a dd'ed disk image file with me.

    I can use a tool like kpartx to create a device-mapper device from this disk image file.

    But partitioning programs like gparted and fdisk don't list my mapped device!

    Is there any way to make gparted (or an equivalent program - graphical or console) list my mapped device and its constituent partitions and detailed information about these partitions?

    PS: Is this a case of missing feature from these tools, or is it that providing this feature is fundamentally not possible?

  • Answers
  • grawity

    It is possible, but I am not sure if it makes sense.

    Partitioning tools only care about the whole-disk device, because they read the partition table directly from the relevant disk sectors. They don't need per-partition devices to exist. This means that a basic loop device made with losetup is enough, and if a tool doesn't see it, you can just manually run fdisk /dev/loop0 or something.

    (If a whole-disk device is in /dev/mapper/, it's not hard to make those tools see it, although it usually involves editing a few lines of the source code... running fdisk /dev/mapper/bleh is often easier.)


    Also note that recent kernels support losetup --partscan which removes the need to use device-mapper for this.

  • Alex Offshore

    Just create temporary hardlink after running kpartx -a ...:

    sudo ln /dev/loop0 /dev/mapper/loop0
    

    And then run gparted as usual (it will properly operate /dev/mapper/loop0p*):

    sudo gparted /dev/mapper/loop0
    

    Don't forget to remove link when its not needed anymore.


  • Related Question

    partitioning - Why does partition tool GParted read the 190GB of data twice when shrink a 250GB partition to 190GB?
  • 動靜能量

    When using GParted to shrink a 250GB partition to 190GB, I thought it will move the 60GB of data back into the 190GB region and call it done.

    But instead it reads the 190GB of data twice, the first time taking about 1 hour and the second time for 2 hours.

    The question is:

    1) how come it touches the 190GB of data instead of the 60GB of data?
    2) how come it reads it twice?

    Update: i am suspecting this: it says "moving /dev/sdb1 to the right and then shrink it to 190GB"... so is that the reason, first it is to shrink the partition to 190GB, and then move it to the right? So it is not moving to the right and then shrink it, but to shrink it first and move it. (cannot move first because the original 250GB is the whole hard drive). Also, why move it to the right?


  • Related Answers
  • Florian Jenn

    Regarding #2 (reading twice):

    If I recall correctly, it performs a read test first. I think that's to make sure that there are no “surprises” during the actual move (read and write operations). You don't want to end up with your file system sawn up in two pieces.

  • 動靜能量

    This might be an answer: (I found that when all actions are completed)

    When "details" in GParted is clicked on, it shows the 2 actions (resize and create new partition), but when the individual action is clicked on, there are more details. It actually shows that there were operations like "reading /dev/sdb1 for errors and (if possible) fix them". It actually contains about 14 lines... with the first line "calibrate /dev/sdb1", which might be what the first 10 minutes was about.