Linux clone hard drive over network

Disk cloning in Linux using dd command

The dd command utility is a simple yet powerful and useful command available in Unix and Linux systems which is used to convert and copy files. Unix like systems treat all devices as files and these device files are located in the /dev directory in your system. So typically your hard disk drive is a file in the /dev directory with the prefix of hd or sd (depending on IDE or SCSI driver). This concept of device as files makes dd a perfect candidate for backup and restore of disk images or cloning some partitions or the entire disk.

This article shows you some examples of how to use the dd command to backup or clone drive partitions and entire drives.

You can use the fdisk command or check the /proc/partitions to view all the disk partitions in your system.

From the above output we can deduce that you have hard disks on your system and their device file names are sda and sdb. There are two partitions in sda which are sda1 and sda2 and we also know that sda1 is a boot partition.

How to clone a partition from one disk to another

The following are the steps to create a clone of a partition from one disk to another disk, lets say for example you want to clone sda1 partition to sdb1 . In this case sda is your source disk and sdb is the destination disk.

Step 1: Create a new partition in the destination disk if it does not already exist. You can use the fdisk command to create the new partition.

Step 2: Run the dd command.

  • conv=sync,noerror tells dd command to continue copying after read errors and fill input block with nulls in case partial records.
  • status=progress shows progress of the copy.
  • bs=64M set the block size to copy at a time. Adjust this value could improve the copying speed

How to clone an entire disk

To clone an entire disk, say for example sda to sdb , run:

When you clone a entire disk, the destination disk will get all the partitions that are on the source disk.

How to create a disk image

Before you create a disk image backup, make sure no partitions on that disk are mounted and run the following command

where sdb is the disk file name and /path/to/backup.img is the path and filename of the backup image.

Compressed disk image

You could also compress the backup image with gzip as shown in the example below

Send disk image to remote system

You could send the backup image to a remote machine using ssh as in the below example.

Split the disk image by size

You can split the disk image in to smaller pieces of any size that you specify by passing the dd output through split command.

Читайте также:  Mac os удаление файла горячие клавиши

The above command splits the backup image file to smaller files of size 50MB or less. A two letter suffix will be added to the files. The resulting files will have names backup.img.gz.aa, backup.img.gz.ab, backup.img.gz.ac.

To join the split files into a single image file, you run the command

Restoring disk image

The below command restores the disk sdb from the image file backup.img .

To restore from a compressed backup image, use the gunzip command with dd

To restore from a backup image that is compressed and split, run:

Источник

Disk cloning

Disk cloning is the process of making an image of a partition or of an entire hard drive. This can be useful for copying the drive to other computers or for backup and recovery purposes.

Contents

Using dd

Using ddrescue

ddrescue is a tool designed for cloning and recovering data. It copies data from one file or block device (hard disc, cdrom, etc) to another, trying to rescue the good parts first in case of read errors, to maximize the recovered data.

To clone a faulty or dying drive, run ddrescue twice. For the first round, copy every block without read error and map the errors to rescue.map .

where X is the partition letter of the source and Y of the target block device.

For the second round, copy only the bad blocks and try 3 times to read from the source before giving up.

Now you can check the file system for corruption and mount the new drive.

File system cloning

This article or section needs expansion.

Using e2image

e2image is a tool included in e2fsprogs for debugging purposes. It can be used to copy ext2, ext3, and ext4 partitions efficiently by only copying the used blocks. Note that this only works for ext2, ext3, and ext4 filesystems, and the unused blocks are not copied so this may not be a useful tool if one is hoping to recover deleted files.

To clone a partition from physical disk /dev/sda , partition 1, to physical disk /dev/sdb , partition 1 with e2image, run

Disk cloning software

These applications allow easy backup of entire filesystems and recovery in case of failure, usually in the form of a Live CD or USB drive. They contain complete system images from one or more specific points in time and are frequently used to record known good configurations. See Wikipedia:Comparison of disk cloning software for their comparison.

See also Synchronization and backup programs for other applications that can take full system snapshots, among other functionality.

Источник

Linhost.info

Clone a Hard Drive over the Network with DD

In more than one occasion I’ve been asked to copy or backup an entire drive from one remote system to a second remote remote system, my preferred method for accomplishing this task is by making use of three different tools available in UNIX-like operating systems. Thanks to DD, Gzip, and OpenSSH I am able to make an exact copy of a drive, compress the resulting drive image while sending the resulting data to another remote system. The case for making use of this method is for when you either lack the local space to store the image or want to keep a backup in a remote system. It doesn’t hurt to backup valuable data, accidents happen. Also, it would be wise to compress the resulting image, I rather have the system spend the extra effort compressing the image using Gzip than to thave the uncompressed image taking more space than it should. What is great about this combination is that you can backup and restore the image using the same tools.

Remember to un-mount the drive you wish to clone. Not doing so may result in possible data corruption.

Locate The Drive You Wish To Backup

You can use the lshw (Hardware Lister) command to discover all available drives.

Читайте также:  Не работает ассоциация файлов windows 10

[root@system7]# lshw -C disk

*-cdrom
description: DVD-RAM writer
product: CDDVDW SH-S203N
vendor: TSSTcorp
physical id: 0.0.0
bus info: scsi@1:0.0.0
logical name: /dev/cdrom
logical name: /dev/dvd
logical name: /dev/scd0
logical name: /dev/sr0
version: SB01
serial: NECVMWarVMware IDE CDR101.00
capabilities: removable audio cd-r cd-rw dvd dvd-r dvd-ram
configuration: ansiversion=5 status=nodisc
*-disk
description: SCSI Disk
physical id: 0.0.0
bus info: scsi@2:0.0.0
logical name: /dev/sda
size: 50GiB (53GB)
capabilities: partitioned partitioned:dos
configuration: signature=000e4a4e

