I know how to mount a drive that has a corresponding device file in /dev, but I don't know how to do this for a disk image that does not represent a physical device and does not have an analogue in /dev (e.g. an ISO file or a floppy image). I know I can do this in Mac OS X by double-clicking on the disk image's icon in Finder, which will mount the drive automatically, but I would like to be able to do this from the terminal. I'm not sure if there is a general Unix way of doing this, or if this is platform-specific.
How to mount a disk image from the command line
disk-imagemount
Related Solutions
The reason why you cannot just mount the partitions is because you have a disc image not images of individual partitions. You would need the offsets of the different partitions and use those when mount using its the loop and offset options.
In your case I would play back the image and then upgrade, but you don't indicate how you connected the 2.5" to you desktop computer, or how you are going to do that now. If you are going to use USB, then upgrading before playback is probably faster (but a bit more work), assuming the image is on an internal SATA drive. Because of the USB 2.0 vs SATA speed differences the upgrading is going to take longer. The playback of the image (upgraded or not) will take the same time.
If you want to upgrade before playback, then use parted to find the start of the images. parted hd.img
will give you a list of partition numbers, start and end. With the start information e.g 12345 you can mount a partition in the disk image:
mount -o loop,ro,offset=12345 hd.img /mnt/tmp
You might need to specify the partition type as well if your desktop does not recognise it. You can then update your fresh install with that info, remount the partition rw
clean out the partition and write things back. The only thing I am not sure about is if that would consfuse the ATX board's bootloader, but upgrading a system restored to disk would have the same problem.
I had a detailed look into the udisks2 source code and found the solution there.
The devices correctly mounted under user permissions were formatted with old filesystems, like fat
. These accept uid=
and gid=
mount options to set the owner. Udisks automatically sets these options to user and group id of the user that issued the mount request.
Modern filesystems, like the ext series, do not have such options but instead remember owner and mode of the root node. So chown auser /run/media/auser/[some id]
indeed works persistently. An alternative is passing -E root_user
to mkfs.ext4
which initializes uid and gid of the newly created filesystem to its creator.
Best Answer
If it was a hard-drive image with a MBR partition table, I would fdisk the image to find the offset for the partition I need to mount.
Then I would mount it passing the offset.
The offset value is in bytes, whereas
fdisk
shows a block count, so you should multiply the value from the "Begin" or "Start" column of thefdisk
output by512
(or whatever the block size is) to obtain the offset to mount at.