1

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?

Sid Ramadoss
  • 521
  • 2
  • 6
  • 13

1 Answers1

1

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.

Mat
  • 202,337
  • 40
  • 393
  • 406
  • I believe the "if" option in dd command is for the source. If i mention my source directory there(say "/home/sid/folder/"), the image gets created, but size is 0. Anything I'm doing wrong? – Sid Ramadoss Apr 30 '12 at 09:00
  • You cannot use a directory as a source, you need a file or a block device. You copy your directory into your image _after_ you've mounted it (by copying your directory to the mount point). – Mat Apr 30 '12 at 09:01
  • My goal is to create one image with my contents and use it to mount it in /dev/loop0. – Sid Ramadoss Apr 30 '12 at 09:42
  • Yes, follow the method above. Copy your contents to the mount point, and unmount. Now your image contains your content. You can re-mount it at will. (There are tools that create ISO images directly from a source directory, and for some other filesystems, but I'm not aware of one for EXT filesystems.) – Mat Apr 30 '12 at 09:44