| #1 | ||||
|
Member
Registered: Jan 2005
Location: USA
Distribution: Debian Etch, Lenny
Posts: 857
|
This
document is made to be easily skimmed. The latest addition was on
01-05-08, "Brief notes for Microsoft Windows XP and Windows Vista
users". This is comprehensive
documentation for one of the most useful linux/UNIX Windows
commands-dd. It is a bitstream duplicator for copying data. If you have a question, post it.
Windows users will find help about 50 lines down from here. First Time visitors please leave a reply. Copying smaller partition, or drive to larger partition, or drive; or vice versa Code:
rsync -rv mount_point/* other_mount_point/ Code:
grub-install Brief notes for Microsoft Windows XP and Windows Vista users Using Windows XP is no excuse for not using dd for all your drive cloning, backup, upgrading, and restore tasks. Boot a Windows XP machine with a Knoppix CD, a live CD operating system that is self contained, and doesn't use the hard drive. You can download Knoppix, burn the iso image file to a CD, boot with it, and clone drives. Drives are described to the dd command using device files. When you boot into Knoppix, which is Linux, you want to open a root command prompt, or root terminal shell. Parallel IDE (80 conductor grey ribbon cable), the first drive (master) on channel 0 is /dev/hda. The second drive (slave) on IDE channel 0 (The first IDE channel), is /dev/hdb. SATA, no matter if there there are also IDE hard drives, are /dev/sda and /dev/sdb. In the root shell you can enter commands: Code:
fdisk -l /dev/hda Code:
man fdisk Code:
man parted Please note: Performance of Knoppix Linux does not indicate performance of Linux overall. Knoppix Linux runs on a CD drive (1/1000 the speed of an HDD). Linux is high performance, giving power users the speed and flexibility to do High Performance Computing. The Knoppix CD has over 1 GB of software, in compressed format. Feel free to read the entire post. Dd is not presently able to clone Microsoft Windows Vista OEM Partitions. End Windows Section When to use the 'conv=sync' option Pressed CDs are difficult accurately write to a HDD, because there are sectors that fool dd. The image file (.iso) will usually work properly, but MS Windows CDs are fussy. Here is how to make a perfect copy of a CD to a HDD image file: Code:
dd if=/dev/hdc of=/home/sam/CD_Image_File.iso bs=2048 conv=sync,noerror Begin Linux dd The basic command is structured as follows: Code:
dd if=<source> of=<target> bs=<byte size>("USUALLY" some power of 2, not less than 512 bytes(ie, 512, 1024, 2048, 4096, 8192, 16384, but can be ANY reasonable number.) skip= seek= conv=<conversion>.[/b]
Warning!! If you reverse the source and target, you can wipe out a lot of data. This feature has inspired the nickname "dd" Data Destroyer. Warning!! Caution should be observed when using dd to copy encrypted partitions. How to make a swap file, or another swapfile on a running system: Code:
dd if=/dev/zero of=/swapspace bs=4k count=250000 New How to pick proper block size: Code:
time dd if=/dev/zero bs=1024 count=1000000 of=/home/sam/1Gb.file Read: Code:
time dd if=/home/sam/1Gb.file bs=64k | dd of=/dev/null Code:
time dd if=/dev/zero bs=1024 count=1000000 of=/home/sam/1Gb.file Code:
1000000+0 records in How to rejuvenate a hard drive This will sometimes cure input/output errors experienced when using dd. Over time the data on a drive, especially a drive that hasn't been used for a year or two grows into larger magnetic flux points than were originally recorded. This makes it hard for the drive heads to decipher these magnetic flux points. This results in read/write errors. Also, sometimes sector 1 goes bad resulting in a useless drive. All you need to do is: Code:
dd if=/dev/sda of=/dev/sda Examples: Copy one hard disk partition to another hard disk: Code:
dd if=/dev/sda2 of=/dev/sdb2 bs=4096 conv=notrunc,noerror Code:
dd if=/dev/sda skip=2 of=/dev/sdb seek=2 bs=4k conv=noerror Code:
fdisk -l Code:
df -h Code:
dd if=smaller_partition of=/home/sam/smaller_partition.img Code:
mount -o loop /home/sam/smaller_partition.img /mnt/directory Code:
dd if=/dev/sda3 of=/dev/sda2 bs=4096 conv=notrunc,noerror Make an iso image of a CD: Code:
dd if=/dev/hdc of=/home/sam/mycd.iso bs=2048 conv=notrunc Code:
mkdir /mnt/mycd Code:
/home/sam/mycd.iso /mnt/mycd iso9660 rw,user,noauto 0 0 Code:
"mount -o loop /mnt/mycd". Code:
/mnt/mycd Code:
dd if=/dev/fd0 of=/home/sam/floppy.image bs=2x80x18b conv=notrunc Code:
dd if=/dev/fd0 of=/home/sam/floppy.image conv=notrunc Code:
/home/sam/floppy.image This makes a hard drive image of the floppy, with bootable info intact. The second example uses default "bs=" of 512, which is the sector size of a floppy.If you're concerned about spies with superconducting quantum-interference detectors you can always add a "for" loop for government level secure disk erasure: copy and paste the following two lines into a text editor. Code:
#!/bin/bash Code:
chmod a+x <shellscriptfile> To make a bootable USB thumb drive: Download 50 MB Debian based distro here: http://sourceforge.net/projects/insert/ Plug in the thumb drive to a USB port. Do: Code:
dmesg | tail Code:
dd if=/home/sam/insert.iso of=/dev/sdb ibs=4b obs=1b conv=notrunc,noerror Copy just the MBR and boot sector of a floppy to hard drive image: Code:
dd if=/dev/fd0 of=/home/sam/MBRboot.image bs=512 count=2 Cloning an entire hard disk:[/color] Code:
dd if=/dev/sda of=/dev/sdb conv=notrunc,noerror Copy MBR only of a hard drive: [/color] Code:
dd if=/dev/sda of=/home/sam/MBR.image bs=446 count=1 Wipe a hard drive of all data (you would want to boot from a cd to do this)[/color] http://www.efense.com/helix 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. Code:
dcfldd if=/dev/zero of=/dev/sda conv=notrunc Overwrite all the free space on a partition (deleted files you don't want recovered)[/color] Code:
dd if=/dev/urandom > fileconsumingallfreespace Code:
rm To view your virtual memory: Code:
dd if=/proc/kcore | hexdump -C | less What filesystems are installed: Code:
dd if=/proc/filesystems | hexdump -C | less Code:
dd if=/proc/kallsyms | hexdump -C | less Code:
dd if=/proc/interrupts | hexdump -C | less Code:
dd if=/proc/uptime | hexdump -C | less Code:
dd if=/proc/partitions | hexdump -C | less Code:
dd if=/proc/meminfo | hexdump -C | less Code:
dcfldd if=/dev/sda of=/dev/sdb bs=4096 conv=notrunc,noerror Code:
dcfldd if=/dev/sdb of=/dev/sda bs=4096 conv=notrunc,noerror Code:
dd if=/dev/sda2 (root) of /home/sam/root.img bs=4096 conv=notrunc,noerror Code:
dd if /home/sam/root.img of=/dev/sda2 (root) bs=4096 conv=notrunc,noerror To make a file of 100 random bytes: Code:
dd if=/dev/urandom of=/home/sam/myrandom bs=100 count=1 Write random data over a file before deleting it: first do an Code:
ls -l In this case it is 3769 Code:
ls -l afile -rw------- ... 3769 Nov 2 13:41 <filename> Code:
dd if=/dev/urandom of=afile bs=3769 count=1 conv=notrunc Copy a disk partition to a file on a different partition. Warning!! Do not copy a partition to the same partition. Code:
dd if=/dev/sdb2 of=/home/sam/partition.image bs=4096 conv=notrunc,noerror Code:
dd if=/dev/sdb2 ibs=4096 | gzip > partition.image.gz conv=noerror Code:
| gunzip > Code:
.bz2 Code:
dd if=/home/sam/partition.image of=/dev/sdb2 bs=4096 conv=notrunc,noerror Code:
dd if=filename of=filename conv=ucase The Linux kernel usually makes a number a ramdisks you can make into ramdrives. You have to populate the drive with zeroes like so: Code:
dd if=/dev/zero of=/dev/ram7 bs=1k count=16384 Code:
mke2fs -m0 /dev/ram7 4096 Code:
debian:/home/sam # hdparm -t /dev/ram7 Code:
mkdir /mnt/mem Copy ram memory to a file: Code:
dd if=/dev/mem of=/home/sam/mem.bin bs=1024 Code:
/dev/mem dd will print to the terminal window if you omit the Code:
of=/dev/output Code:
dd if=/home/sam/myfile To search the system memory: [/color] Code:
dd if=/dev/mem | hexdump -C | grep 'some-string-of-words-in-the-file-you-forgot-to-save-before-the-power-failed' Code:
mkdir /mnt/mem Code:
mount -t ramfs /dev/mem /mnt/mem Code:
dd if=/dev/zero > /mnt/mem/bigfile.file If you are just curious about what might be on you disk drive, or what an MBR looks like, or maybe what is at the very end of your disk: Code:
dd if=/dev/sda count=1 | hexdump -C 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 MNA of the disk. For a 120 GB Seagate SATA drives Code:
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 myfile. Even with LBA addressing Disks still secretly are read in sectors, cylinders, and heads. There are 63 sectors per cylinder, and 255 heads per cylinder. Then there is a total cylinder count for the disk. You multiply out 512x63x255=bytes per cylinder. 63x255=sectors per cylinder. With 234441647 total sectors, and 16065 sectors 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 partitioned because to be in a partition you have to be a whole cylinder. 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 after the last partition. 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 our Seagate 120 GB drive you subtract total sectors(234441647)-(5102) which don't make up a whole cylinder=234436545 partitionable sectors. Code:
dd if=/dev/sda of=/home/sam/myfile skip=234436545 Code:
dd if=/dev/urandom of=/dev/sda bs=512 seek=234436545 Block size: One cylinder in LBA mode = 255 heads * 63 sectors per track = 16065 sectors = 16065 * 512 bytes = 16065b. The b means '* 512'. 32130b represents a two cylinder block size. When using cylinder sized block sizes you never need to worry about that last fraction of a block not being copied because partitions are made of a whole number of cylinders. Partitions cannot contain partial cylinders. One cylinder is 8,225,280 bytes. If you want to check out some random area of the disk: Code:
dd if=/dev/sda of=/home/sam/myfile bs=4096 skip=2000 count=1000 Code:
dd if=/home/sam/myfile of=/dev/sda bs=4096 seek=2000 count=1000 You can make a boot floppy:With the Code:
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. If you want to make a partition image on another machine: on source machine: Boot both machines with the helix CD just to be extra sure. Then, Code:
dd if=/dev/hda bs=16065b | netcat targethost-IP 1234 Code:
netcat -l -p 1234 | dd of=/dev/hdc bs=16065b Alert!! Don't hit enter yet. Hit enter on the target machine, hit enter on the source machine. CONTINUES...SEE NEXT POST dd will not copy or erase an HPA or host protected area. If used properly dd will erase a disk completely, but not as well as using the hardware secure erase, security erase unit command Dd need not be black boxed like other inexpensive forensic software. See the following link: http://www.cftt.nist.gov/ For a low cost bootable CD based professional ghosting solution, that supports all operating systems and file systems: http://www.feyrer.de/g4u/ Dd is like Symantec Norton Ghost, Acronis True Image, Drive Image, . You can perform disk drive backup, restore, imaging, disk image, cloning, clone, drive cloning, transfer image, transfer data, clone to another drive or clone to another machine, move Windows XP to a new hard drive, clone Windows XP, clone Windows, transfer Windows, hard drive upgrade, copy a boot drive, copy a bootable drive, upgrade your operating system hard drive, Tired of reinstalling WinXP Windows XP? Last edited by AwesomeMachine : 01-06-2008 at 03:00 AM. Reason: revision |
|||
|
|
|
|
||
|
|
#2 | |
|
Member
Registered: Jan 2005
Location: USA
Distribution: Debian Etch, Lenny
Posts: 857
|
You
want to find out if your girlfriend is cheating on you, having cyber
whoopie, or just misbehaving. Even if the computer is secured with a
password you can boot with the:
http://www.efense.com/helix CD and search the entire drive partition for text strings: Code:
dd if=/dev/sda2 bs=16065 | hexdump -C | grep 'I really don't love him anymore.' Code:
dd if=/dev/sda2 bs=16065 skip=2140 count=3 | less Code:
cdrecord dev=ATAPI:0,1,0 -raw tsize=700000000 driveropts=burnfree /dev/mem [/color] Code:
cdrecord -scanbus=ATAPI Code:
dd if=/dev/hdd | less Code:
dd if=/dev/hdd | hexdump -C | grep 'string' list: Code:
'[[:alnum:]]' any alphanumeric characters Code:
dd if=/dev/sda of=mbr.bin count=1 Code:
dd if=boot.img of=/dev/fd0 Code:
dd if=mbr.bin of=/dev/sda count=1 Code:
dd if=/dev/fd0 of=/home/sam/floppies/backup.bin conv=notrunc Code:
dd if=/home/sam/floppies/backup.bin of=/dev/fd0 conv=notrunc Code:
dd if=/dev/mem bs=1k skip=768 count=256 2>/dev/null | strings -n 8 |
|



