Re: dd and image files
- From: "Chris F.A. Johnson" <cfajohnson@xxxxxxxxx>
- Date: Mon, 30 Oct 2006 00:12:51 -0500
On 2006-10-31, TonyTheJavaTiger wrote:
Keywords: dd image file image files .img files device flash bios .exe file
So, here's the plain detailed explanation I would have liked to receive
instead of all the nonsense I got.
Let's suppose we have a Linux system and a FreeDOS boot floppy that we want to
make available on the net for people who want to flash their BIOS with an .exe
file, the only kind provided by the motherboard manufacturer.
On this floppy disk (fd), we have files such as command.com for
instance.
You *are* joking, I hope? There's no such thing as command.com on
any *nix system.
The Linux cp command could copy them but, unfortunately, since both
OS differ in their conception, the files might slightly differ.
No, the cp command will copy them byte for byte. They will be
identical.
Besides, in order for the floppy to be used for booting, we'll also
need its boot sector and file allocation table (FAT). And it would
be so nice to have all the stuff in just one file!
That's true.
In Linux/Unix, everything is a file: a directory is a file containing a list
of files and even devices are refered to as file and it so happens that in the
/dev directory, we have a file named fd0 that refers to our floppy disk.
(That's the device that's usually mounted on /mnt/floppy in fstab.)
Everything is stream of bytes; files are one manifestation of that.
The rest appears to be correct.
For copying, Linux also offers a utility called dd. This utility copies files
bit for bit, no question asked. If dd sees our /dev/fd0 file, it sees the boot
sector, the FAT, the files, etc. as just a succession of bits in one file.
So, if you:
dd if=/dev/fd0 of=fdboot.img
(if=input file of=output file)
every single bit of data on the floppy will be copied to the image file, which
will allow you to distribute the floppy as a single file. Wherever you copy
the file, it will appear as fdboot.img.
Note that you don't even have to mount the floppy to copy it. Countrary to the
case for cp, it doesn't even need to be part of your filesystem: the device is
accessed directly.
But what if we do the opposite dd operation?
dd if=fdboot.img of=/dev/fd0
Well, exactly the opposite will happen. Every bit of the file will be written
to device and you'll get an exact copy of the original floppy.
Whenever building or recomstituting an image file from a 1.44 MB floppy,
you'll see:
2880+0 records in
2880+0 records out
That's because each record is 512 bytes long. Since there are 1440 k on the
floppy, we have double the records.
This is how dd builds image files and reconstitute their content through a
device file.
--
Chris F.A. Johnson, author | <http://cfaj.freeshell.org>
Shell Scripting Recipes: | My code in this post, if any,
A Problem-Solution Approach | is released under the
2005, Apress | GNU General Public Licence
.
- Follow-Ups:
- Re: dd and image files
- From: TonyTheJavaTiger
- Re: dd and image files
- From: Dan C
- Re: dd and image files
- References:
- dd and image files
- From: TonyTheJavaTiger
- dd and image files
- Prev by Date: Re: MP3/player/USB-stick with unrecognised filesystem
- Next by Date: Re: dd and image files
- Previous by thread: dd and image files
- Next by thread: Re: dd and image files
- Index(es):
Relevant Pages
|