Questions tagged [dd]

A low-level command-line tool on Unix-like operating systems to copy and convert files.

Ref

Examples:

  • Clone the drive sda onto drive sdb:

    `$ dd if=/dev/sda of=/dev/sdb`
    
  • Clone the drive hda onto an image file:

    `$ dd if=/dev/hda of=/image.img`
    
  • Copy a CD or DVD disc to a .iso image file, first unmounting the disc: sudo umount /dev/dvd-device

    dd if=/dev/dvd-device of=dvd.iso bs=2048 conv=sync,notrunc

    # dvd-device will typically be dvd for a dvd disc or cdrom for a cdrom disc.

  • Clone a hard drive to a zipped image file in 100Mb blocks:

    $ dd if=/dev/hda bs=100M | gzip -c > /image.img

  • Create a 10 KB file filled with random data (10 x 1K blocks):

    $ dd if=/dev/random of=random.bin bs=1024 count=10

  • Completely wipe the hard drive hdz by overwriting it with random data:

    $ dd if=/dev/urandom of=/dev/hdz

  • Create a boot floppy:

    $ dd if=boot.img of=/dev/fd0 bs=1440

345 questions
148
votes
5 answers

dd: How to calculate optimal blocksize?

How do you calculate the optimal blocksize when running a dd? I've researched it a bit and I've not found anything suggesting how this would be accomplished. I am under the impression that a larger blocksize would result in a quicker dd... is this…
eckza
  • 2,212
  • 3
  • 22
  • 28
65
votes
1 answer

Why using conv=notrunc when cloning a disk with dd?

If you look up how to clone an entire disk to another one on the web, you will find something like that: dd if=/dev/sda of=/dev/sdb conv=notrunc,noerror While I understand the noerror, I am getting a hard time understanding why people think that…
Undo
  • 1,165
  • 2
  • 10
  • 15
53
votes
7 answers

How to create an .IMG image of a disc (sd card) without including free space?

In Linux, we can do dd if=/dev/sdb of=bckup.img but if the disk is of 32GB with only 4GB used, the 32GB image file is waste of space-time. Is there any way or tool to create images with only valid data?
Necktwi
  • 2,483
  • 7
  • 39
  • 62
44
votes
6 answers

Using grep to search for hex strings in a file

Does anyone know how to get grep, or similar tool, to retrieve offsets of hex strings in a file? I have a bunch of hexdumps (from GDB) that I need to check for strings and then run again and check if the value has changed. I have tried hexdump and…
user650649
  • 495
  • 1
  • 5
  • 10
30
votes
1 answer

How to overwrite some bytes of a binary file with dd?

I have a binary file and i want to replace the value A2 at address DEADBEEF with some other value, say A1. How can I do this with dd? If there are other tools that can do this, please suggest. But I plan to do this on iPhone so I can only work with…
Wei Shi
  • 4,945
  • 8
  • 49
  • 73
27
votes
1 answer

Why is dd with the 'direct' (O_DIRECT) flag so dramatically faster?

I have a server with a RAID50 configuration of 24 drives (two groups of 12), and if I run: dd if=/dev/zero of=ddfile2 bs=1M count=1953 oflag=direct I get: 2047868928 bytes (2.0 GB) copied, 0.805075 s, 2.5 GB/s But if I run: dd if=/dev/zero…
Joseph Garvin
  • 20,727
  • 18
  • 94
  • 165
21
votes
2 answers

dd a compressed *.xz image into a partition

I'm trying to copy a compressed image into a partition inside a Beaglebone. Usually, it is a 2 step process: xz -d console.img.xz # console.img is created dd if=console.img of=/dev/mmcblk0p3 Is there a way, I can do it in a single step without…
Sayanee
  • 4,957
  • 4
  • 29
  • 35
15
votes
1 answer

create a virtual floppy image without mount?

There are a lot of posts to show to create a virtual floppy image file as a super user or users can run sudo command. The basic steps are: create empty 1.44MB image file by dd command format the image file by mkfs.msdos mount the image file to some…
Congbin Guo
  • 1,685
  • 2
  • 16
  • 16
14
votes
3 answers

Not understanding dd command arguments at all

I'm passingly familiar with the dd command, but I've rarely had the need to use it myself. Today I need to, but I'm encountering behavior that seems really weird. I want to create a 100M text file, each line of which contains the single word…
Sean
  • 29,130
  • 4
  • 80
  • 105
14
votes
4 answers

How to extract the first x-megabyte from a large file in unix/linux?

I have a large file which I am only interested in the first couple of megabytes in the head. How do I extract the first x-megabyte from a large file in unix/linux and put it into a seperate file? (I know the split command can split files into many…
umps
  • 1,119
  • 4
  • 15
  • 25
12
votes
4 answers

Windows Powershell command line equivalent of dd

I am writing a Powershell script to make a raw copy of a drive and I have been unable to find a way to complete this. On Linux, I would use 'dd' to perform this copy. There are a handful of tools that can do this on Windows but none that I can…
R3dChief
  • 181
  • 1
  • 1
  • 9
12
votes
2 answers

Creating a bootable ISO image with custom bootloader

I am trying to convert a bootloader I wrote in Assembly Language to an ISO image file. The following is the code from MikeOS bootloader. Here is my bootloader code: BITS 16 start: mov ax, 07C0h ; Set up 4K stack space after this…
Mahmoud Abdel-Rahman
  • 497
  • 2
  • 10
  • 27
12
votes
4 answers

how to make an image of android partition to your pc

I am trying to make a backup (a direct dd image of the partitions of my built-in memory card of my phone to my PC. I am using Linux and my phone is a Nexus 4.
hongo
  • 687
  • 1
  • 6
  • 10
10
votes
2 answers

dd: opening `/dev/sdb': Permission denied

I'm trying to write a linux image in a CF card, as is shown in *: When I do: sudo bzcat debian-for-alix-cf2g.img.bz2 | dd of=/dev/sdb bs=16k I get: dd: opening `/dev/sdb': Permission denied I can see in mtab that /dev/sdb corresponds to the…
Guillermo Parada
  • 199
  • 1
  • 1
  • 6
9
votes
3 answers

Copy n bytes of data x to file

How we can copy for example 10 bytes of '7' to a file? How can I generate those 10 bytes of 7? For example for n bytes of zero I'm doing dd if=/dev/zero of=myFile bs=1 count=10.
Mike Egren
  • 205
  • 1
  • 3
  • 7
1
2 3
22 23