6

If you have a hard disk image (including partition table, multiple partitions,...), is it possible to let Linux treat it as a regular hard disk?

By "regular hard disk" I mean I would like to have the image show up as, for instance, /dev/hdx and its partitions as /dev/hdx1,...

(I know I can mount one of the partitions in the image using "mount -o loop,offset=x ..." but I don't really like this option.)

Hennes
  • 65,142
mtvec
  • 403

2 Answers2

6

kpartx will generate multiple device files from the partitions within the file which you can then loopmount to get at the contents.

  • Yes that does what I want! Just one thing: only the partitions show up as dev-nodes, is it also possible to create a node for the entire device? – mtvec Apr 07 '10 at 08:14
  • I'm not certain why you'd need to. With the exception of ioctls, a normal file works just like a block device. – Ignacio Vazquez-Abrams Apr 07 '10 at 08:21
  • I need it to access the MBR, but you're right: I can do that via the image file as well. Thanks for the help! – mtvec Apr 07 '10 at 12:34
1

+1 for kpartx.

For command line fans, partx does the same job.

CJBrew
  • 221