Loop-mount image of harddrive
Hello!
I can mount a regular file (containing a filesystem) using `-o loop'. Is there a way to mount a file representing a complete harddrive image (like the result of `dd if=/dev/hda of=my-file'), containing partition table and partitions? If yes, how can it be done? I hope, this hasn't been answered already (I don't know what to search for...). Thank you Adrian |
This how to mount the first partition on a harddisk image:
Code:
losetup -o $((63 * 512)) /dev/loop0 hd.img If you run fdisk -l on the image and play around with the offset maybe you can find out how to mount the other partitions as well. |
OOhhhh ! 8-)
That's what I was looking for a year ago (or so...). Thanks! It's a nice tip to know. Could you give the explanation for the bash-computed 63*512? I guess it is 63 times the size of a sector, but then are we sure that sectors are always 512 bytes big, and why 63 times? Yves. |
Thank you, you helped me a lot (this makes it much easier to play around with Bochs).
But I guess it's easier to use fdisk -ul because you get the partition sizes in sectors (partitions are not necessarily aligned to cylinders). @theYinYeti: AFAIK a cylinder has typically 63 sectors on a large hard disk. I don't know on which devices a sector has <> 512 bytes, but you can get the geometry and sector size with fdisk -l |
I found that recipe through googling a few months ago, don't really remember what it means, but I think the offset is to skip the MBR.
@addy86: Have you tried Qemu? In my opinion it is a lot easier to use than bochs, and it is supposed to be faster as well, especially with the accelerator module. http://fabrice.bellard.free.fr/qemu/ EDIT: This is useful to me too, so I wrote a bash script to mount a partition on a image, thanks for the tips about fdisk -u. EDIT2: Bugfix for the below script, would fail for partitions marked bootable. Code:
#!/bin/bash |
Excellent! Thanks both! And thanks for this nice script.
Yves. (Small typing error: 7th line from the end: 4:- instead of 4-) |
Quote:
Code:
a= |
All times are GMT -5. The time now is 01:33 PM. |