[GUIDE] The dd command for noobs.

Search This thread

teh5abiking

Senior Member
Feb 15, 2011
94
50
New York, NY
This is really just a look back at the dd command, and its usage in the world of rooting. For the sake of this guide, we'll be using an HTC Vision. Let's start with something that looks similar to a command that was used before gfree was available.

Code:
dd if=/dev/block/mmcblk0p18 of=/sdcard/hboot-eng.img

dd is the command that allows you to copy files from certain areas that normally aren't accessible in a UNIX/Linux filesystem via a command line. However, a risk factor does come in when using this command because a small mistake such as reversing the "if" and "of" parameters can result in loss of data and/or a brick. This is why it often garners the nickname of "disk destroyer" etc.

if" is a parameter stands for "input file" so /dev/block/ is the directory in which the file is contained.

mmcblk0p18 is an Android specific partition that contains the current SPL (Secondary Program Loader).

"of" stands for output file. in this case, we have "of=/sdcard/hboot-eng.img" which means that the output file will be an .img file in the sdcard of your device.

In total, the above command "dd if=/dev/block/mmcblk0p18 of=/sdcard/hboot-eng.img" copies the files that is in partition 18 and then pastes it on the root of your sdcard as the file "hboot-eng.img"

The dd command was used to install the Engineering SPL as a means to achieve S-OFF since the G2/Desire Z/Vision couldn't be S-OFF at the time without the use of the Engineering SPL. Also, the dd command can be used as a method to manually edit the misc partition in order to unroot the device if you don't care for misc_version OR don't have access to it at present moment,

However, present root/unroot methods pretty much renders the dd command as obsolete when it comes to Android devices.
 

dhkr234

Senior Member
Jan 27, 2011
570
158
That is quite a superficial look at the 'dd' command. In fact, the dd command is not much more than a pipe. In its standard form, it just conveys standard input to standard output. "cat filename | dd > destination". Or even more simply "cat filename > destination" -- remove the 'dd' command altogether -- this is the equivalent of 'dd if=filename of=destination'.

Unix "sees" things as big linear chunks of memory, laid out as files within the filesystem. It is just a matter of reading and writing it, and this is done no differently than reading and writing any other file... that is why these devices are visible as parts of the regular filesystem and not as some magical background devices that need special hacker voodoo to play with.

The power of the 'dd' command isn't in a straight copy (what is used in above example), but in its ability to "seek" and to limit lengths and other such fun things. You can also alter the sizes of reads/writes to synchronize with the media you are reading/writing. For example "dd if=infile of=outfile skip=500 seek=500 ibs=1024 obs=1024 count=2048"
This command will read from infile starting 500 blocks of 1024 bytes (i.e. 500x1024 bytes) from the start of the file, and write beginning at 500 blocks of 1024 bytes past the start of the output file, and will copy a total of 2048 input blocks.

The funny thing about playing about with full partitions on these phones is that the "cat" command will be just as effective -- 'dd' is unnecessary. "cat /dev/block/mmcblk0p18 >/sdcard/hboot-eng.img" will do the exact same thing.

So... the 'dd' command *could* be used within such hacks as gfree to alter ONLY the PART of the partitions that need to be modified, rather than reading the full partition, making changes, and writing the whole thing back. Technically, this would be much more safe since it wouldn't involve wiping and rewriting the entire thing -- imagine something crashed right after the wipe and before you had the opportunity to write the new one. Use of 'dd' for this purpose would allow the majority of the partition to remain unaltered, and therefore STILL FUNCTIONAL, even if something bad happened.
 

teh5abiking

Senior Member
Feb 15, 2011
94
50
New York, NY
That is quite a superficial look at the 'dd' command. In fact, the dd command is not much more than a pipe. In its standard form, it just conveys standard input to standard output. "cat filename | dd > destination". Or even more simply "cat filename > destination" -- remove the 'dd' command altogether -- this is the equivalent of 'dd if=filename of=destination'.

Unix "sees" things as big linear chunks of memory, laid out as files within the filesystem. It is just a matter of reading and writing it, and this is done no differently than reading and writing any other file... that is why these devices are visible as parts of the regular filesystem and not as some magical background devices that need special hacker voodoo to play with.

The power of the 'dd' command isn't in a straight copy (what is used in above example), but in its ability to "seek" and to limit lengths and other such fun things. You can also alter the sizes of reads/writes to synchronize with the media you are reading/writing. For example "dd if=infile of=outfile skip=500 seek=500 ibs=1024 obs=1024 count=2048"
This command will read from infile starting 500 blocks of 1024 bytes (i.e. 500x1024 bytes) from the start of the file, and write beginning at 500 blocks of 1024 bytes past the start of the output file, and will copy a total of 2048 input blocks.

