Linux makes it easy to work with disk images because copying a disk (a floppy disk or a CD or a hard disk partition) to a file is a simple matter:
[email protected]:~> dd if=/dev/fd0 of=floppy.img
The dd command reads the raw data from the device /dev/fd0 (the floppy disk) and writes it to the image file floppy.img.
You can now mount this image (you may need to become root):
If you look in /mnt you see exactly the same files that you would have seen if you had mounted the floppy disk. You need the option -o loop to the mount command to mount a filesystem from a file rather than a disk device. (The -o loop option is discussed in more detail later in the chapter.)
If you want to write the image back to another floppy, use the following:
[email protected]:~> dd if=floppy.img of=/dev/fd0
This is exactly the same process in reverse. Now the input to the dd command is the image file, and you are writing to the floppy disk.
^ Be very careful with the dd command. If you mix up the if= with the of= you could end up doing very serious damage, particularly if one of them is a hard disk partition.
You can do exactly the same thing with disk partitions:
[email protected] : ~ # dd if=/dev/hda1 of=imagefile In this case it is certainly best if /dev/hda1 is not mounted at the time.
This is something you might find yourself doing in the rescue system. For example, it's possible to imagine circumstances in which you might run the rescue system, get on the network, mount an NFS share from somewhere on the network, and then copy the disk partitions across to that share to back them up before doing something drastic to the system.
When you have copied the partition to a file, you can simply mount the file (with the -o loop option) as follows:
A CD image (ISO image) works in exactly the same way. To copy a CD to an ISO image, do the following:
[email protected]:~> dd if=/dev/cdrom of=cdimage.iso Again, you can mount it as follows:
Was this article helpful?