LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 04-14-2021, 01:06 PM   #1
mcv110
LQ Newbie
 
Registered: Mar 2021
Posts: 16

Rep: Reputation: Disabled
Using dd utility to clone a server


I have two (old) identical servers running RHEL5. One has failed and I have decided to clone the other to restore the failed box.

I ran dd with this command on the healthy server from a live CD:
Code:
sudo dd if=/dev/sda of=/dev/sdb1
the process ran without issue and reported that the amount of data I would have expected was successfully copied to the external HDD. I can view the contents of the drive from file manager, doesn't look like anything useful to me, but there is data.

When I move that HDD to the failed machine and want to copy it back (running live CD) that server does not even see the drive.

Did I miss something in the dd process? I have never done this before. Thanks for any input.
 
Old 04-14-2021, 01:17 PM   #2
lvm_
Member
 
Registered: Jul 2020
Posts: 912

Rep: Reputation: 314Reputation: 314Reputation: 314Reputation: 314
You copied disk to a partition, should be "...of=/dev/sdb" (assuming the target disk is the same or larger).
 
Old 04-14-2021, 02:05 PM   #3
mcv110
LQ Newbie
 
Registered: Mar 2021
Posts: 16

Original Poster
Rep: Reputation: Disabled
ah man. ok so adding that 1 made it a partition? rather than a dd data file?

As I understood the sdb1 was the mount point of the drive, and should have been the target? but the 1 should not be apart of the of= target?
 
Old 04-14-2021, 03:09 PM   #4
jefro
Moderator
 
Registered: Mar 2008
Posts: 21,974

Rep: Reputation: 3623Reputation: 3623Reputation: 3623Reputation: 3623Reputation: 3623Reputation: 3623Reputation: 3623Reputation: 3623Reputation: 3623Reputation: 3623Reputation: 3623
sda is an entire drive. When you dd it you dd some areas like bootloader and maybe other places. It is a copy of the readable area of the entire disk.

While you can copy it to a second drive (sdb) and further copy it to a partition on that second drive it ends up being putting the wrong data in the wrong place.

If you do really want to make an exact copy of sda it makes me further wonder one important thing. You don't want to clone a booted drive. You usually clone a disk by booting to some live media. Then the drives need to be correctly identified as to source and destination. sda may not be source.

Booting to clonezilla may work and should be more safe.
 
Old 04-14-2021, 03:51 PM   #5
Emerson
LQ Sage
 
Registered: Nov 2004
Location: Saint Amant, Acadiana
Distribution: Gentoo ~amd64
Posts: 7,661

Rep: Reputation: Disabled
Quote:
Originally Posted by mcv110 View Post
ah man. ok so adding that 1 made it a partition? rather than a dd data file?

As I understood the sdb1 was the mount point of the drive, and should have been the target? but the 1 should not be apart of the of= target?
Code:
sudo dd if=/dev/sda of=/dev/sdb1
Even without knowing anything about whole thing this should raise a red flag as not logical. You want to clone, then you do it sda1 to sdb1 (partition to partition) or sda to sdb (drive to drive), otherwise it can't be a clone.
 
Old 04-14-2021, 04:21 PM   #6
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,642
Blog Entries: 4

Rep: Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933
Are the disk drives "identical?"
 
Old 04-14-2021, 06:26 PM   #7
computersavvy
Senior Member
 
Registered: Aug 2016
Posts: 3,342

Rep: Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484
The disk drives do not have to be "identical".
The destination must be equal or larger in size as the partitions sizes can be adjusted after the fact to fit the physical space.

To the OP.
It seems you wanted to make a disk image that then could be copied back to the drive in the second system.

My suggestion is that you have two choices.
1) Do a direct disk to disk copy by connecting both drives in the same machine and doing the copy with "dd if=/dev/sda of=/dev/sdb bs=64M " as it seemed you intended to do with the command you used.
2) The alternative, which will take at least twice the time, would be to use dd to create an image file of the source disk then write back from the image to the destination disk.
Creating the image involves having a drive mounted with adequate disk space to contain the image, then creating the image with dd using a command like
Code:
 dd if=/dev/sda of=/mountpoint/image.img bs=64M
