0% found this document useful (0 votes)
51 views3 pages

Clonar Linux DD Command

This document provides 6 examples of using the dd command in Linux to backup disks and partitions. It describes backing up an entire hard disk, creating a disk image, restoring from an image, creating a floppy image, backing up a partition, and backing up a CDROM to an ISO file. The dd command can be used to directly copy data or create disk/file images for backup purposes.

Uploaded by

pepet1000
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views3 pages

Clonar Linux DD Command

This document provides 6 examples of using the dd command in Linux to backup disks and partitions. It describes backing up an entire hard disk, creating a disk image, restoring from an image, creating a floppy image, backing up a partition, and backing up a CDROM to an ISO file. The dd command can be used to directly copy data or create disk/file images for backup purposes.

Uploaded by

pepet1000
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

6 Examples to Backup Linux Using dd Command (Including Disk to

Disk)
Data loss will be costly. At the very least, critical data loss will have a financial impact
on companies of all sizes. In some cases, it can cost your job. Ive seen cases where
sysadmins learned this in the hard way.
There are several ways to backup a Linux system, including rsync and rsnapshot that we
discussed a while back.
This article provides 6 practical examples on using dd command to backup the Linux
system. dd is a powerful UNIX utility, which is used by the Linux kernel makefiles to
make boot images. It can also be used to copy data. Only superuser can execute dd
command.
Warning: While using dd command, if you are not careful, and if you dont know what
you are doing, you will lose your data!

Example 1. Backup Entire Harddisk


To backup an entire copy of a hard disk to another hard disk connected to the same
system, execute the dd command as shown below. In this dd command example, the
UNIX device name of the source hard disk is /dev/hda, and device name of the target
hard disk is /dev/hdb.
# dd if=/dev/sda of=/dev/sdb

if represents inputfile, and of represents output file. So the exact copy of /dev/sda
will be available in /dev/sdb.
If there are any errors, the above command will fail. If you give the parameter
conv=noerror then it will continue to copy if there are read errors.
Input file and output file should be mentioned very carefully, if you mention source
device in the target and vice versa, you might loss all your data.

In the copy of hard drive to hard drive using dd command given below, sync option
allows you to copy everything using synchronized I/O.
# dd if=/dev/sda of=/dev/sdb conv=noerror,sync

Example 2. Create an Image of a Hard Disk


Instead of taking a backup of the hard disk, you can create an image file of the hard disk
and save it in other storage devices.There are many advantages to backing up your data
to a disk image, one being the ease of use. This method is typically faster than other
types of backups, enabling you to quickly restore data following an unexpected
catastrophe.
# dd if=/dev/hda of=~/hdadisk.img

The above creates the image of a harddisk /dev/hda. Refer our earlier article How to
view initrd.image for more details.

Example 3. Restore using Hard Disk Image


To restore a hard disk with the image file of an another hard disk, use the following dd
command example.
# dd if=hdadisk.img of=/dev/hdb

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

Example 4. Creating a Floppy Image


Using dd command, you can create a copy of the floppy image very quickly. In input
file, give the floppy device location, and in the output file, give the name of your floppy
image file as shown below.
# dd if=/dev/fd0 of=myfloppy.img

Example 5. Backup a Partition


You can use the device name of a partition in the input file, and in the output either you
can specify your target path or image file as shown in the dd command example below.
# dd if=/dev/hda1 of=~/partition1.img

Example 6. CDROM Backup


dd command allows you to create an iso file from a source file. So we can insert the CD
and enter dd command to create an iso file of a CD content.
# dd if=/dev/cdrom of=tgsservice.iso bs=2048

dd command reads one block of input and process it and writes it into an output file.
You can specify the block size for input and output file. In the above dd command
example, the parameter bs specifies the block size for the both the input and output
file. So dd uses 2048bytes as a block size in the above command.
Note: If CD is auto mounted, before creating an iso image using dd command, its
always good if you unmount the CD device to avoid any unnecessary access to the CD
ROM.

"Barra de progreso" en la ejecucin de dd


7/21/2012 linux, trucos Se el primero en comentar!

Muchas veces cuando estamos ejecutando un proceso con el comando dd, una de las cosas
que ms echamos en falta, o yo por lo menos lo hago, es saber en qu punto est y cuanto
le falta. Esto tpicamente se conoce como una barra de progreso. Pues bien, os voy a
ensear un truco que permitir saber el progreso de la ejecucin de dd, aunque no en
forma de barra, pero s lo podra simular. Para saberlo, haremos uso del comando kill. S,
kill se encarga de mandar seales y no slo de matar procesos, aunque efectivamente
algunas de las seales tambin matan los procesos.
Pues bien, vamos a ver a continuacin cmo lograr saber el estado del comando durante
el tiempo. Para ello partimos de una ejecucin de dd, tal como esta, por ejemplo.
shell> dd if=/dev/zero of=file.img bs=1024 count=1048576

Con ello crearemos un fichero de 1,1Gb vaco. Mientras se est ejecutando en otra consola
averiguamos el pid del proceso, ya que tenemos que saber a quin le hay que mandar la
seal.
shell> ps aux |grep dd
javier

17829 ...

dd if=/dev/zero of=file.dd bs=1024 count=1048576

javier

17831 ...

grep --color=auto dd

Aqu observamos que el pid del proceso dd es 17829, pues ahora le mandamos una seal
de tipo USR1 para que nos informe del estado del proceso.
shell> kill -USR1 17829

Y cada vez que ejecutemos el kill con dicha sea, lo que nos aparecer ser la informacin
de esta, similar a sta,
739705+0 records in
739705+0 records out
757457920 bytes (757 MB) copied, 11,3332 s, 66,8 MB/s

You might also like