Re: dd and image files



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
.



Relevant Pages

  • Re: installation problems
    ... RH 9 had trashed my Linux partition and rendered my PC unbootable. ... >you can create the floppy from and can be created on a differnet ... >on the CD as the floppy boot image. ... and since flash drives seem to be listed in /proc as scsi devices, ...
    (comp.os.linux.misc)
  • Re: xPC boot-up from hard drive
    ... The boot floppy was certainly easier... ... It's slow to boot up (and dependent on a floppy disk), ... All in all it means that using xPC Embedded Option with a "normal" PC ...
    (comp.soft-sys.matlab)
  • Re: Making a bootable CD from a bootable USB flash drive
    ... I have a working bootable USB flash drive. ... CD from the image file. ... mean that you boot from the USB drive? ... floppy, or it would be easy to make a bootable CD from a bootable ...
    (microsoft.public.windowsxp.general)
  • Re: re boot problem after replacing hard drive
    ... "mikec" wrote: ... It was one of the options available to me when floppy booted up. ... choice between windows xp and fastdetect. ... Firstly the good news, the boot floppy worked, yes I make good boot floppies ...
    (microsoft.public.windowsxp.general)
  • Re: How can I completely wipe my entire system and do a fresh install
    ... Search for floppy image on web site. ... Boot with XP CD. ... >:> to partition and format your drive. ... > Go back to Normal Mode and install SP2 from a CD. ...
    (microsoft.public.windowsxp.general)