This question already has an answer here:

I've a bootable USB with Debian. Normally I clone the disk with dd, write the image on a new USB disk, mount this disk on my filesystem and edit some files. Is it possible to edit files on the image without writing the image to USB and mount the USB? I've tried ISO Master, but that raises an error: Failed to read volume info: 'Failed to read expected number of bytes'.

marked as duplicate by Gilles, jasonwryan, Braiam, slm, Anthon Feb 8 '14 at 4:30

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • Are you always able to modify the usb content since Debian 9.4.0? It seems the read-only blocks that now. – Sandburg May 20 '18 at 12:11

As root:

modprobe loop max_part=16
losetup /dev/loop0 file.img
vgchange -ay # if using LVM on there
mount /dev/the-device /mnt

(where the-device is the device (/dev/loop0p2 or /dev/someVG/someLV) with the filesystem that contains your file.

Then edit the file, and:

umount /mnt
vgchange -an someVG # if using LVM there
losetup -d /dev/loop0

Alternatively, you could boot your image in a VM:

kvm -hda file.img -m 1024

(don't forget to shutdown the VM gracefully after editing the file in there).

Not the answer you're looking for? Browse other questions tagged or ask your own question.