swab 交换输入的每对字节。
Unlike theUnix dd, this works when an odd number of bytes are read. If
the input file contains an odd number of bytes, the last byte is simply
copied (since there is nothing to swap it with).
The basic command is structured as follows: dd
if= of= bs=(some power of
2, not less than 512 bytes(ie, 512, 1024, 2048, 4096, 8192, 16384)
conv=. Source is the data being read. Target is
where the data gets written. If you mess up, and accidently reverse the
source and target, you can wipe out a lot of data.
Examples::
Copy one hard disk partition to another hard disk:
sda2,
sdb2 are partitions. You want to copy sda2 to sdb2. If sdb2 doesn't
exist, dd will start at the beginning of the disk, and create it. Be
careful with order of if and of. You can write a blank disk to a good
disk if you get confused.
CD
sectors are 2048 bytes, so this copies sector for sector. The result
will be a hard disk image file of the CD. You can use "chmod a+rwx
mycd.iso" to make the image writable. You can mount the image with
"mkdir /mnt/mycd", this line in fstab: "/home/sam/mycd.iso /mnt/mycd
iso9660 rw,user,noauto 0 0", save fstab, "mount -o loop /mnt/mycd". Then
the file system will be viewable as files and directories in the
directory /mnt/mycd. You can edit the image as you wish, and the new
file will be "/home/sam/mycd.iso" dd does not write to CD's. You need to
use a burning utility, or the cdrdao command
The
18b specifies 18 sectors of 512 bytes, the 2x multiplies the sector
size by the number of heads, and the 80x is for the cylinders--a total
of 1474560 bytes. This issues a single 1474560-byte read request to
/dev/fd0 and a single 1474560 write request to /tmp/floppy.image. This
makes a hard drive image of the floppy, with bootable info intact.
in
this example, sda is the source. sdb is the target. Do not reverse the
intended source and target. Surprisingly many people do. notrunc means
to not truncate. noerror means to keep going if there is an error.
Normally dd stops at any error. if you have a question about a hard
drive on whether or not it works, you can try to use it as the source
drive for the dd command. You should get an error if it is not working.
target drives need to be really messed up to give an error in dd.
this
will copy the first 446 bytes of the hard drive to a file. If you
haven't already guessed, reversing the objects of if and of, in the dd
command line reverses the direction of the write.
Wipe a hard drive of all data (you would want to boot from a cd to do this) is a good boot cd
the helix boot environment contains the DoD version of dd called dcfldd. It works the same way, but is has a progress bar.
dd if=/dev/zero of=/dev/sda conv=notrunc
This is useful for getting rid of viruses, DRM trojans and the like.
It would be useful, at this time to interject a tip:
I
have several machines, but on the one I use a lot I have two SATA hard
drives. They are exactly the same. Before I do anything dangerous, I
boot from the helix CD, run
Please
note: bs=4096 works fast for machines with at least 128 MB of ram. dd
uses a lot of buffers. At bs=4096, on modern machines, the optimal
transfer rate is reached for hard drives.
Here,
urandom is the linux random byte device. myrandom is a file. Byte size
equals 1 and there are 100 of them. Gpg requires a random seed to
generate keys. Generating a file of say 4096 random bytes, which can be
passed to Gpg, will allow a truly random seed.
Write random data over a file before deleting it: first do an ls -l to find filesize. In this case it is 3769
ls -l afile -rw------- ... 3769 Nov 2 13:41 dd if=/dev/urandom of= \ bs=3769 count=1 conv=notrunc
This will write random characters over the entire file.
Copy a disk partition to a file on a different partition. Do not copy a partition to the same partition.
This
way you can get a bazonga hard drive and partition it so you can back
up your root partition. If you mess up your root partition, you just
boot from the helix cd and restore the image.
To covert a file to all uppercase:
dd if=filename of=filename conv=ucase
Copy ram memory to a file:
dd if=/dev/mem of=/home/sam/mem.bin bs=1024
The
device /dev/mem is your system memory. You can actually copy any blobk
or character 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 to hard drive takes about 10 minutes. Copying a
floppy to a hard drive takes about 2 minutes. With dd, your floppy drive
images will not change at all. If you have a bootable DOS diskette, and
you save it to your HDD as an image file, when you 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 exact copy of the original.