Backup To Remote Server

This command will copy, compress and send the image to the remote server.

dd if=/dev/sdb | gzip -c –fast | ssh user@ip ‘dd of=/home/user/sdb.img.gz’

Explanation: DD has been instructed to copy the drive /dev/sdb. Gzip will be used for compression, — c means Write on standard output, keep original files unchanged, — -fast mean Compress faster at the expense of high compression ration. The image will then be transferred via OpenSSH using the provided user credentials to the user directory /home/user. Note: the backup image makes use of the .gz extension to indicate compression is being used.

Restore From Remote Server

Restoring the image is not that different from the command used to backup the image.

ssh user@ip ‘dd if=/home/user/sdb.img.gz’ | gunzip -1 — | dd of=/dev/sdb

Explanation: Using OpenSSH log in to the remote system where the image is stored and with DD pull the image. Gunzip will be used to decompress the image crated by Gzip. Once again DD will be in charged of writing the image to /dev/sdb.

Keep In Mind

Remember that using OpenSSH or any other encrypted protocol for the transfer will slow down the progress and specifically impact CPU load during the cloning. But, because I am moving data across the Internet the security provided by OpenSSH is worth it. In a not so scientific test done between a white box server(sender) and a HP Quad Core server(receiver) it took 40.6 minutes to compress 80GB of data in to a 21GB image and transfer the result at a rate of 8.4MB/s(over a Gigabit network). The white box server uses an Intel E3200 CPU which during the test stayed at around 87% utilization, a faster CPU should provide better throughput.

Источник

How to Clone a Partition or Hard drive in Linux

There are many reasons why you may want to clone a Linux partition or even hard drive, most of which are related to creating backups of your data. There are multiple ways you can achieve this in Linux by using some external tools such as partimage or Clonezilla.

However in this tutorial we are going to review Linux disk cloning with tool called dd, which is most commonly used to convert or copy files and it comes pre-installed in most Linux distributions.

How to Clone Linux Partition

With dd command you can copy entire hard drive or just a Linux partition. Lets start with cloning one of our partitions. In my case I have the following drives: /dev/sdb, /dev/sdc.. I will clone /dev/sdb1/ to /dev/sdc1.

First list the these partitions using the fdisk command as shown.

List Linux Partitions

Now clone a partition /dev/sdb1/ to /dev/sdc1 using the following dd command.

The above command tells dd to use /dev/sdb1 as input file and write it to output file /dev/sdc1.

Clone Linux Partition with dd Command

After cloning Linux partition, you can then check both partitions with:

Verify Linux Partition Cloning

How to Clone Linux Hard Drive

Cloning a Linux hard drive is similar to cloning a partition. However, instead of specifying the partition, you just use the entire drive. Note that in this case it is recommended that the hard drive is same in size (or bigger) than the source drive.

Читайте также:  Обновить grub kali linux

Clone Hard Drive in Linux

This should have copied the drive /dev/sdb with its partitions on the target hard drive /dev/sdc. You can verify the changes by listing both drives with fdisk command.

Verify Linux Hard Drive Cloning

How to Backup MBR in Linux

dd command can also be used to backup your MBR, which is located at the first sector of the device, before the first partition. So if you want to create backup of your MBR, simply run:

The above command tells dd to copy /dev/sda to /backup/mbr.img with step of 512 bytes and the count option tells to copy only 1 block. In other words you tell dd to copy the first 512 bytes from /dev/sda to the file you have provided.

Backup MBR in Linux

That’s all! dd command is a powerful Linux tool that should be used with caution when copying or cloning Linux partitions or drives.

If You Appreciate What We Do Here On TecMint, You Should Consider:

TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

We are thankful for your never ending support.

Источник

How to Clone Linux disk partition over network using dd

In this tutorial, we will show you how to clone Linux harddisk partition over a network, in this tutorial we will use dd command. For the guys who don’t know what dd is – it is a command-line utility for Unix and Unix-like operating systems whose primary purpose is to convert and copy files.

Clone Linux harddisk has advantages because we don’t need to reinstall and configure again the applications especially in Linux that we used as a server.

Prerequisites

This article assumes you have at least basic knowledge of Linux, know how to use the shell, root user or non-root user account with sudo privileges set up on your server.

For other prerequisites :

  • Linux with network interface.
  • Make sure 2 linux have same storage size.
  • Both 2 linux has been booted using rescue OS or other live OS , so you not boot using installed OS in the disk.

We will use description for our example:

Source

Destination

1. Clone disk partition using dd over SSH

To clone entire Linux disk partition using dd over ssh from server-A to server-B. Let’s assume you use root user.

Run this command in server A (source):

If you want to clone some partition only, just choose the partition you want to clone like these command below, for example, we will clone /dev/sda3 partition

Run this command in server A (source):

2. Clone disk partition using dd over telnet with bzip compression

Clone using telnet and bzip has advantages to reduce clone time, but make sure you use a secure network.

Lets assume server-B has ip address 192.168.100.2. Run this command in server B (destination):

Run this command in server A (source):

Based on these 2 commands above we will connect to server-B using port 19000.

Conclusion

You can choose 2 kinds of the method above, clone disk partition over a network is useful when you need to migration from different datacenter with same disk storage space.

Источник

Оцените статью