5

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

1
  • Are you always able to modify the usb content since Debian 9.4.0? It seems the read-only blocks that now. Commented May 20, 2018 at 12:11

1 Answer 1

4

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

2
  • +1, you might also mention kpartx as described here: superuser.com/questions/344899/how-can-i-mount-a-disk-image Commented Feb 7, 2014 at 10:52
  • Using losetup -f you can find an empty loop device that you can use in losetup /dev/loopX /path/to/img.img (say /dev/loop0 is already in use). Commented May 1 at 9:38

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.