Edit file on image created with dd

5,451

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:
5,451

Related videos on Youtube

OrangeTux
Author by

OrangeTux

Updated on September 18, 2022

Comments

  • OrangeTux
    OrangeTux almost 2 years

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

    • Sandburg
      Sandburg about 6 years
      Are you always able to modify the usb content since Debian 9.4.0? It seems the read-only blocks that now.
  • grebneke
    grebneke over 10 years
    +1, you might also mention kpartx as described here: superuser.com/questions/344899/how-can-i-mount-a-disk-image