Search code examples
imagemountext3loopback

How to use /dev/loop0 to create and mount image?


I want to create an image from the contents of a directory(say "/home/sid/folder/"). I then want to use /dev/loop0, format it to ext3 format. Finally associate the image i just created with loop0 and mount it. How do I do this?


Solution

  • Create your image file of the size you want:

    dd if=/dev/zero of=./your.img bz=1M count=<number of megabytes you want>
    

    Format it

    mkfs.ext3 ./your.img
    

    (Recheck that command before running it, do read what is printed out.)

    Mount it:

    mount -o loop ./your.img /some/mount/point
    

    And you're done. Don't forget to unmount before you copy/send that image file anywhere.