Backup of linux drives and partitions, using dd command example

The dd command is a very simple backup tool for Linux distributions. The "dd" utility simply copies standard input to standard output, reading in 512-byte blocks.
The dd command is a very simple backup tool for Linux distributions. The "dd" utility simply copies standard input to standard output, reading in 512-byte blocks. With the dd command, we can create backups of entire disks, disk drives, etc. The following article will help you learn some useful "dd" commands.

1: Create a backup of an existing partition

The following command backs up the entire partition /dev/sdb1 to the /opt/sdb1.img file.
# dd if=/dev/sdb1 of=/opt/sdb1.imgSample output

16064937+0 records in
16064937+0 records out
8225247744 bytes (8.2 GB) copied, 123.319 s, 66.7 MB/s

2: Restore the backup to another partition

The above /opt/sdb1.img backup file can be restored to other partitions (/dev/sdb2), we can restore it with the following command.
# dd if=/opt/sdb1.img of=/dev/sdb2Sample output

16064937+0 records in
16064937+0 records out
8225247744 bytes (8.2 GB) copied, 197.688 s, 41.6 MB/s 

Now, you can see that /dev/sdb2 is a clone of /dev/sdb1.

3: Create a copy with an existing partition

We can directly partition from an existing partition replica. The following command will create a copy of /dev/sdb1 to /dev/sdb2.
# dd if=/dev/sdb1 of=/dev/sdb2Sample output

16064937+0 records in
16064937+0 records out
8225247744 bytes (8.2 GB) copied, 221.431 s, 37.1 MB/s

4: Create a clone of an existing hard drive

The following command will copy the first 446 bytes which is the MBR from the first disk to the second disk. This will create the second disk to boot. .
# dd if=/dev/sda of=/dev/sdb bs=446 count=1

1+0 records in
1+0 records out
446 bytes (446 B) copied, 0.00174812 s, 255 kB/s 

Now make sure the partition in /dev/sdb matches the partition in /dev/sda. Once this is done, you can copy each partition using:
# dd if=/dev/sda1 of=/dev/sdb1
# dd if=/dev/sda2 of=/dev/sdb2

5: Backup and restore MBR image files

Create a backup of the MBR image file using the following command.
# dd if=/dev/sda of=/opt/backup-mbr-sda.img bs=512 count=1Sample output

1+0 records in
1+0 records out
512 bytes (512 B) copied, 0.0115243 s, 44.4 kB/s 

The next step is to restore the MBR to a different disk, use the command below to do this.
# dd if=/opt/backup-mbr-sda.img of=/dev/sdb bs=446 count=1

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325390093&siteId=291194637