perbu (perbu) wrote,
perbu
perbu

tool tip: kpartx

kpartx is not, despite its name, some KDE-tool for partitioning disks. It is usually shipped with multipath - but it makes a lot of sense on its own. Its purpose is to read the partition table of a device or a file and create device map entries for the individual partitions.

So, how does it work? Say someone shippet you a DVD image with a xen instance on. You would like to extract a small file from the image but you don't want to go through the pain of installing xen and booting.

Lets see how it works. The image is contained in test7disk1.
root@nice:/media/cdrom# sfdisk -l test7disk1 
Disk test7disk1: cannot get geometry

Disk test7disk1:
Warning: The partition table looks like it was made
  for C/H/S=*/255/63 (instead of 0/0/0).
For this listing I'll assume that geometry.
Units = cylinders of 8225280 bytes, blocks of 1024 bytes.

   Device Boot Start     End   #cyls    #blocks   Id
test7disk1p1   *      0+     12      13-    104391   83
test7disk1p2         13     508     496    3984120   8e
test7disk1p3          0       -       0          0    0
test7disk1p4          0       -       0          0    0

Okey. Theres a bit of whining because sfdisk can't figure out the geometry. Lets ignore that.

Now lets add the maps:
root@nice:/media/cdrom# kpartx -a test7disk1 

Thats it! kpartx has set up a loopback device and created /dev/mapper/loop0p1 and /dev/mapper/loop0p2. These can be mounted, used av PVs in LVM or dealt with in other ways. Nice, eh?
Subscribe

  • Sun - the dot in oracle.com

    Sorry about the lame pun. I couldn't resist. How will the Sun acquisition affect Redpill Linpro and it's products? It's not quite clear yet, but I…

  • ext4 and the Jaunty Jackalope

    I've been longing for ext4 for a long time now. ext3 has a really broken implementation of fsync(2). Each fsync() turns into a sync(). If there is…

  • Google calc on the command line

    At some point a wrote a currency calculator. It downloaded a list of current exchange rates from a bank, somewhere. The draw back was that it could…

  • Post a new comment

    Error

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.
  • 4 comments