You are not logged in.

#1 2013-10-29 12:14:59

aardwolf
Member
From: Belgium
Registered: 2005-07-23
Posts: 280

Copying the OS disk to another disk

Hello,

When copying the disk with the OS on it to another equally sized disk with:

dd if=/dev/sda of=/dev/sdc bs=4096 conv=notrunc,noerror

Then a problem is that, possibly, during the 3 hours that this copy takes (for 1TB at 100MB/s), the disk sda may change due to other activity you're doing during the copy. So you end up with sdc having some combination of older and newer things, or maybe even a file that is half changed because it changed exactly during the time it was being copied.

So I should do this at night instead while not using the computer. But, the question is: could Linux still do activity that alters the disk while not using the computer?

Would KDE do stuff? When instead booting to terminal and no graphical desktop, are there then still potential things that might change the disk? What's the most reliable way of making an identical copy of your OS disk?

Reason: I discovered the disk in my desktop PC on which Linux is installed is compatible with a NAS I got, while an empty unused disk I have that I was planning to put in the NAS is not compatible with the NAS due to disk manufacturers putting crappy firmware on the disk on purpose to make you have to buy different disks for desktop and NAS/RAID. So I want to move everything of my desktop PC to the new disk so that I can use the old one for the NAS.

Thanks.

Offline

#2 2013-10-29 12:29:51

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: Copying the OS disk to another disk

Offline

#3 2013-10-29 13:21:52

x33a
Forum Fellow
Registered: 2009-08-15
Posts: 4,586
Website

Re: Copying the OS disk to another disk

@ aardwolf, There is always a possibility of some data being modified, whether you are actively using the computer or not (for example cron scripts running). It is better if you do this from a live environment.

And, as karol said, rsync is the better tool for this job.

Last edited by x33a (2013-10-29 13:22:37)

Offline

#4 2013-10-29 14:13:22

aardwolf
Member
From: Belgium
Registered: 2005-07-23
Posts: 280

Re: Copying the OS disk to another disk

I have actually two disks in my desktop, sda and sdb, and I want to copy sda to sdc. sda and sdc have the exact same size, and I want sdc to get the exact same bytes, MBR, etc... So I think dd is quite alright in this situation, right?

I want to copy disks, not copy "/" which is a combination of two disks and possible other mounted stuff... hmm

Offline

#5 2013-10-29 14:19:34

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: Copying the OS disk to another disk

Boot a liveCD / liveUSB, don't do it when booting sda.

Offline

#6 2013-10-29 14:28:21

x33a
Forum Fellow
Registered: 2009-08-15
Posts: 4,586
Website

Re: Copying the OS disk to another disk

aardwolf wrote:

I have actually two disks in my desktop, sda and sdb, and I want to copy sda to sdc. sda and sdc have the exact same size, and I want sdc to get the exact same bytes, MBR, etc... So I think dd is quite alright in this situation, right?

I want to copy disks, not copy "/" which is a combination of two disks and possible other mounted stuff... hmm

Yeah, dd is fine in this situation.

Offline

#7 2013-10-29 15:38:46

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 18,760

Re: Copying the OS disk to another disk

I would summarize most of the advice here WRT dd as "Do not mount either the source or destination disks".  This may mean boot from a live environment, or from an installed system on another drive, such as /dev/sdb.

But, (ewaller gets out his soapbox)  BE VERY CAREFUL WHEN USING dd.  These forums are riddled with tales of woe in which data were copied to the wrong destination, obliterating the critical data that had lived in that location.   dd is a dangerous command.  I speak from experience.


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way

Online

#8 2013-10-29 17:49:36

aardwolf
Member
From: Belgium
Registered: 2005-07-23
Posts: 280

Re: Copying the OS disk to another disk

Ok, I guess I will physically disconnect sdb (which is irrelevant to me here and should of course not accidently be overwritten), boot with a live cd, and, before using dd, look with smartctl at the manufacturer name of both disks to ensure I'm using the correct one as input and the correct one as output.

I hope my arch live cd has smartctl on it...

Offline

#9 2013-10-29 17:54:06

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: Copying the OS disk to another disk

aardwolf wrote:

I hope my arch live cd has smartctl on it...

smartmontools should be included: https://projects.archlinux.org/archiso. … kages.both

Offline

#10 2013-10-30 13:17:44

kokoko3k
Member
Registered: 2008-11-14
Posts: 2,324

Re: Copying the OS disk to another disk

Can i ask why somebody suggested rsync for this task instead of a simple cp -ax?

-edit
I did it one month ago without issues, and online.
to copy (say) sda to sdc, i first partitioned and formatted sdc with a partition scheme similar to sda.
then i mounted sdc:
mount /dev/sdc1 /tmp/sdc1
mount /dev/sdc2 /tmp/sdc2
mount /dev/sdc3 /tmp/sdc3

then i cpied:
cp -axv /boot/* /tmp/sdc1/
cp -axv / /tmp/sdc3/
...and so on
All is working right now

The pros over dd are that you can (moderately) do this online and is of course safer.
The cons over dd are that you have to install the bootloader

But again, why rsync in this case?
There is even the "--update" switch on cp...

Last edited by kokoko3k (2013-10-30 13:25:47)


Help me to improve ssh-rdp !

Offline

#11 2013-10-30 13:28:34

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: Copying the OS disk to another disk

kokoko3k wrote:

Can i ask why use reync for this task instead of a simple cp -ax?

See note https://wiki.archlinux.org/index.php/Di … g#Using_cp
A bit OT, but can you verify the factual accuracy of 'As a cp alternative' section of https://wiki.archlinux.org/index.php/Tar ?

Offline

#12 2013-10-30 13:41:11

kokoko3k
Member
Registered: 2008-11-14
Posts: 2,324

Re: Copying the OS disk to another disk

So, (is cp vs rsync here, not cp vs dd) seems to be all about this statement?

Also, it has been reported that even with the -a flag, some extended attributes may not be copied.


Help me to improve ssh-rdp !

Offline

Board footer

Powered by FluxBB