Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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'.

share|improve this question

marked as duplicate by Gilles, jasonwryan, Braiam, slm, Anthon Feb 8 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.

1 Answer 1

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).

share|improve this answer
    
+1, you might also mention kpartx as described here: superuser.com/questions/344899/how-can-i-mount-a-disk-image –  grebneke Feb 7 at 10:52

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