Skip to content

Instantly share code, notes, and snippets.

@fegue
Created May 3, 2021 10:26
Show Gist options
  • Save fegue/80630aada3f40109964c6d6b28b98698 to your computer and use it in GitHub Desktop.
Save fegue/80630aada3f40109964c6d6b28b98698 to your computer and use it in GitHub Desktop.
[Mount image as filesystem] MOunt Iamges and edit files as if it was a USB-Drive #linux #bash

Method 1: Use 'Disk Image Mounter'

If that does not work ...

Method 2

https://superuser.com/questions/1018877/ubuntu-mount-image-file-with-r-w-permission

sudo fdisk -l raspberry_pi.img

Multiply sector size in bytes (e.g. 512) with sector start of partition you want to mount

Example

Disk raspberry_pi.img: 7.3 GiB, 7826571264 bytes, 15286272 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: 0xbeb1a7ff

Device          Boot Start      End  Sectors  Size Id Type
raspberry_pi.img1       8192    93813    85622 41.8M  c W95 FAT32 (LBA)
raspberry_pi.img2      94208 15069183 14974976  7.1G 83 Linux

512 * 94208 = 48234496

Create sdcard folder

sudo mkdir /media/sdcard
sudo mount -o loop,rw,sync,offset=48234496 raspberry_pi.img /media/sdcard

Finally unmount sudo umount /media/sdcard

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment