Table of Contents
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
Option | Explanation | Remark |
---|---|---|
bs | blocksize | Uptil a blocksize of 1 MB dd speeds up. Above 1 MB there is no speed gain |
count | block count | |
ibs | read n bytes at a time | |
if | input file / device | |
obs | write n bytes at a time | |
of | output file | |
skip | Skip N ibs-sized blocks at start of input | |
status | Control the status information | status=[none,noxfer,progress] |
Examples
p | A drive letter | |
q | An other drive letter | |
sd | Drive inicator | |
x | The 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:
- Boot the computer with a live CD like gParted
- CTRL-ALT-F2
- cd /mnt
- mkdir filltemp
- CTRL-ALT-F3
- lsblk (to see which partitions are on the computer)
- CTRL-ALT-F2
- mount /dev/sdX filltemp (replace X with the partitionletter at hand)
- df (to see how big, in blocks, the frees space of the partitions is) → SEEdf value of the partition in 1k (1024 bytes) blocks
- dd if=/dev/zero of=/mnt/sdX/zerofill.txt bs=1024 count=SEEdf status=progress
- umount filltemp
- 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
Related packages
ddrescueview | Graphic tool to examine map files |
ddrutility | View related files |
lziprecover | Recovery 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
Useful links
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.