Mount

From Leo's Notes
Revision as of 18:55, 18 February 2020 by Leo (talk | contribs) (mounting specific partition on disk image)
This page was last edited on 18 February 2020, at 18:55.

Todo Merge all Mount articles here.

Remounting from Read-Only to Read-Write

You can remount something that's mounted read-only by using the remount option.

# mount -o remount,rw /

Mounting a disk image without root

Using udisksctl, you can mount disk images without requiring root or sudoers access.

$ dd if=/dev/zero of=test.img bs=1M count=100
$ udisksctl loop-setup -f test.img
Mapped file $PATH_TO_IMAGE as /dev/loop0.

Depending on your system, this may have triggered the loopmount to automount somewhere in /run/media/username. If nothing was mounted, manually mount the loopmount device:

$ udisksctl mount -b /dev/loop0
Mounted /dev/loop0 at /media/$USER/$IMAGE_NAME

To unmount the filesystem:

$ udisksctl unmount -b /dev/loop0
$ udisksctl loop-delete -b /dev/loop0

See Also: https://wiki.debian.org/ManipulatingISOs

Mounting disk image partitions

To mount a specific partition inside a disk image, use the fdisk utility to see where the partition boundaries are.

# fdisk -l out.bin
Disk out.bin: 58.6 MiB, 61440000 bytes, 120000 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x000981cb

Device     Boot  Start     End Sectors  Size Id Type
out.bin1          8192  122879  114688   56M  c W95 FAT32 (LBA)
out.bin2        122880 5785599 5662720  2.7G 83 Linux

The first partition starts on sector 8192. Since each sector is 512 bytes, we can mount this particular partition by passing an offset of 8192 * 512 bytes.

# mount -o loop,offset=$((8192 * 512)) out.bin /mnt/card

Alternatively, you may want to set up a loopback device specifically for a partition using losetup:

# losetup /dev/loop0 disk.img -o $((10860003 * 512))
# file -s /dev/loop0
/dev/loop0: Linux rev 1.0 ext3 filesystem data
# mount /dev/loop0 /mnt
[...]
# umount /mnt
# losetup -d /dev/loop0


See Also

  1. http://madduck.net/blog/2006.10.20:loop-mounting-partitions-from-a-disk-image/