LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-29-2013, 11:53 AM   #1
Soapm
Member
 
Registered: Dec 2012
Posts: 180

Rep: Reputation: Disabled
Restore 2 Partitions


i have a back up image of a complete drive which contains 9 partitions. The back up was done with dd if=/dev/sda of=/dev/sdc.

Now I want to copy two of the partitions back to the original drive. How can I move to complete partitions? If I use dd if=sdc1 for example it only copies the contents of the partition but not the partition itself. I would like the entire partition moved so it can retain it's partition characteristics like UUID etc...

Is there another tool i can use or am I using dd wrong???
 
Old 03-29-2013, 12:23 PM   #2
mddnix
Member
 
Registered: Mar 2013
Distribution: Redhat, Ubuntu
Posts: 516

Rep: Reputation: 139Reputation: 139
How about clonezilla?

also check http://www.linuxquestions.org/questi...ommand-362506/

Last edited by mddnix; 03-29-2013 at 12:27 PM.
 
Old 03-29-2013, 01:57 PM   #3
ozar
Member
 
Registered: May 2004
Location: USA
Distribution: Arch Linux
Posts: 415

Rep: Reputation: 82
Hello

Another good option in addition to the above recommendation would be to use FSArchiver.
 
Old 03-29-2013, 02:18 PM   #4
spiky0011
Senior Member
 
Registered: Jan 2011
Location: PLANET-SPIKE
Distribution: /LFS/Centos6.3/Debian
Posts: 2,175
Blog Entries: 1

Rep: Reputation: 326Reputation: 326Reputation: 326Reputation: 326
Hi

It looks like the OP has made abackup already and would like to get the 2 partitions back, Hope I'm reading that correct.

If that is so then I think that you will have to dd the backup to somewhere then just dd the 2 partitions you want
 
Old 03-29-2013, 04:29 PM   #5
Soapm
Member
 
Registered: Dec 2012
Posts: 180

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by spiky0011 View Post
Hi

It looks like the OP has made abackup already and would like to get the 2 partitions back, Hope I'm reading that correct.

If that is so then I think that you will have to dd the backup to somewhere then just dd the 2 partitions you want
Yes, that's right. The image is sitting on a separate drive, bootable and everything. When you say dd the back up to somewhere, i don't know what that means. Basically drive B is a mirror of drive A so if the recommended software is able of moving one partition then I think that's what I need. I will give them a look...

Thanks...
 
Old 03-29-2013, 04:44 PM   #6
Soapm
Member
 
Registered: Dec 2012
Posts: 180

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by mddesai View Post

From the second link you gave, this one doesn't seem to be right or maybe I'm doing something wrong. This is what i expected to happen;

Quote:
Examples: duplicate one hard disk partition to another hard disk partition: Sda2 and sdb2 are partitions. You want to duplicate sda2 to sdb2.
Code:
Code:
dd if=/dev/sda2 of=/dev/sdb2 bs=4096 conv=notrunc,noerror
If sdb2 doesn't exist, dd will start at the beginning of the disk, and create it. Be careful with order of if and of. You can write a blank disk to a good disk if you get confused. If you duplicate a smaller partition to a larger one, using dd, the larger one will now be formatted the same as the smaller one. And there will be no space left on the drive. The way around this is to use
From what I am seeing this command isn't copying the partition, it is only copying the contents of the partition. Based on what they're saying I must have had an existing partition with that number or something.

I see they said it will create the partition. Is create the same as mirroring the existing partition meaning it will have the same UUID etc...?

Also, what does this stuff mean at the end of the command? I've never been able to figure out when to use what so I never use any of them, "bs=4096 conv=notrunc,noerror". I go with the strait command and it hasn't failed me yet.
 
Old 03-29-2013, 04:47 PM   #7
Soapm
Member
 
Registered: Dec 2012
Posts: 180

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by ozar View Post
Hello

Another good option in addition to the above recommendation would be to use FSArchiver.
Based on this description I believe this tool only deals with the contents of the partition and not the partition itself.

Quote:
FSArchiver is a system tool that allows you to save the contents of a file-system to a compressed archive file. The file-system can be restored on a partition which has a different size and it can be restored on a different file-system. Unlike tar/dar, FSArchiver also creates the file-system when it extracts the data to partitions. Everything is checksummed in the archive in order to protect the data. If the archive is corrupt, you just loose the current file, not the whole archive. Fsarchiver is released under the GPL-v2 license. You should read the Quick start guide if you are using FSArchiver for the first time.
 
