[H-GEN] Creating disk image
Ben Carlyle
benc at foxboro.com.au
Mon Aug 9 22:18:23 EDT 1999
( Humbug *General* list - semi-serious discussions about Humbug and
Unix related topics. Consider also the 'Chat' list (reply-to) if
your posting is not on-topic for 'General'. Including this text in
your reply shows that you have not read it. )
John,
The reason the dd documentation probably seems a little sketchy is
that it is the block-based equivalent of "cat". dd is a very simple
generic utility for reading blocks from one file and writing them to
another, and like cat (which does the same with characters) it can
be used for just about any duplication of block-based files.
I'll assume at this point you're familiar with the cat program and
its usage, and move on to a few analogies that my help you think
about what's going on in the filesystems:
In UNIX everything is a file, including all devices. A standard ide
hard drive may be /dev/hda, while it's partitions may be /dev/hda1,
/dev/hda2, etc etc. If I wanted to copy the contents of the first
parition onto the second, and I had enough space on the second to
do so, then I could use dd:
dd if=/dev/hda1 of=/dev/hda2
(this will succeed with a block count, or return an error of there
is not enough space on hda2 to write the image after writing as much
as possible)
If the partitions are exactly the same size, then you can do this
ad infinitum. As mentioned in an earlier post you can follow a
simialar principal with whole disks if you also want to make a
mirror of the partition information.
Case study:
/dev/hda1 is smaller than /dev/hda2, and I want to backup the former
onto the latter as a true disk image. I run the command:
dd if=/dev/hda1 of=/dev/hda2
returns:
30+0 records in
30+0 records out
No errors are returned, and I'm a happy larakin.
I now find that I want to restore from /dev/hda2, and I use dd for
this function also:
dd if=/dev/hda2 of=/dev/hda1
(you do -not- want to get these steps the wrong way 'round :)
returns:
31+0 records in
30+0 records out
with some kind of error message.
You can ignore the error message, because it has written what we
wanted. Everything is hunky-dory.
As I said before, dd is the block version of cat. It's only useful
because unix has the /dev/ files available, but because they are it
can be very useful indeed. Be warned that using dd to store other
kinds of data on a disk partition will destroy the partition's
filesystem, and that using dd to store other kinds of data on a raw
disk will destory the partition table as well (making the disk
appear to be completely unformatted to any operating system that
cares to look at it). dd write directly into the file you target,
and assumes that you know what you're doing. Whatever data you feed
into it will be exactly what it writes[1].
Benjamin
(elder fuzzy)
[1]
You will undoubtably find a few quirks documented in the man page if
you attempt to write files that are not "block-sized". If you have
stray characters then you could confuse dd, and it will attempt to
counter your insolence by filling the blocks with empty data, and
generally teach you a lesson you need to learn.
John Boggon wrote:
> dd does not require the disk to be formatted ?. But it would need to be
> partitioned with the same size as the image ?
--
This is list (humbug) general handled by majordomo at lists.humbug.org.au .
Postings only from subscribed addresses of lists general or general-post.
More information about the General
mailing list