LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   How to use dd ddrescue to merge two disk images (https://www.linuxquestions.org/questions/linux-software-2/how-to-use-dd-ddrescue-to-merge-two-disk-images-4175479890/)

Corsari 10-07-2013 04:54 AM

How to use dd ddrescue to merge two disk images
 
Hello to all the users

I'm not sure on how to use dd or ddrescue to do what follow

I have two disks images disk1.bin (700MB) and disk2.bin (300MB)

Since disk2.bin is only partial but complete, from first byte 0 up to last byte 300M and something, I need to overwrite the same first 300MB of disk1.bin with the content of disk2.bin with all the available disk2.bin bytes

Since I have no space for backups, I need to issue the correct command, and here I'm asking kind hints

Can you kindly hint which is the best correct command either with dd or ddrescue to achieve such merging process?

Thank you

Cor

pan64 10-07-2013 05:18 AM

I do not really understand it. First, you must have space enough to complete it, otherwise it will be really hard, but probably not impossible. Next, overwriting the first 300 MB will mean the remaining 400 will not be available any more.
What is the real goal?

syg00 10-07-2013 05:31 AM

Quote:

Originally Posted by pan64 (Post 5041417)
I do not really understand it.

Me too.
Quote:

Next, overwriting the first 300 MB will mean the remaining 400 will not be available any more.
Not necessarily, but will require some finesse - both in the original backup, and in the restore.
Given the question has even been raised, one certainly has to doubt the ability to recover (all) the data.

Corsari 10-07-2013 07:56 AM

Hello Pan and Syg

thank you both for your kind replies

disk1.bin covers the entire drive, but it is damaged in many areas, damages are present also in its first 300MB,

disk2.bin is an previous image that stopped imaging at more or less 50%, but such rough first 300MB are perfect and error free.

Now creating an image where the first part of 700MB is made with the disk2.bin content and the rest of the 700MB remains the original disk1.bin content, will provide the most valuable result.

I know how to do it with a double passage
- dump disk1.bin on top of an hard drive
- repeat the operation using disk2.bin as source

I'd like to skip this solution as it requires an additional hard drive while I'm pretty sure it can be done "at once", especially with dd.

So the question, kindly remains:
how to achieve a byte to byte merge/overwrite of disk1.bin and disk2.bin, picking as source disk2.bin to displace on top of disk1.bin.

Thank you

Cor

pan64 10-07-2013 08:49 AM

you can achive it easily, just you will need to take disk2.bin and append the content of disk1.bin (after cutting the first part).
The problem is that as long as disk1.bin and disk2.bin is opened you will not be able to remove them from the disk, therefore this small app will create an additional new file (even when you try appending). So actually I would rather use a pendrive (or whatever) to move onto another drive/host, split disk1 and concatenate disk2 and disk1.

rknichols 10-07-2013 10:03 AM

As I understand it, you want to overwrite the first part of disk1.bin with the contents of disk2.bin. That is pretty simple:
Code:

dd if=disk2.bin conv=notrunc of=disk1.bin
That will take the entire contents of disk2.bin and write it over the beginning of disk1.bin. If you only need a portion of disk2.bin, you can use the "bs=" and "count=" operands to specify. The "conv=notrunc" is essential, or else the size of disk1.bin will be truncated to the amount copied from disk2.bin.

Note: Dangerous as Hell to be doing this without any backup for the data.

Corsari 10-07-2013 10:59 AM

Hello rknichols

thank you so much

your one is the kind and piece of info I was wondering about

Thank you to pan64 too

About the note
Note: Dangerous as Hell to be doing this without any backup for the data.

I will be able to regenerate disk1.bin as many times I want, but I must move to another site. Don't worry, I know what you mean :-), BTW thank you

P.S. do you think it will create some kind of intermediate file, or will it physically overwrite the disk1.bin?

rknichols 10-07-2013 11:04 AM

Physically overwrite.

Corsari 10-07-2013 11:14 AM

one last curiosity
you don't use parameters as 512byte or 1k or more

are those intended for disk drive operations only?

Thank you

rknichols 10-07-2013 12:07 PM

You can use them. Totally optional. The operation will be more efficient with a larger blocksize, and if you are trying to move a specific amount of data a different blocksize might make the calculation easier. I typically use 32k since one time in the (now distant) past I did some testing and found that there wasn't much improvement when going larger. In the interest of conciseness, I didn't mention blocksize.

jpollard 10-09-2013 04:19 PM

And if you didn't want to use all of the disk2.bin (you say you want the first 300MB)
then you could use
Code:

dd if=disk2.bin conv=notrunc bs=1M count=300 of=disk1.bin
This specifies that the buffer record size is 1MB, and to use only 300 records.

You can get quite elaborate because there is also a "skip" option to skip records before reading, and "seek" options to skip doing output for the number of records (allows you to position the output so that the input starts being written at the given location).

As always, having backups really helps.


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