Tuesday, January 25, 2011

How to create .img file

An IMG file contains a raw dump of the content of a disk. We will use losetup to associate loop device with a file and mount it to work with.
  1. Pre-allocate img file (stuff.img) of the size you need (10M):
    dd if=/dev/zero of=/tmp/stuff.img bs=1M count=10
    
  2. Setup a loop device:
    losetup /dev/loop0 /tmp/stuff.img
    
  3. Create ext3 file system on loop device:
    mkfs.ext3 /dev/loop0
    
  4. Mount it:
    mount /dev/loop0 /mnt
    
Once you are done:
  1. Unmount file system:
    umount /mnt
    
  2. Delete loop device:
    losetup -d /dev/loop0
    

No comments :

Post a Comment