You are not logged in.

#1 2014-02-06 20:53:47

Lawless Flogic
Member
Registered: 2013-11-26
Posts: 11

cloning an entire hard drive? (including the partitions)

I have a dual boot setup with many partitions (arch, osx, and a shared partition with a shared home directory). this is very convient because i can work in linux or osx and then if i need a tool that one system doenst have I can just reboot and continue working with the same files. the only issue is that it is rather complicated and time consuming to set up, and I'm worried about having to do it again if (when) something gets mucked up.

so is there a way to back up an enitire disk? I'm talking about 1 hard disk with 6 partitions where some are formatted ext and some are formatted hfs. It seems like this would be possible but my googling has not returned anything terribly useful so far.

does anybody else use a setup like this? any help would be appreciated!

Offline

#2 2014-02-06 20:56:03

nagaseiori
Member
Registered: 2012-09-22
Posts: 72

Re: cloning an entire hard drive? (including the partitions)

dd if=/dev/sdX of=/dev/sdY

?

Offline

#3 2014-02-06 21:00:36

Slithery
Administrator
From: Norfolk, UK
Registered: 2013-12-01
Posts: 5,776

Re: cloning an entire hard drive? (including the partitions)

You could always use dd.

Clonezilla will probably work as well, you'll have to check that it fully supports HFS though.


No, it didn't "fix" anything. It just shifted the brokeness one space to the right. - jasonwryan
Closing -- for deletion; Banning -- for muppetry. - jasonwryan

aur - dotfiles

Offline

#4 2014-02-06 21:08:43

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,424
Website

Re: cloning an entire hard drive? (including the partitions)

Not a Sysadmin issue, moving to NC...


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#5 2014-02-06 21:50:13

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 19,804

Re: cloning an entire hard drive? (including the partitions)

dd would be my choice.  But [ewaller drags out his soapbox], be extremely careful when you enter the command.  Then stop, put your hands in your lap, and read the command you typed.  Then read it again.  Verify the source and destination, contemplate why those with experience have dubbed dd to mean "Data Destroyer", read that command again, throw caution to the wind, and press enter.  Pray you got it right.[/soapbox mode]

Last edited by ewaller (2014-02-06 21:50:46)


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

Offline

#6 2014-02-06 22:19:20

drcouzelis
Member
From: Connecticut, USA
Registered: 2009-11-09
Posts: 4,092
Website

Re: cloning an entire hard drive? (including the partitions)

I do just that! I have four operating systems installed and make backups using "dd". You can read about my backup strategy on my blog here: http://archlinux.me/drcouzelis/2012/04/17/backups/

Offline

#7 2014-02-06 23:03:29

alphaniner
Member
From: Ancapistan
Registered: 2010-07-12
Posts: 2,810

Re: cloning an entire hard drive? (including the partitions)

Using dd to clone/backup seems awfully inefficent in most cases. If I wanted to duplicate a drive, I'd use dd to clone the beginning of the drive (0 to sector before first partition), then format the partitions and copy the data over.

Of course, that's for linux filesystems. To clone other filesystems, dd is often the safest choice. In the past I used ntfsclone and fsarchiver for Windows partitions, but that was for creating image files rather than cloning. If you want to go that route, partimage and partclone which seem to have some support for HFS.


But whether the Constitution really be one thing, or another, this much is certain - that it has either authorized such a government as we have had, or has been powerless to prevent it. In either case, it is unfit to exist.
-Lysander Spooner

Offline

#8 2014-02-07 00:07:15

Lawless Flogic
Member
Registered: 2013-11-26
Posts: 11

Re: cloning an entire hard drive? (including the partitions)

Ok thanks for all the feedback! sorry if this is dead simple, but when I asked a knowlegable person that I know he said he didnt know of anything offhand to do this. but you guys say i can do this with dd? just to clarify, dd will copy all of the partitions, so when i run it on /dev/sda it will copy /dev/sda1, sda2, etc? and they will remain formatted the same?

Offline

#9 2014-02-07 00:07:32