then writing the image file to the destination disk with
Code:
 dd if=/mountpoint/image.img of=/dev/sdb bs=64M
Note that I added a bs (block size) part to the command. The default block size for dd is 512 bytes and adding the part as I did means it takes 128000 reads at default size to equal one read with the bs=64M option added to the command. A major saving in time for reading and writing the disk image.
 
Old 04-14-2021, 06:38 PM   #8
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,120

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
Quote:
Originally Posted by Emerson View Post
[CODE]Even without knowing anything about whole thing this should raise a red flag as not logical. You want to clone, then you do it sda1 to sdb1 (partition to partition) or sda to sdb (drive to drive), otherwise it can't be a clone.
Not at all - data is just data. The OP states it is merely temporary usage to allow the target disk to be moved over and the image copies off. Most might use an output file, but it's certainly not required.
The issue is:
Quote:
When I move that HDD to the failed machine and want to copy it back (running live CD) that server does not even see the drive.
What does this mean - it doesn't mount or it doesn't appear as a device node under /dev ?. Let's see relevant lines of dmesg on the target machine.
 
Old 04-15-2021, 05:23 PM   #9
mcv110
LQ Newbie
 
Registered: Mar 2021
Posts: 16

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by computersavvy View Post
The disk drives do not have to be "identical".
The destination must be equal or larger in size as the partitions sizes can be adjusted after the fact to fit the physical space.

To the OP.
It seems you wanted to make a disk image that then could be copied back to the drive in the second system.

My suggestion is that you have two choices.
1) Do a direct disk to disk copy by connecting both drives in the same machine and doing the copy with "dd if=/dev/sda of=/dev/sdb bs=64M " as it seemed you intended to do with the command you used.
2) The alternative, which will take at least twice the time, would be to use dd to create an image file of the source disk then write back from the image to the destination disk.
Creating the image involves having a drive mounted with adequate disk space to contain the image, then creating the image with dd using a command like
Code:
 dd if=/dev/sda of=/mountpoint/image.img bs=64M
then writing the image file to the destination disk with
Code:
 dd if=/mountpoint/image.img of=/dev/sdb bs=64M
Note that I added a bs (block size) part to the command. The default block size for dd is 512 bytes and adding the part as I did means it takes 128000 reads at default size to equal one read with the bs=64M option added to the command. A major saving in time for reading and writing the disk image.
This was the process I was going for. I will retry adding the .img
 
Old 04-15-2021, 05:32 PM   #10
mcv110
LQ Newbie
 
Registered: Mar 2021
Posts: 16

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by syg00 View Post
Not at all - data is just data. The OP states it is merely temporary usage to allow the target disk to be moved over and the image copies off. Most might use an output file, but it's certainly not required.
The issue is:What does this mean - it doesn't mount or it doesn't appear as a device node under /dev ?. Let's see relevant lines of dmesg on the target machine.
hmmm. I am not sure what to look for in dmesg. I did a dmesg | grep sda and got the following:

Code:
[7.817364] sd 9:2:0:0: [sda] 14082048 512-byte logical blocks: (72.7 GB/67.8GiB)
[7.817396] sd 9:2:0:0: [sda] Write Protect if off
[7.817398] sd 9:2:0:0: Mode Sense: 1f 00 10 08
[7.817841] sd 9:2:0:0: Write cache: disabled, read cache: enabled, supports DPO and FUA
[7.838260] sda: sda1 sda2 sda3 sda4 sda5 sda6 sda7 >
[7.839036] sd 9:2:0:0: [sd 9:2:0:0:] Attached SCSI disk
I would expect sda1,2,5,6,7 based on the partitions of the other system. but I dont know about 3 and 4. I do not see the drive when I do a df -h, and from the graphical interface the device is not present in "Other Locations" of the file manager, as the other system is.

would I expect the drive to look like sdb1 in /dev?

Last edited by mcv110; 04-15-2021 at 05:33 PM.
 
Old 04-15-2021, 06:13 PM   #11
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,120

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
From the liveCD on the target let's see
Code:
lsblk -f
 
1 members found this post helpful.
Old 04-15-2021, 06:31 PM   #12
mcv110
LQ Newbie
 