Old 03-29-2013, 04:54 PM   #8
spiky0011
Senior Member
 
Registered: Jan 2011
Location: PLANET-SPIKE
Distribution: /LFS/Centos6.3/Debian
Posts: 2,175
Blog Entries: 1

Rep: Reputation: 326Reputation: 326Reputation: 326Reputation: 326
Have a look at this might help explain some things
http://en.wikipedia.org/wiki/Dd_%28Unix%29
 
Old 03-29-2013, 06:34 PM   #9
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 15,050

Rep: Reputation: 1915Reputation: 1915Reputation: 1915Reputation: 1915Reputation: 1915Reputation: 1915Reputation: 1915Reputation: 1915Reputation: 1915Reputation: 1915Reputation: 1915
Quote:
Originally Posted by Soapm View Post
i have a back up image of a complete drive which contains 9 partitions. The back up was done with dd if=/dev/sda of=/dev/sdc.

Now I want to copy two of the partitions back to the original drive. How can I move to complete partitions? If I use dd if=sdc1 for example it only copies the contents of the partition but not the partition itself. I would like the entire partition moved so it can retain it's partition characteristics like UUID etc...

Is there another tool i can use or am I using dd wrong???
This seems an unreasonable request. Partition definitions are merely the location and size of the space that contains the filesystem. There is "nothing" to them - no UUID, nothing (gpt excepted - tell us if you are using gpt). However there is a defined relationship to their location - and for logical partitions the are chained together. Expecting/hoping to randomly drop a copy of a partition and it's filesystem onto an already occupied disk is unworkable. You should preallocate the partition (which can be larger than needed) and "dd" the image back. The UUID and/or LABEL is part of the filesystem meta-data and will be copied also.
 
Old 03-29-2013, 06:56 PM   #10
Soapm
Member
 
Registered: Dec 2012
Posts: 180

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by syg00 View Post
There is "nothing" to them - no UUID, nothing (gpt excepted - tell us if you are using gpt).
Yes, these are GPT partitions...

Quote:
Originally Posted by syg00 View Post
You should preallocate the partition (which can be larger than needed) and "dd" the image back. The UUID and/or LABEL is part of the filesystem meta-data and will be copied also.
This I did not know, if that is the case then dd is working as advertised. I thought the UUID was in the partition not the filesystem but if it's in the file system then I guess I can make new partitions then dd in the contents... Thanks for that piece of the puzzle.
 
Old 03-29-2013, 08:29 PM   #11
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 15,050

Rep: Reputation: 1915Reputation: 1915Reputation: 1915Reputation: 1915Reputation: 1915Reputation: 1915Reputation: 1915Reputation: 1915Reputation: 1915Reputation: 1915Reputation: 1915
gpt partitions also have a UUID - in addition to the UUID of the filesystem - but is rarely used in "normal" situations.

Be aware if you do restore a partition as you plan, if the original filesystem is still there (different partition) you will not be able to mount both as they will have the same UUID.
 
Old 03-31-2013, 03:03 AM   #12
Soapm
Member
 
Registered: Dec 2012
Posts: 180

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by syg00 View Post
gpt partitions also have a UUID - in addition to the UUID of the filesystem - but is rarely used in "normal" situations.

Be aware if you do restore a partition as you plan, if the original filesystem is still there (different partition) you will not be able to mount both as they will have the same UUID.
I owe you another thanks, you turned me into a gutsy and determined freak but in the end I have what I've been wanting and it's working great. I also didn't have to install any of the OS since as you said, everything copied over.

Thanks...
 
Old 03-31-2013, 08:34 AM   #13
wroom
Member
 
Registered: Dec 2009
Location: Sweden
Posts: 159

Rep: Reputation: 31
My "lazy way" of cloning a drive is to copy the contents to a drive of the same size or bigger using dd.

I then do like the following:
have the SOURCE and TARGET drives connected to a PC or something that runs linux.

One way is to use a live linux system on a CD or USB stick.

And Clonezilla is a very good live cloning system that can manage most drive cloning with ease, but one can also boot Clonezilla up and use the shell to manually do some operations. Clonezilla have a great support of different hardware, like raid controllers, LVM et cetera already set up for you.

Ok. The drives are connected. Make sure they are not mounted in any way!
command 'df' will show if they had been automounted. Then umount them