The funny thing about playing about with full partitions on these phones is that the "cat" command will be just as effective -- 'dd' is unnecessary. "cat /dev/block/mmcblk0p18 >/sdcard/hboot-eng.img" will do the exact same thing.

So... the 'dd' command *could* be used within such hacks as gfree to alter ONLY the PART of the partitions that need to be modified, rather than reading the full partition, making changes, and writing the whole thing back. Technically, this would be much more safe since it wouldn't involve wiping and rewriting the entire thing -- imagine something crashed right after the wipe and before you had the opportunity to write the new one. Use of 'dd' for this purpose would allow the majority of the partition to remain unaltered, and therefore STILL FUNCTIONAL, even if something bad happened.
i wrote this at like 4 in the morning (jet lag -_-)

i'll fix it soon
 
  • Like
Reactions: rommy0515

DanWilson

Senior Member
Oct 8, 2010
1,326
54
Glasgow
how would I use the 'dd' command on windows to root an HTC phone?

It involves more than just that.
Is your phone even a G2/Desire Z? If it is, use the tool in the Development section.
If it isn't, go to the correct forum for it. I ain't kicking you out of here, but we can't help you if you have an Evo 3D or something.
 

DoktorKot

New member
Oct 15, 2012
1
0
I have another noob question:
My device is Samsung galaxy tab GT-P7300.
I need to clone the 12GB data partition from device to microsd flash 16GB. Closest and puriest way i have found is dd command.
As well as everybody knows, it is impossible to create a file larger than 4GB in fat32 filesystem BUT it is the only fileystem that this device understands as native(any other(ext3 ext4 ntfs) need special moves to mount and cloning process can not be guaranteed as clean, i.e. without convertation).

Device is already rooted and i'm using terminal to use *nix commands

Please advise, how to use dd command to skip first 4GB and start creating next 4GB file and so on???
 

gee one

Senior Member
Jul 29, 2010
1,979
866
linux command line
The beauty about linux is that anyone can be a command line commando simply by using the built-in help.

Try "dd --help"

you'll want something like dd if=/blah/blah/partition of=/blah/blah/memcard bs=1 skip=4G (bs=1M skip=4096 might be faster, but check the math, base 2 vs base 10, ln vs log, etc)
 

DVS_Sokar

Senior Member
Apr 26, 2009
499
154
Sacramento,CA
That is quite a superficial look at the 'dd' command. In fact, the dd command is not much more than a pipe. In its standard form, it just conveys standard input to standard output. "cat filename | dd > destination". Or even more simply "cat filename > destination" -- remove the 'dd' command altogether -- this is the equivalent of 'dd if=filename of=destination'.

Unix "sees" things as big linear chunks of memory, laid out as files within the filesystem. It is just a matter of reading and writing it, and this is done no differently than reading and writing any other file... that is why these devices are visible as parts of the regular filesystem and not as some magical background devices that need special hacker voodoo to play with.

The power of the 'dd' command isn't in a straight copy (what is used in above example), but in its ability to "seek" and to limit lengths and other such fun things. You can also alter the sizes of reads/writes to synchronize with the media you are reading/writing. For example "dd if=infile of=outfile skip=500 seek=500 ibs=1024 obs=1024 count=2048"
This command will read from infile starting 500 blocks of 1024 bytes (i.e. 500x1024 bytes) from the start of the file, and write beginning at 500 blocks of 1024 bytes past the start of the output file, and will copy a total of 2048 input blocks.

The funny thing about playing about with full partitions on these phones is that the "cat" command will be just as effective -- 'dd' is unnecessary. "cat /dev/block/mmcblk0p18 >/sdcard/hboot-eng.img" will do the exact same thing.

So... the 'dd' command *could* be used within such hacks as gfree to alter ONLY the PART of the partitions that need to be modified, rather than reading the full partition, making changes, and writing the whole thing back. Technically, this would be much more safe since it wouldn't involve wiping and rewriting the entire thing -- imagine something crashed right after the wipe and before you had the opportunity to write the new one. Use of 'dd' for this purpose would allow the majority of the partition to remain unaltered, and therefore STILL FUNCTIONAL, even if something bad happened.

You seem to have a better grasp then I on DD.

