The dd command in Linux, How to use the dd command

On Unix, the device driver for hardware (such as hard drive) and special device files (such as / dev / zero and / dev / random ) appear in the file system just like normal files.

The dd command in Linux, How to use the dd command Picture 1

dd can also read and / or write from / to these files, provided that functionality is implemented in their respective drivers.

Hence, dd can be used for tasks such as backing up the hard drive's boot sector and fetching fixed amounts of random data.

The dd program can also perform conversions on data as it is copied, including byte-order swapping and conversion to and from ASCII and EBCDIC text encodings.

How to use the dd command

Dd's command line syntax differs from many other Unix programs in that it uses the option = value syntax for its command line options, instead of the more standard -option value or -option = value formats . By default, dd reads from stdin and writes to stdout , but they can be altered using the if (input file) and of (output file) options.

The dd command in Linux, How to use the dd command Picture 2

Some practical examples of dd command

Backup entire hard drive

To back up an entire copy of one hard drive to another hard drive connected to the same system, execute the dd command as shown. In this dd command example, the UNIX device name of the source hard drive is / dev / hda and the device name of the target hard drive is / dev / hdb.

# dd if = /dev/sda of = /dev/sdb

'If' represents the input file and 'of' represents the output file. So an exact copy of / dev / sda should be in / dev / sdb.

If there are any errors, the above command will fail. If you supply the parameter 'convert = noerror' then the parameter will continue to copy if there is a read error.

The input file and the output file should be mentioned very carefully. You mention the source device in the target and vice versa, you could lose all of your data.

To clone hard drive to hard drive using the dd command given below, sync option allows you to clone everything using the synchronized I / O.

# dd if = /dev/sda of = /dev/sdb conv=noerror, sync

Partition backup

You can use the device name of the partition in input file and in output, you can specify your destination path or image file as shown in dd command.

# dd if=/dev/hda1 of=~/partition.img

Create an image of the hard drive

Instead of making a backup of your hard drive, you can create an image file of your hard drive and store it in other storage devices. There are many advantages of backing up data to a disk image, one of which is its ease of use. This method is usually faster than other backup types, allowing you to quickly restore data after an unexpected crash. It creates an image of the / dev / hda hard drive .

# dd if = /dev/hda of = ~/hdadisk.img

Recover hard drive image

To restore the hard drive with the image file of another hard drive, you can use the following dd command:

# dd if = hdadisk.img of = /dev/hdb

The hdadisk.img image file is the image of / dev / hda, so the above command will restore the image of / dev / hda to / dev / hdb.

Create CDROM Backup

The dd command allows you to create an ISO file from a source file. So the user can insert the CD and enter the dd command to create ISO file for the CD content.

# dd if = /dev/cdrom of = tgsservice.iso bs = 2048

The dd command reads an input block and processes it, then writes it to an output file. You can specify the block size for the input and output files. In the dd command example above, the 'bs' parameter specifies the block size for both the input and output files. So dd uses 2048 bytes as the block size in the above command.

5 ★ | 1 Vote

May be interested

  • How to install µTorrent (uTorrent) in Ubuntu 20.04Photo of How to install µTorrent (uTorrent) in Ubuntu 20.04
    µtorrent provides clients for windows and macos x, however it is installed as a server in ubuntu linux and provides a web ui for managing downloads.
  • How to disable automatic workspace in GNOMEPhoto of How to disable automatic workspace in GNOME
    with distributions rolling out releases using the latest version of gnome 3, more and more users are returning to gnome and finding that it has been greatly improved, since the gnome project played. onions for the first time.
  • How to upgrade from Linux Mint 19.3 to Linux Mint 20Photo of How to upgrade from Linux Mint 19.3 to Linux Mint 20
    upgrading can be problematic, from errors to lost files or having to reconfigure settings. luckily, the mint development team provides a handy tool for upgrading without the need to completely reinstall the operating system.
  • How to create new files in LinuxPhoto of How to create new files in Linux
    there are a number of different linux applications and commands that will create new files for you, even without launching the application. the method you use will depend on your purpose for the file. let's take a look at the options so you can see which one is most useful for you!
  • Top 10 examples of Netstat commands on LinuxPhoto of Top 10 examples of Netstat commands on Linux
    netstat is a command line utility that can be used to list all network connections (sockets), allowing comparison with network connections, routing tables, interface records, connection spoofing.
  • How to create Cron Jobs in Linux with ZeitPhoto of How to create Cron Jobs in Linux with Zeit
    the sole goal of zeit is to make adding and managing cron jobs easy. with zeit, running commands and scripts is as simple as adding a new item to the task list.