If there are raid partitions on any of the disks, (SOURCE or TARGET), then the command 'cat /proc/mdstat' will show if the raid partions have been automatically loaded by the system. You will in that case want to stop the raid partitions.
Lets say you want to clone sda to sdd, and 'cat /proc/mdstat' give you the following:
Code:
Personalities : [raid6] [raid5] [raid4] [raid0]
md0 : active raid0 sda1[0] sdb1[1]
      1172463360 blocks 256k chunks

unused devices: <none>
Then you must issue the command 'mdadm --stop /dev/md0' to stop that raid set.
Recheck /proc/mdstat will to see that you stopped the raid set. You will not damage anything unless you stop the raid in the actual booted os that uses the raid. You will merely so to say "unmount" the raid set.

So far, so good.

You can check what partitions and filesystems you currently have on your disks by the commands:
Code:
blockdev --report
which will show you all the recognized drives and partitions, and
Code:
blkid
which will show you the UUID and filesystem type of all drives and partitions recognized by the OS.

Lets say that the TARGET drive already have some partitions on it. Then you will have to remove them first.
Easiest way is to remove them with 'cfdisk' or 'fdisk' or whatever your prefer.
If there are any DOS partitions, you will have to remove them, and then reboot to make sure the system forgets about them. (d*mned sneaky BIOS)!

Check that the partiotions are all gone on /dev/sdd by the command:
Code:
ls /dev/sdd*
It should only list the sdd drive, and not any partitions, like sdd1.

Then, to be paranoid, you can completely remove the partitioning and boot sector data from the target drive, through the following command, where we use /dev/sdd as the TARGET drive:
Code:
dd if=/dev/zero bs=1k count=64k of=/dev/sdd
sync
Which wipes the first 64 megabytes of the TARGET drive /dev/sdd.
(Dont forget the 'sync'. It makes sure the writes are flushed to the disks).

Next step, when we have the SOURCE and TARGET drives online and unmounted, is to copy the partitions.
Simplest way is to first copy over partition table and boot sector from the SOURCE, like the following where SOURCE is /dev/sda and TARGET is /dev/sdd

Code:
dd if=/dev/sda bs=1b count=42 of=/dev/sdd
sync
Copies 42 sectors. Why 42, where one sector is enough? Why not?
Then open up the target drive in cfdisk, take a look, and then Write the contets (unchanged) to disk.
Code:
cfdisk /dev/sdd
This makes sure that BIOS understands the new partitioning of the drive /dev/sdd
If you have copied/created any DOS partitions you will have to reboot before the next step.

You can now check that the partitioning has been copied from /dev/sda to /dev/sdd with:
Code:
ls /dev/sda* /dev/sdd*
if you now want to completely clone the SOURCE drive to the TARGET drive, go ahead and:
Code:
dd if=/dev/sda of=/dev/sdd
sync
You can also copy each partition one by one, like:
Code:
dd if=/dev/sda1 of=/dev/sdd1
sync
Then the cloning is all done.
Disks now have the same partitions, MBR, UUID's and disk volume id. Remember that strange things will happen if you connect both these disks to the same PC, or uses these two disks in two PCs, sinve they have the same UUIDs and disk volume ids. (Especially if you use Windows).

Bear in mind that some PCs use the "dead space" between the first sector containing master boot record and partition table, and the first partition on disk for things like hibernation storage and other "under the hood handling", like for example the IBM/Lenovo Thinkpad laptops, so for a safe clone, just copy the entire drive.


But i still think you should use either Clonezilla or R-Studio to copy the drive. Safer that way.

Last edited by wroom; 03-31-2013 at 08:37 AM.
 
Old 03-31-2013, 08:44 AM   #14
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 671Reputation: 671Reputation: 671Reputation: 671Reputation: 671Reputation: 671
Why back up a drive image to another drive. Why not back it up to a file. If you zero out free space, you can pipe the output of did through gzip, saving space. Image backups are fine after a fresh install, and that is when you have the most free space available. If you save an uncompressed image, you can use losetup to access a partition in it.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Cannot restore partitions from one computer to another. Both RAID0 HawaiiMike Linux - General 10 11-02-2009 12:37 PM
Can I restore my partitions? Terramann Linux - Newbie 12 10-20-2009 01:31 PM
How can I backup/restore different partitions individually? n1c0_ds Linux - Hardware 10 09-07-2009 10:36 AM
back up and restore disk partitions ekdya Debian 2 10-05-2006 05:43 PM
Ubuntu install deleted all my partitions - any way to restore them? Spitfire24 General 5 12-15-2005 07:08 AM


All times are GMT -5. The time now is 04:40 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration