LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Restore 2 Partitions (https://www.linuxquestions.org/questions/linux-newbie-8/restore-2-partitions-4175456031/)

Soapm 03-29-2013 10:53 AM

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???

Madhu Desai 03-29-2013 11:23 AM

How about clonezilla?

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

ozar 03-29-2013 12:57 PM

Hello

Another good option in addition to the above recommendation would be to use FSArchiver.

spiky0011 03-29-2013 01:18 PM

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

Soapm 03-29-2013 03:29 PM

Quote:

Originally Posted by spiky0011 (Post 4921178)
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...

Soapm 03-29-2013 03:44 PM

Quote:

Originally Posted by mddesai (Post 4921144)


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.

Soapm 03-29-2013 03:47 PM

Quote:

Originally Posted by ozar (Post 4921171)
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.

spiky0011 03-29-2013 03:54 PM

Have a look at this might help explain some things
http://en.wikipedia.org/wiki/Dd_%28Unix%29

syg00 03-29-2013 05:34 PM

Quote:

Originally Posted by Soapm (Post 4921136)
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.

Soapm 03-29-2013 05:56 PM

Quote:

Originally Posted by syg00 (Post 4921321)
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 (Post 4921321)
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.

syg00 03-29-2013 07:29 PM

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.

Soapm 03-31-2013 02:03 AM

Quote:

Originally Posted by syg00 (Post 4921366)
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...

wroom 03-31-2013 07:34 AM

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.

jschiwal 03-31-2013 07:44 AM

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.


All times are GMT -5. The time now is 09:18 PM.