Kpartx: a tool for mounting partitions within an image file
July 12, 2008
Kpartx can be used to set up device mappings for the partitions of any partitioned block device. It is part of the Linux multipath-tools. With kpartx -l imagefile you get an overview of the partitions in the image file and with kpartx -a imagefile the partitions will accessible via /dev/mapper/loop0pX (X is the number of the partition). You can mount it now with mount /dev/mapper/loop0pX /mnt/ -o loop,ro. After unmounting you can disconnect the mapper devices with kpartx -d imagefile.
There are packages for Debian and Ubuntu.
- Ubuntu: http://packages.ubuntu.com/de/hardy/kpartx
- Debian: http://packages.debian.org/search?keywords=kpartx
8 Comments »
RSS feed for comments on this post. TrackBack URI
Leave a comment
Powered by WordPress
Entries and comments feeds.
Valid XHTML and CSS.
17 queries. 0.082 seconds.
Hello,
I’m trying to do this in my fedora system but doesnt work. I am not getting any output after issuing this command kpartx -a and kpartx -l and getting nothing in /dev/mapper/
What should I check ?
Comment by smary — June 26, 2009 #
What is the nature of the image file you’re using? Is it a full image of a complete hard disk or only an image of one partition?
Comment by robert — June 27, 2009 #
Its a full image of a complete hard disk
Comment by smary — June 29, 2009 #
Actually I’m getting the following error now:
[root@smary ~]# kpartx -l /tmp-mnt/BACKUP_final.img
loop1p1 : 0 1701990410 /dev/loop1 218129509
loop1p2 : 0 543974724 /dev/loop1 729050177
loop1p4 : 0 51635 /dev/loop1 2692939776
[root@smary ~]# kpartx -a -v /tmp-mnt/BACKUP_final.img
device-mapper: reload ioctl failed: Invalid argument
create/reload failed on loop1p1
add map loop1p1 (0:0): 0 1701990410 linear /dev/loop1 218129509
device-mapper: reload ioctl failed: Invalid argument
create/reload failed on loop1p2
add map loop1p2 (0:0): 0 543974724 linear /dev/loop1 729050177
device-mapper: reload ioctl failed: Invalid argument
create/reload failed on loop1p4
add map loop1p4 (0:0): 0 51635 linear /dev/loop1 2692939776
[root@smary ~]# ls -all /dev/mapper/
total 0
drwxr-xr-x 2 root root 60 2009-06-25 08:32 .
drwxr-xr-x 16 root root 5060 2009-06-29 08:14 ..
crw-rw—- 1 root root 10, 63 2009-06-25 08:32 control
[root@smary ~]#
Comment by smary — June 29, 2009 #
This normally says that you’ve updated your kernel and it doesn’t fit anymore your device-mapper version. Update also the device-mapper package. also take a look at the syslog as it should provide additional info.
Comment by robert — June 29, 2009 #
Just use it on a device and not an image file. Create the device with losetup first.
Comment by partition mage — July 14, 2009 #
Just found ya…Great stuff.
I will be adding you to my links list and checking in…
Comment by andy — March 2, 2010 #
[...] Kpartx: a tool for mounting partitions within an image file [...]
Pingback by 通过kpartx使用LVM卷 - 阿泰的菜园 — June 28, 2010 #