Live data from Hacker News

Mounting partitions from a dd image

assafmo.github.io

11–20 of 37 posts

Re: Mounting partitions from a dd image

#11

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…

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.

Re: Mounting partitions from a dd image

#12

OpenBSD 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

Re: Mounting partitions from a dd image

#14
post #11

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…

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.

Re: Mounting partitions from a dd image

#15

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…

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 but I've never had a pressing need.

Re: Mounting partitions from a dd image

#16

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…

If you have a full dd image of the disk, you can just do losetup -Pf /path/to/your/image.img and that will pick a loopback device and perform the partprobe on it automatically.

Re: Mounting partitions from a dd image

#17
post #11

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…

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.

kpartx is an older tool that was used with 2.6.xx-era Linux systems. partprobe/losetup are the newer mechanisms for doing this.

A lot of StackOverflow questions have answers that use kpartx, and those answers are out of date.

Re: Mounting partitions from a dd image

#18
post #2

Is it also possible to repartition the image with conventional tools? How about setting a boot flag and writing it back to e.g. an USB stick?

Yes, you can use losetup. ~# dd if=/dev/zero of=image.img bs=1M count=100 ~# LODEVICE=$(losetup --find --show image.img) ~# fdisk $LODEVICE ~# losetup -d $LODEVICE ^ The above creates a 100MB disk image, binds it to a loopback device, runs fdisk, and then detaches it. I'm not sure how formatting the partition would work but presumably those tools have an offset option too? edit: this page explains using offsets for m…

I have built block-level bootable system images for the TS-7800 using this mechanism.

https://www.embeddedarm.com/products/TS-7800

That was before I found multistrap.

Re: Mounting partitions from a dd image

#20
post #2

Is it also possible to repartition the image with conventional tools? How about setting a boot flag and writing it back to e.g. an USB stick?

Yes, you can use losetup. ~# dd if=/dev/zero of=image.img bs=1M count=100 ~# LODEVICE=$(losetup --find --show image.img) ~# fdisk $LODEVICE ~# losetup -d $LODEVICE ^ The above creates a 100MB disk image, binds it to a loopback device, runs fdisk, and then detaches it. I'm not sure how formatting the partition would work but presumably those tools have an offset option too? edit: this page explains using offsets for m…

Extlinux on an ext4 partition doesn't need an offset. Or at least didn't when I wrote this: http://www.blackkettle.org/posts/archive/2013-08-19-bootable...
Post reply on HN