Gibt es eine Möglichkeit, Partitionierungstools dazu zu bringen, von kpartx erstellte Geräte anzuzeigen?

Gibt es eine Möglichkeit, Partitionierungstools dazu zu bringen, von kpartx erstellte Geräte anzuzeigen?

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?

Antwort1

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.

Antwort2

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.

Antwort3

After 3.5 years I have another solution on that :)

wenn Sie keine Bedenken hinsichtlich der Verwendung von kpartx haben und ich mit meiner Annahme richtig liege, dass Ihr Ziel darin besteht, Partitionen auf einem Disk-Image zu betreiben, das als normale Datei dargestellt wird, finden Sie hier einen alternativen Workflow ohne kpartx und symbolische Links (deshalb wird er als separate Antwort gepostet):

  1. sudo losetup --find --show ./somedrive.img

    Fügen Sie ein Loop-Gerät für die gesamte Datei hinzu ./somedrive.img; --findes wird losetupautomatisch nach freien Geräten gesucht; und --showes wird gedruckt, wenn das Gerät verwendet wurde. Nehmen wir beispielsweise an, das ausgewählte Gerät ist /dev/loop5.

  2. sudo partx --update /dev/loop5

    Weisen Sie den Linux-Kernel an, die Partitionen darin erneut zu scannen /dev/loop5. Im Erfolgsfall wird keine Ausgabe erzeugt, sehen Sie also nach, ls -al /dev/loop5*was angezeigt wird.

  3. Tun Sie, was Sie brauchen, wiesudo gparted /dev/loop5

    An diesem Punkt sollten Sie in der Lage sein, ordnungsgemäß zu arbeiten /dev/loop5p*.

  4. sudo partx --delete /dev/loop5

    Geben Sie die Partitionszuordnungen frei.

  5. sudo losetup --detach /dev/loop5

    Lassen Sie zum Schluss das Loop-Gerät los.

PSWenn Sie der stolze Besitzer™ eines util-linuxPakets mit der Version v2.21 oder höher sind, können Sie sowohl die Loop-Geräteanbindung als auch einen erneuten Partitionsscan in einem Durchgang anfordern: sudo losetup --find --show --partscan ./somedrive.imgund das Problem mit gparted-ähnlichen Dienstprogrammen sollte überhaupt nicht auftreten.

verwandte Informationen