Registered: Mar 2021
Posts: 16

Original Poster
Rep: Reputation: Disabled
I cant copy text from the source, so I have attached a screen snip.
Attached Thumbnails
Click image for larger version

Name:	lsbkl -f.jpg
Views:	16
Size:	50.5 KB
ID:	36124  
 
Old 04-15-2021, 08:00 PM   #13
computersavvy
Senior Member
 
Registered: Aug 2016
Posts: 3,342

Rep: Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484
Quote:
Originally Posted by mcv110 View Post
hmmm. I am not sure what to look for in dmesg. I did a dmesg | grep sda and got the following:

Code:
[7.817364] sd 9:2:0:0: [sda] 14082048 512-byte logical blocks: (72.7 GB/67.8GiB)
[7.817396] sd 9:2:0:0: [sda] Write Protect if off
[7.817398] sd 9:2:0:0: Mode Sense: 1f 00 10 08
[7.817841] sd 9:2:0:0: Write cache: disabled, read cache: enabled, supports DPO and FUA
[7.838260] sda: sda1 sda2 sda3 sda4 sda5 sda6 sda7 >
[7.839036] sd 9:2:0:0: [sd 9:2:0:0:] Attached SCSI disk
I would expect sda1,2,5,6,7 based on the partitions of the other system. but I dont know about 3 and 4. I do not see the drive when I do a df -h, and from the graphical interface the device is not present in "Other Locations" of the file manager, as the other system is.

would I expect the drive to look like sdb1 in /dev?
If none of the drive partitions are attached to the file system (mounted) then the file system utilities like df and the file manager will not be able to see them.

You could use the command "mount" to see what is actually mounted and active.
You can use "sudo fdisk -l" to list all disks the computer has configured and their details, including sizes and partitions defined as well as the type of filesystems on the partitions.

In my earlier post I noted the "of=/mountpoint/image.img".
This is actually a file to be created at some location in the file system you choose, not a literal "/mountpoint/". You will need to select where to create that actual image file and it will have to be in a part of the existing file system, not a device (unless you are doing a disk to disk copy)

Last edited by computersavvy; 04-15-2021 at 08:07 PM.
 
Old 04-15-2021, 08:26 PM   #14
computersavvy
Senior Member
 
Registered: Aug 2016
Posts: 3,342

Rep: Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484
Looking at the image you posted, the live USB you booted from appears to be /dev/sdc.
/dev/sda appears to be a fully configured drive, with sda4 being the extended partitions and sda5-7 appear to be extended partitions. /dev/sdb has one partition but no details are given. "sudo fdisk -l" will give more info than "lsblk" (and in a different way).

I am guessing that sda may be the drive you are copying from and sdb may be the drive you are wanting to copy to. If this is the case then the command you used earlier was (almost) correct.
"dd if=/dev/sda of=/dev/sdb bs=64M" would be a good way to do the actual disk to disk copy.

If you want to do the copy disk to image then when running the live image you will need to attach another disk that you can mount and actually copy a disk image to. The live image you are booted to only has the amount of memory in the system that you can write to, and that certainly will not be enough for a full disk image to be stored.
 
Old 04-15-2021, 10:37 PM   #15
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,120

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
I beg to differ.
If that thumbnail was from the target, then the disk has been recognised, but /dev/sdb1 can't be mounted as it's the dd'd image. Given statements in the first post, this will restore that image onto the target - simply reversing the initial command.
Code:
sudo dd of=/dev/sda if=/dev/sdb1
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Clone and boot from clone geelsu Linux - Server 5 12-17-2018 12:03 PM
LXer: Open-spec SBC is a clone of a clone of a clone of a Raspberry Pi 3 LXer Syndicated Linux News 0 04-25-2018 04:56 PM
Linux 64 bit fresh install, created clone on cd, want to use clone on another laptop... apollo1980 Linux - Software 12 10-12-2017 02:59 PM
I need to Clone a Red Hat drive and install clone in HP server drummer54 Linux - Newbie 14 03-07-2009 04:15 PM
bugzilla: to clone, or not to clone? The00Dustin Linux - Newbie 1 05-24-2008 05:19 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 06:06 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration