User Tools

Site Tools


dd

If you want to send us your comments, please do so. Thanks
More on comments


dd

Convert and copy a file

See also ddrescue (gddrescue in the Debian repository)
The difference between dd and ddrescue:

  • dd stops the transfer on a read error and displays the error
  • ddrescue notes the error, leaves a blank spot in the output file, and continues transferring what data it can

dd options

See the dd man page for more options

OptionExplanationRemark
bsblocksizeUptil a blocksize of 1 MB dd speeds up. Above 1 MB there is no speed gain
countblock count
ibsread n bytes at a time
ifinput file / device
obswrite n bytes at a time
ofoutput file
skipSkip N ibs-sized blocks at start of input
statusControl the status informationstatus=[none,noxfer,progress]

Examples

pA drive letter
qAn other drive letter
sdDrive inicator
xThe partition number


Read from partition sdp1 and save in some_file.dd

dd if=/dev/sdp1 bs=512 of=/home/user/some_file.dd

Copy a chunck of data from a harddisk to a file

dd if=/dev/sdp of=/mnt/mountedPartition/file.dd ibs=4096 obs=512 skip=10000 count=20000 status=progress
dd if=/dev/sdp of=/mnt/sdq/file.dd ibs=512 obs=1024 seek=20000 count=1000000 status=progress

Read device sdp. Delete all 0x00's. Save the output to file nonull.txt

dd if=/dev/sdp ibs=512 obs=4096 | tr -d '\000' > nonull.txt

Read 2000 blocks of 512 bytes, skip blocks only containing NULL's and show them in hexdump

dd status=progress if=/dev/sdp1 bs=512 conv=sparse count=2000 | hexdump | less

Wipe the MBR (Master Boot Record)

dd if=/dev/zero of=/dev/sdp bs=446 count=1 

SD card

Save the contents of a SDcard to an image file
To check the contents of the image see Mount an img file

dd if=/dev/sdx of=/home/user/SDcard.img bs=4096

Put the contents of an image file on a SDcard

dd if=/home/user/SDcard.img of=/dev/sdd bs=4096

Diskette

Copy all but the last 352 blocks because they contain bad blocks. dd does not have an option to skip bad blocks. A diskette has 2880 blocks of 512 bytes

dd if=/dev/sdc of=diskette.dd bs=512 count=2528 status=progress

Fill with zero's

Create a file filled with zero's

dd bs=1000000 count=1 if=/dev/zero of=hello.txt
dd if=/dev/zero of=~/testfile4.txt bs=20000000 count=1 status=progress

Fill the free space of a partition, hard disk, with zero's:

  1. Boot the computer with a live CD like gParted
  2. CTRL-ALT-F2
  3. cd /mnt
  4. mkdir filltemp
  5. CTRL-ALT-F3
    1. lsblk (to see which partitions are on the computer)
  6. CTRL-ALT-F2
    1. mount /dev/sdX filltemp (replace X with the partitionletter at hand)
    2. df (to see how big, in blocks, the frees space of the partitions is) → SEEdf value of the partition in 1k (1024 bytes) blocks
    3. dd if=/dev/zero of=/mnt/sdX/zerofill.txt bs=1024 count=SEEdf status=progress
    4. umount filltemp
    5. repeat from point 6.a for an other partition. Check with CTRL-ALT-F3 which one if needed

Errors

dd: /dev/sdp: cannot skip: Invalid argument

Solution

  • Check the bs and ibs values in relation to the skip and count values. bs * skip = bytes to skip

ddrescue

ddrescue is a data recovery tool (gddrescue in the Debian repository)
GNU ddrescue manual

ddrescueviewGraphic tool to examine map files
ddrutilityView related files
lziprecoverRecovery tool

Examples

ddrescue -n /dev/sda /home/user/ddrescue.img /home/user/ddrescue.mapfile
ddrescue -f -r3 /dev/sda /dev/sdb /home/user/ddrescue.mapfile

Example output:

GNU ddrescue 1.27
Press Ctrl-C to interrupt
     ipos:  524222 kB, non-trimmed:        0 B,  current rate:  67567 kB/s
     opos:  524222 kB, non-scraped:        0 B,  average rate:  58246 kB/s
non-tried:  159517 MB,  bad-sector:        0 B,    error rate:       0 B/s
  rescued:  524222 kB,   bad areas:        0,        run time:          9s
pct rescued:    0.32%, read errors:        0,  remaining time:         45m
                              time since last successful read:          0s
Copying non-tried blocks... Pass 1 (forwards)

Errors

ddrescue: Can't open input file: Permission denied

You need to be root or use sudo

Loop devices
The fallocate command


Main subjects on this wiki: Linux, Debian, HTML, Microcontrollers, Privacy

RSS
Disclaimer
Privacy statement
Bugs statement
Cookies
Copyright © : 2014 - 2024 Webevaluation.nl and the authors
Changes reserved.

This website uses cookies. By using the website, you agree with storing cookies on your computer. Also you acknowledge that you have read and understand our Privacy Policy. If you do not agree leave the website.More information about cookies
dd.txt · Last modified: 20-01-2024 23:02 by wim