Creating and Using New Disk Images

Just as you can copy a partition to a file and mount it using the loopback device (using the -o loop option), you can create a file and then create a filesystem on it as if it were a disk partition. You can then write it out to a partition or to a removable device. For example:

[email protected]: /tmp # dd if=/dev/zero of=image.dsk count=1440k bs=1 1474560+0 records in 1474560+0 records out

What you are doing here is creating a file of exactly the same size as a standard floppy disk image (1440k) by reading from the /dev/zero device (which simply outputs a stream of null bytes).

Now you can create a filesystem on the file image.dsk (you need to be root to do this):

[email protected]: /tmp # mkfs -t ext2 image.dsk mke2fs 1.34 (25-Jul-2003)

image.dsk is not a block special device.

Filesystem label =

OS type: Linux

Block size=1024 (log=0)

Fragment size=1024 (log=0)

184 inodes, 1440 blocks

72 blocks (5.00%) reserved for the super user First data block=1 1 block group

8192 blocks per group, 8192 fragments per group 184 inodes per group

Writing inode tables: done

Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 37 mounts or

180 days, whichever comes first. Use tune2fs -c or -i to override.

You can then mount the filesystem and copy files onto it as follows:

[email protected]: /tmp # mount image.dsk /mnt -o loop cp filel file2 /mnt

Now you can write out the image to a floppy disk, but first you should unmount it:

[email protected]: /tmp # umount mnt [email protected]: /tmp # dd if=image.dsk of=/dev/fd0

You now have a file containing an image of the filesystem and a floppy disk that actually contains that filesystem.

Was this article helpful?

0 0

Post a comment