This is doing it the hard way. Make the image a loop device: losetup /dev/loop0 /path/to/your/image.img Now you can use /dev/loop0 like it's a normal disk. If you're not seeing your partitions (/dev/loop0p1, etc.): partprobe /dev/loop0 When you're done, detach the loop device: losetup -d /dev/loop0 I use this trick to transparently compress ddrescue images with brtfs: https://brashear.me/blog/2017/11/14/how-to-create…
You can make that even easier: # losetup -Pf /path/to/disk.img # mount /dev/loop0pX /mnt
Mounting partitions from a dd image
31–37 of 37 posts
Re: Mounting partitions from a dd image
#32This is doing it the hard way. Make the image a loop device: losetup /dev/loop0 /path/to/your/image.img Now you can use /dev/loop0 like it's a normal disk. If you're not seeing your partitions (/dev/loop0p1, etc.): partprobe /dev/loop0 When you're done, detach the loop device: losetup -d /dev/loop0 I use this trick to transparently compress ddrescue images with brtfs: https://brashear.me/blog/2017/11/14/how-to-create…
Thanks, not OP but that looks useful to me. For context, I've used the strategy in OP to debug a small linux system running on an SD card, if I have one version that has a bug and one that doesn't, and I don't know the difference, I can image them both, mount them and diff the whole system (i.e. with meld.) And it can be done with the same card over time. I'd like to figure out how to do this with VM disks as well bu…
Everything that you will (probably) need is here: http://libguestfs.org
If you happen to need something that isn't already included, the APIs make it pretty easy to build your own tools as well.
Conveniently, those tools are also already packaged up for your distro (unless you use some esoteric distribution, perhaps).
Re: Mounting partitions from a dd image
#33This is doing it the hard way. Make the image a loop device: losetup /dev/loop0 /path/to/your/image.img Now you can use /dev/loop0 like it's a normal disk. If you're not seeing your partitions (/dev/loop0p1, etc.): partprobe /dev/loop0 When you're done, detach the loop device: losetup -d /dev/loop0 I use this trick to transparently compress ddrescue images with brtfs: https://brashear.me/blog/2017/11/14/how-to-create…
There's just one thing I don't get with this approach. How do you make use of the space savings? You've explicitly created an outside disk image which is larger than the ddrescue image, and the ddrescue image is inside that larger file. So while the inside image is taking less space inside the mounted loopback volume, the outside disk image will always take the original amount of space. Do you trim the outside volume…
Re: Mounting partitions from a dd image
#34OpenBSD uses vnconfig (also FreeBSD; on NetBSD it's vndconfig). An example: # vnconfig vnd0 install63.fs Then you can treat vnd0 as if it was a disk: # disklabel vnd0 # /dev/rvnd0c: type: vnd disk: vnd device label: fictitious duid: 138b4f2a2e184426 flags: bytes/sector: 512 sectors/track: 100 tracks/cylinder: 1 sectors/cylinder: 100 cylinders: 7382 total sectors: 738240 boundstart: 1024 boundend: 737280 drivedata: 0…
FreeBSD does not use vnconfig, FreeBSD uses mdconfig: # mdconfig -f smartos-latest-USB.img md0 # gpart list md0 ... scheme: MBR Providers: 1. Name: md0s1 ... # mount -o ro -t msdosfs /dev/md0s1 /mnt // (or, use labels) # mount -o ro -t msdosfs /dev/msdosfs/SMARTOSBOOT /mnt Or for ISOs, in one line: # mount -t cd9660 /dev/$(mdconfig -f image.iso) /mnt
Apparently that's been a little while, however. According to vnconfig(8):
> The mdconfig utility first appeared in FreeBSD 5.0 as a cleaner replacement for the vn(4) and vnconfig(8) combo.
5.0 was released just over 15 years ago.
Re: Mounting partitions from a dd image
#35This is doing it the hard way. Make the image a loop device: losetup /dev/loop0 /path/to/your/image.img Now you can use /dev/loop0 like it's a normal disk. If you're not seeing your partitions (/dev/loop0p1, etc.): partprobe /dev/loop0 When you're done, detach the loop device: losetup -d /dev/loop0 I use this trick to transparently compress ddrescue images with brtfs: https://brashear.me/blog/2017/11/14/how-to-create…
There's just one thing I don't get with this approach. How do you make use of the space savings? You've explicitly created an outside disk image which is larger than the ddrescue image, and the ddrescue image is inside that larger file. So while the inside image is taking less space inside the mounted loopback volume, the outside disk image will always take the original amount of space. Do you trim the outside volume…
Re: Mounting partitions from a dd image
#36Earlier quoted context omitted.
There's just one thing I don't get with this approach. How do you make use of the space savings? You've explicitly created an outside disk image which is larger than the ddrescue image, and the ddrescue image is inside that larger file. So while the inside image is taking less space inside the mounted loopback volume, the outside disk image will always take the original amount of space. Do you trim the outside volume…
It's called sparse files, it's files with holes in them where no data is written to disk. You can have terabytes of files on small disks as long as they contain a high % of bocks of only zeros.
Re: Mounting partitions from a dd image
#37Earlier quoted context omitted.
Interesting I have used kpartx which uses device mapper instead of Partprobe. Wonder why kpartx exists; will have to look into that. Maybe not everything can be partprobed.
I'm not sure. All I can think is that partprobe is provided by parted and I have noticed people tend to gravitate towards using fdisk or parted and ignoring the other. Notice the author of the article is an fdisk guy. I might be mis-remebering but I think parted used to be considered lame before fdisk lagged to support GPT.
I don’t like how parted will automatically commit your changes as you go, though this is useful for scripting your changes and is my preferred method for disk geometry modifications when preparing maintenances etc
Right tool for the job and all that.
From what I remember partprobe has had a history of occasional unreliable behaviour under RHEL - but I understand it works properly under RHEL 7.3+