The device /dev/mem is your system memory. You can actually copy any block or ch
aracter device to a file with dd. Memory capture on a fast system, with bs=1024
takes about 60 seconds. Copying a 120 GB HDD takes about an hour. Copying a CD t
o hard drive takes about 10 minutes. Copying a floppy to a hard drive takes abou
t 2 minutes. With dd, your floppy drive images will not change at all. If you ha
ve a bootable DOS diskette, and you save it to your HDD as an image file, when y
ou restore that image to another floppy it will be bootable. dd is an excellent
way to make an image of MS Windows XP install CD's. When you make a copy of such
a cd, there is one sector that is of nonstandard length. It is the last sector.
dd doesn't pad this sector, making the copy indistinguishable from the original
. If you burn the CD using cdrdao, the resulting disk will be an absolutely exac
t copy of the original.
dd will print to the terminal window if you omit the of= part.
dd if=/home/sam/myfile
will print the file myfile to the terminal window.
If you are just curious about what might be on you disk drive, or what an MBR lo
oks like, or maybe what is at the very end of your disk:
dd if=/dev/sda count=1 | hexdump -C
Will show you sector 1, or the MBR. There is the beginning of the loader code an
d the partition table in there. To see the end of the disk you have to know the
total number of sectors for the disk, and the disk has to be set up with Maximum
Addressable Sector equal to Maximum Native Address. The helix CD has a utility
to set this correctly. In the dd command your seek value will be one less than M
NA of the disk.
for a 120 GB Seagate SATA drives
dd if=/dev/sda of=home/sam/myfile skip=234441646
default bs=512, so this reads sector for sector, and writes the last sector to m
yfile.
Disks, even though there is LBA addressing now, still secretly are read in secto
rs, cylinders, and heads. There are 63 sectors per cylinder, and 255 heads per c
ylinder. Then there is a total cylinder count for the disk. You multiply out 512
x63x255=bytes per cylinder. 63x255=sectors per cylinder. With dd you usually wan
t to work with sectors per cylinder. With 234441647 total sectors, and 16065 sec
tors per cylinder, you get some trailing sectors which do not make up an entire
cylinder, 14593.317584812. This leaves you with 5102 sectors which cannot be par
titioned because to be in a partition you have to be a whole cylinder. Part cyli
nders do not count. It's like having part of a person. That doesn't really count
as a person. So, what happens to these sectors? They become surplus sectors aft
er the last partition. This a perfect place for sneaky programs to play, because
you can't ordinarily read in there with an operating system. But, dd can.
It is really a good idea to check for anything writing to surplus sectors. For o
ur Seagate 120 GB drive you subtract total sectors(234441647)-(5102) which don't
make up a whole cylinder=234436545 partitionable sectors. Remember, native HDD
sectors are 512, or 1b. If you don't specify bs in dd it defaults to 512.
dd if=/dev/sda of=/home/sam/myfile skip=234436545
this writes the last 5102 sectors to myfile. Launch mc to view the file. I swear, half
the time Windows XP has left a weird, mutated MBR there. It like marks the disk
for life that XP was there.
If there is something in there, you do not need it for anything. In this case yo
u would write over it with random characters. Many digital rights management pro
grams use surplus sectors to operate from, while enforcing DRM. These trojans, w
hich are corporate trojans, are meant to enforce the security measures in copyri
ghted software. There are other various means to conceal such a trojan. One of t
hese is a hidden partition. There is an undocumented type of partition which is
called hidden. It is not visible to any operating system.
dd if=/dev/urandom of=/dev/sda bs=512 seek=234436545
Will overwrite the 5102 surplus sectors on our 120 GB Seagate drive.
If you want to check out some random area of the disk:
dd if=/dev/sda of=/home/sam/myfile bs=4096 skip=2000 count=1000
will give you 8,000 sectors in myfile, after the first 16,000 sectors. You can o
pen that file with a hex editor, edit some of it, and write the edited part back
to disk:
dd if=/home/sam/myfile of=/dev/sda bs=4096 seek=2000 count=1000
So there you got yourself a disk editor. It's not the best, but it works.
You can make a boot floppy: with the boot.img file, which is pretty easy to get.
You just need a program that will literally start writing at sector 1.
dd if=boot.img of=/dev/fd0 bs=1440k
This makes a bootable disk you can add stuff to.
OPERANDS
The following operands are supported:
if=file
Specifies the input path. Standard input is the default.
of=file
Specifies the output path. Standard output is the default. If the seek=expr conv
ersion is not also specified, the output file will be truncated before the copy
begins, unless conv=notrunc is specified. If seek=expr is specified, but conv=no
trunc is not, the effect of the copy will be to preserve the blocks in the outpu
t file over which dd seeks, but no other portion of the output file will be pres
erved. (If the size of the seek plus the size of the input file is less than the
previous size of the output file, the output file is shortened by the copy.)
ibs=n
Specifies the input block size in n bytes (default is 512).
obs=n
Specifies the output block size in n bytes (default is 512).
bs=n
Sets both input and output block sizes to n bytes, superseding ibs= and obs=. If
no conversion other than sync, noerror, and notrunc is specified, each input bl
ock is copied to the output as a single block without aggregating short blocks.
cbs=n
Specifies the conversion block size for block and unblock in bytes by n (default
is 0). If cbs= is omitted or given a value of 0, using block or unblock produce
s unspecified results.
This option is used only if ASCII or EBCDIC conversion is specified. For the asc
ii and asciib operands, the input is handled as described for the unblock operan
d except that characters are converted to ASCII before the trailing SPACE charac
ters are deleted. For the ebcdic, ebcdicb, ibm, and ibmb operands, the input is
handled as described for the block operand except that the characters are conver
ted to EBCDIC or IBM EBCDIC after the trailing SPACE characters are added.
files=n
Copies and concatenates n input files before terminating (makes sense only where
input is a magnetic tape or similar device).
skip=n
Skips n input blocks (using the specified input block size) before starting to c
opy. On seekable files, the implementation reads the blocks or seeks past them.
On non-seekable files, the blocks are read and the data is discarded.
iseek=n
Seeks n blocks from beginning of input file before copying (appropriate for disk
files, where skip can be incredibly slow).
oseek=n
Seeks n blocks from beginning of output file before copying.
seek=n
Skips n blocks (using the specified output block size) from beginning of output
file before copying. On non-seekable files, existing blocks are read and space f
rom the current end-of-file to the specified offset, if any, is filled with null
bytes. On seekable files, the implementation seeks to the specified offset or r
eads the blocks as described for non-seekable files.
count=n
Copies only n input blocks.
conv=value[,value. . . ]
Where values are comma-separated symbols from the following list:
ascii
Converts EBCDIC to ASCII.
asciib
Converts EBCDIC to ASCII using BSD-compatible character translations.
ebcdic
Converts ASCII to EBCDIC. If converting fixed-length ASCII records without NEWLI
NEs, sets up a pipeline with dd conv=unblock beforehand.
ebcdicb
Converts ASCII to EBCDIC using BSD-compatible character translations. If convert
ing fixed-length ASCII records without NEWLINEs, sets up a pipeline with dd conv
=unblock beforehand.
ibm
Slightly different map of ASCII to EBCDIC. If converting fixed-length ASCII reco
rds without NEWLINEs, sets up a pipeline with dd conv=unblock beforehand.
ibmb
Slightly different map of ASCII to EBCDIC using BSD-compatible character transla
tions. If converting fixed-length ASCII records without NEWLINEs, sets up a pipe
line with dd conv=unblock beforehand.
The ascii (or asciib), ebcdic (or ebcdicb), and ibm (or ibmb) values are mutuall
y exclusive.
block
Treats the input as a sequence of NEWLINE-terminated or EOF-terminated variable-
length records independent of the input block boundaries. Each record is convert
ed to a record with a fixed length specified by the conversion block size. Any N
EWLINE character is removed from the input line. SPACE characters are appended t
o lines that are shorter than their conversion block size to fill the block. Lin
es that are longer than the conversion block size are truncated to the largest n
umber of characters that will fit into that size. The number of truncated lines
is reported.
unblock
Converts fixed-length records to variable length. Reads a number of bytes equal
to the conversion block size (or the number of bytes remaining in the input, if
less than the conversion block size), delete all trailing SPACE characters, and
append a NEWLINE character.
The block and unblock values are mutually exclusive.
lcase
Maps upper-case characters specified by the LC_CTYPE keyword tolower to the corr
esponding lower-case character. Characters for which no mapping is specified are
not modified by this conversion.
ucase
Maps lower-case characters specified by the LC_CTYPE keyword toupper to the corr
esponding upper-case character. Characters for which no mapping is specified are
not modified by this conversion.
The lcase and ucase symbols are mutually exclusive.
swab
Swaps every pair of input bytes. If the current input record is an odd number of
bytes, the last byte in the input record is ignored.
noerror
Does not stop processing on an input error. When an input error occurs, a diagno
stic message is written on standard error, followed by the current input and out
put block counts in the same format as used at completion. If the sync conversio
n is specified, the missing input is replaced with null bytes and processed norm
ally. Otherwise, the input block will be omitted from the output.
notrunc
Does not truncate the output file. Preserves blocks in the output file not expli
citly written by this invocation of dd. (See also the preceding of=file operand.
)
sync
Pads every input block to the size of the ibs= buffer, appending null bytes. (If
either block or unblock is also specified, appends SPACE characters, rather tha
n null bytes.)
If operands other than conv= are specified more than once, the last specified op
erand=value is used.
For the bs=, cbs=, ibs=, and obs= operands, the application must supply an expre
ssion specifying a size in bytes. The expression, expr, can be:
a positive decimal number
a positive decimal number followed by k, specifying multiplication by 1024
a positive decimal number followed by M, specifying multiplication by 1024*1024
a positive decimal number followed by b, specifying multiplication by 512
two or more positive decimal numbers (with or without k or b) separated by x, sp
ecifying the product of the indicated values.