I am trying to reverse the process of reading what value is in a certain partition. I am using the dd commands below to write a hex value. I would also like to accomplish the opposite and read what the value is at that location. Is this possible?

echo -ne '\x00\x00\x00\x00' | dd of =/dev/block/mmcblk0p3 bs=1 seek=33796 // This tells the HTC bootloader to Show Locked on Bootloader flag
or
echo -ne 'HTCU' | dd of =/dev/block/mmcblk0p3 bs=1 seek=33796 // This tells the HTC Bootloader to Show Unlocked on the Bootloader flag

Based on what you have said about of=/ is out file. Which is confusing based on the command line above.

However the command works and sets the HTC device's Bootloader flag to Null which reads as Unlocked.

I am trying to programatically read that partition and report back to the user the state using C#. Can I use the DD command to accomplish this?
 
  • Like
Reactions: jvchawk

Top Liked Posts

  • There are no posts matching your filters.
  • 6
    This is really just a look back at the dd command, and its usage in the world of rooting. For the sake of this guide, we'll be using an HTC Vision. Let's start with something that looks similar to a command that was used before gfree was available.

    Code:
    dd if=/dev/block/mmcblk0p18 of=/sdcard/hboot-eng.img

    dd is the command that allows you to copy files from certain areas that normally aren't accessible in a UNIX/Linux filesystem via a command line. However, a risk factor does come in when using this command because a small mistake such as reversing the "if" and "of" parameters can result in loss of data and/or a brick. This is why it often garners the nickname of "disk destroyer" etc.

    if" is a parameter stands for "input file" so /dev/block/ is the directory in which the file is contained.

    mmcblk0p18 is an Android specific partition that contains the current SPL (Secondary Program Loader).

    "of" stands for output file. in this case, we have "of=/sdcard/hboot-eng.img" which means that the output file will be an .img file in the sdcard of your device.

    In total, the above command "dd if=/dev/block/mmcblk0p18 of=/sdcard/hboot-eng.img" copies the files that is in partition 18 and then pastes it on the root of your sdcard as the file "hboot-eng.img"

    The dd command was used to install the Engineering SPL as a means to achieve S-OFF since the G2/Desire Z/Vision couldn't be S-OFF at the time without the use of the Engineering SPL. Also, the dd command can be used as a method to manually edit the misc partition in order to unroot the device if you don't care for misc_version OR don't have access to it at present moment,

    However, present root/unroot methods pretty much renders the dd command as obsolete when it comes to Android devices.
    3
    That is quite a superficial look at the 'dd' command. In fact, the dd command is not much more than a pipe. In its standard form, it just conveys standard input to standard output. "cat filename | dd > destination". Or even more simply "cat filename > destination" -- remove the 'dd' command altogether -- this is the equivalent of 'dd if=filename of=destination'.

    Unix "sees" things as big linear chunks of memory, laid out as files within the filesystem. It is just a matter of reading and writing it, and this is done no differently than reading and writing any other file... that is why these devices are visible as parts of the regular filesystem and not as some magical background devices that need special hacker voodoo to play with.

    The power of the 'dd' command isn't in a straight copy (what is used in above example), but in its ability to "seek" and to limit lengths and other such fun things. You can also alter the sizes of reads/writes to synchronize with the media you are reading/writing. For example "dd if=infile of=outfile skip=500 seek=500 ibs=1024 obs=1024 count=2048"
    This command will read from infile starting 500 blocks of 1024 bytes (i.e. 500x1024 bytes) from the start of the file, and write beginning at 500 blocks of 1024 bytes past the start of the output file, and will copy a total of 2048 input blocks.

    The funny thing about playing about with full partitions on these phones is that the "cat" command will be just as effective -- 'dd' is unnecessary. "cat /dev/block/mmcblk0p18 >/sdcard/hboot-eng.img" will do the exact same thing.

    So... the 'dd' command *could* be used within such hacks as gfree to alter ONLY the PART of the partitions that need to be modified, rather than reading the full partition, making changes, and writing the whole thing back. Technically, this would be much more safe since it wouldn't involve wiping and rewriting the entire thing -- imagine something crashed right after the wipe and before you had the opportunity to write the new one. Use of 'dd' for this purpose would allow the majority of the partition to remain unaltered, and therefore STILL FUNCTIONAL, even if something bad happened.
    1
    That is quite a superficial look at the 'dd' command. In fact, the dd command is not much more than a pipe. In its standard form, it just conveys standard input to standard output. "cat filename | dd > destination". Or even more simply "cat filename > destination" -- remove the 'dd' command altogether -- this is the equivalent of 'dd if=filename of=destination'.

    Unix "sees" things as big linear chunks of memory, laid out as files within the filesystem. It is just a matter of reading and writing it, and this is done no differently than reading and writing any other file... that is why these devices are visible as parts of the regular filesystem and not as some magical background devices that need special hacker voodoo to play with.

    The power of the 'dd' command isn't in a straight copy (what is used in above example), but in its ability to "seek" and to limit lengths and other such fun things. You can also alter the sizes of reads/writes to synchronize with the media you are reading/writing. For example "dd if=infile of=outfile skip=500 seek=500 ibs=1024 obs=1024 count=2048"
    This command will read from infile starting 500 blocks of 1024 bytes (i.e. 500x1024 bytes) from the start of the file, and write beginning at 500 blocks of 1024 bytes past the start of the output file, and will copy a total of 2048 input blocks.

    The funny thing about playing about with full partitions on these phones is that the "cat" command will be just as effective -- 'dd' is unnecessary. "cat /dev/block/mmcblk0p18 >/sdcard/hboot-eng.img" will do the exact same thing.

    So... the 'dd' command *could* be used within such hacks as gfree to alter ONLY the PART of the partitions that need to be modified, rather than reading the full partition, making changes, and writing the whole thing back. Technically, this would be much more safe since it wouldn't involve wiping and rewriting the entire thing -- imagine something crashed right after the wipe and before you had the opportunity to write the new one. Use of 'dd' for this purpose would allow the majority of the partition to remain unaltered, and therefore STILL FUNCTIONAL, even if something bad happened.
    i wrote this at like 4 in the morning (jet lag -_-)

    i'll fix it soon
    1
    That is quite a superficial look at the 'dd' command. In fact, the dd command is not much more than a pipe. In its standard form, it just conveys standard input to standard output. "cat filename | dd > destination". Or even more simply "cat filename > destination" -- remove the 'dd' command altogether -- this is the equivalent of 'dd if=filename of=destination'.

    Unix "sees" things as big linear chunks of memory, laid out as files within the filesystem. It is just a matter of reading and writing it, and this is done no differently than reading and writing any other file... that is why these devices are visible as parts of the regular filesystem and not as some magical background devices that need special hacker voodoo to play with.

    The power of the 'dd' command isn't in a straight copy (what is used in above example), but in its ability to "seek" and to limit lengths and other such fun things. You can also alter the sizes of reads/writes to synchronize with the media you are reading/writing. For example "dd if=infile of=outfile skip=500 seek=500 ibs=1024 obs=1024 count=2048"
    This command will read from infile starting 500 blocks of 1024 bytes (i.e. 500x1024 bytes) from the start of the file, and write beginning at 500 blocks of 1024 bytes past the start of the output file, and will copy a total of 2048 input blocks.

    The funny thing about playing about with full partitions on these phones is that the "cat" command will be just as effective -- 'dd' is unnecessary. "cat /dev/block/mmcblk0p18 >/sdcard/hboot-eng.img" will do the exact same thing.

    So... the 'dd' command *could* be used within such hacks as gfree to alter ONLY the PART of the partitions that need to be modified, rather than reading the full partition, making changes, and writing the whole thing back. Technically, this would be much more safe since it wouldn't involve wiping and rewriting the entire thing -- imagine something crashed right after the wipe and before you had the opportunity to write the new one. Use of 'dd' for this purpose would allow the majority of the partition to remain unaltered, and therefore STILL FUNCTIONAL, even if something bad happened.

    You seem to have a better grasp then I on DD.

    I am trying to reverse the process of reading what value is in a certain partition. I am using the dd commands below to write a hex value. I would also like to accomplish the opposite and read what the value is at that location. Is this possible?

    echo -ne '\x00\x00\x00\x00' | dd of =/dev/block/mmcblk0p3 bs=1 seek=33796 // This tells the HTC bootloader to Show Locked on Bootloader flag
    or
    echo -ne 'HTCU' | dd of =/dev/block/mmcblk0p3 bs=1 seek=33796 // This tells the HTC Bootloader to Show Unlocked on the Bootloader flag

    Based on what you have said about of=/ is out file. Which is confusing based on the command line above.

    However the command works and sets the HTC device's Bootloader flag to Null which reads as Unlocked.

    I am trying to programatically read that partition and report back to the user the state using C#. Can I use the DD command to accomplish this?