Note: While I agree that this question basically is a duplicate of the above question, I feel @alienth's answer (below) is more concise, so I suggest you take a look at it before going to the other question.

I periodically backup/image/clone my entire ubuntu system drive to another drive with:

dd if=/dev/sda of=/media/disk1/backup.iso

It works great when I need to restore the drive after an experiment, drive failure, etc.

However I'd now like to mount a partition from within that .iso (i.e. what would have been /dev/sda1 when I was dd'ing the drive). If I'd backed up with:

dd if=/dev/sda1 of=/media/disk1/backup.iso

then the .iso would be easily mountable using ubuntu's mount volume utility. But the utility doesn't work for an iso of the entire drive. Is there a way to just mount sda1 from the original iso?

One notable issue with that blog post is that it uses fdisk, which may not work correctly with a GPT partition table (which is the standard on many recent distro releases).
– alienthSep 18 '15 at 21:39

I knew that I was creating a raw disk image, and now that I think about it I do remember someone explaining that an iso is some sort of concatenation of files, so I guess I should have been aware. I am now, anyway - thanks.
– Fred HamiltonSep 18 '15 at 22:42

You need to take the logical sector size and multiply that by the Start of the partition you'd like to mount. In this case, if I want to mount the first partition, the position would be 2048 * 512, or 1048576.

You can then mount the partition using a loopback setup, plugging the value determined from above into the offset parameter.

Very helpful indeed! If you are trying to mount an lvm partition, you should follow these directions, but you will need to use the offset as shown in this answer. So instead of losetup /dev/loop0 backup-cloud.img, you need losetup -o XXX where XXX is the offset computed as shown above (start * 512, assuming logical/physical is 512).
– svenevsNov 4 '17 at 0:49

This should, ideally, create loop devices /dev/loop0p1, /dev/loop0p2 and so forth for the partitions in backup.iso. You can then mount these normally as loop devices; it's probably prudent to do it read-only, so as not to corrupt your backup. There are likely safer ways to trigger the partition read than using fdisk directly, such as partprobe or kpartx; however, I've had reliability issues with those, and fdisk is the best way I've found.

The second way is more difficult. It involves reading the partition start manually (fdisk -l /dev/loop0), then redoing losetup with an appropriate --offset option to make the loop device begin at the partition start. Precisely what number you pass depends on the output from fdisk, but it's an offset in bytes, equal to the starting block times the block size. At that point, you can mount /dev/loop0 directly (again, read-only is prudent).

I'm on a recent Mint release and fdisk bombs with a warning about GPT and spits out an incorrect partition layout. Using version 2.20.1.
– alienthSep 18 '15 at 21:22

Also, curiously I can't get loop0p1 to show up in a test case by simply writing out the partition table with fdisk (with a standard DOS-type table), despite it being listed when printed out with fdisk. I do know that used to work. partprobe doesn't fetch it, either.
– alienthSep 18 '15 at 21:24

1

You can use the -P option to requst a partition scan of the created loop device - this is what sets up the partition device nodes. I often use it like this: dev=$(sudo losetup -P -f --show disk.img) and then I can do sudo mount ${dev}p2 /mnt, cleaning up afterwards with sudo losetup -d $dev.
– starfryDec 20 '16 at 12:32