thiagowfx
Member
Registered: 2013-07-09
Posts: 586

Re: cloning an entire hard drive? (including the partitions)

But does dd only copy the used space?

Usually I use clonezilla too, it is perfect to backup. But I have to confess I've never got any success when I needed that backup, I'd always get a different error.

Never tried it, but there is ddrescue also. It looks better than dd for backups.

Offline

#10 2014-02-07 00:22:01

frostschutz
Member
Registered: 2013-11-15
Posts: 1,421

Re: cloning an entire hard drive? (including the partitions)

dd copies everything. the copy dd creates is the same size as the source. the downside of dd is that you can't use it while the filesystems are mounted, as the copy would be inconsistent.

Every few days I make a copy of my SSD by using md. The SSD is actually set up as a RAID 1 with 1 disk. When I want to make a copy (while things are mounted and running), I add another disk (a HDD backed logical volume) to the RAID. That mirrors stuff in the background and once the sync is done, I kick it out of the RAID again. That way you have an image like you would with dd but it's consistent because any changes that were made to filesystems during the sync process were instantly synced too by the raid layer.

script to go with that  (/dev/md0 being the SSD, /dev/HDD/ is a HDD backed volume group, /dev/HDD/SSD the Logical Volume for the SSD mirror)

#!/bin/bash

mdadm --grow /dev/md0 --raid-devices=2 --force
mdadm --zero-superblock /dev/HDD/SSD
mdadm --manage /dev/md0 --add --write-mostly /dev/HDD/SSD
mdadm --wait /dev/md0
sync
mdadm /dev/md0 --fail /dev/HDD/SSD
mdadm /dev/md0 --remove /dev/HDD/SSD
mdadm --grow /dev/md0 --raid-devices=1 --force

Of course this is just a quick way to get back on your feet; for a real backup (incremental, keeps around older copies of files, etc.) you should still do rsync/tar/dar/whatever to a backup disk...

Last edited by frostschutz (2014-02-07 00:25:34)

Offline

#11 2014-02-07 00:38:25

Xyne
Administrator/PM
Registered: 2008-08-03
Posts: 6,963
Website

Re: cloning an entire hard drive? (including the partitions)

dd copies the raw disk data: boot sectors, partition tables, file data, empty space... everything. dd does not see the partitions or the file systems. All it sees are raw bytes. A disk is just one huge array of bytes. When you copy a full disk with dd, you end up with a copy of that array of bytes. If you copy the array back to the disk at a later time, you end up with the exact same data as when you created the array from the disk (yes, partition tables, file data, deleted files, etc.). It is not efficient if you want to back up your data because it will recopy unchanged bytes and it will copy all unused bytes. If you have a 1 TB disk then dd will copy 1 TB every time it is run (assuming no errors), even if you only have a 100 GB partition with 20 GB of files on it. Whatever time you may eventually save from not needing to recreate the partition table and file systems will be lost 100 times over through regular backups using dd.

In your case I would create a script to regenerate the partition table and file systems if necessary and then use a tool like rsync to back up and restore data as necessary. It will be much faster.

ddrescue is only better if there are disk errors (e.g. bad sectors that generate read errors). Under normal operation it is neither better nor worse than dd afaik.

Fun fact: paritions copied to files with dd can be mounted as regular disks with the "mount" command. You can use this to create encrypted LUKS partition files as a sort of poor man's TrueCrypt.


My Arch Linux StuffForum EtiquetteCommunity Ethos - Arch is not for everyone

Offline

#12 2014-02-07 01:07:35

WonderWoofy
Member
From: Los Gatos, CA
Registered: 2012-05-19
Posts: 8,414

Re: cloning an entire hard drive? (including the partitions)

Xyne wrote:

<snip>
In your case I would create a script to regenerate the partition table and file systems if necessary and then use a tool like rsync to back up and restore data as necessary. It will be much faster.
<snip>

I came here to say exactly this.  In addition to being faster, it will also rewrite every file sequentially.  So if you use a HDD you can enjoy the benefits of a nice defrag as well.

Offline

Board footer

Powered by FluxBB