LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 10-07-2013, 04:54 AM   #1
Corsari
Member
 
Registered: Oct 2004
Posts: 57

Rep: Reputation: 15
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

Last edited by Corsari; 10-07-2013 at 04:57 AM.
 
Old 10-07-2013, 05:18 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,927

Rep: Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320
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?
 
Old 10-07-2013, 05:31 AM   #3
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,139

Rep: Reputation: 4122Reputation: 4122Reputation: 4122Reputation: 4122Reputation: 4122Reputation: 4122Reputation: 4122Reputation: 4122Reputation: 4122Reputation: 4122Reputation: 4122
Quote:
Originally Posted by pan64 View Post
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.
 
Old 10-07-2013, 07:56 AM   #4
Corsari
Member
 
Registered: Oct 2004
Posts: 57

Original Poster
Rep: Reputation: 15
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

Last edited by Corsari; 10-07-2013 at 08:06 AM.
 
Old 10-07-2013, 08:49 AM   #5
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,927

Rep: Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320
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.
 
Old 10-07-2013, 10:03 AM   #6
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,781

Rep: Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214
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.

Last edited by rknichols; 10-07-2013 at 10:10 AM.
 
Old 10-07-2013, 10:59 AM   #7
Corsari
Member
 
Registered: Oct 2004
Posts: 57

Original Poster
Rep: Reputation: 15
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?

Last edited by Corsari; 10-07-2013 at 11:01 AM.
 
Old 10-07-2013, 11:04 AM   #8
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,781

Rep: Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214
Physically overwrite.
 
Old 10-07-2013, 11:14 AM   #9
Corsari
Member
 
Registered: Oct 2004
Posts: 57

Original Poster
Rep: Reputation: 15
one last curiosity
you don't use parameters as 512byte or 1k or more

are those intended for disk drive operations only?

Thank you
 
Old 10-07-2013, 12:07 PM   #10
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,781

Rep: Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214
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.
 
Old 10-09-2013, 04:19 PM   #11
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
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.
 
  


Reply



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
[SOLVED] sequence and merge jpeg images using pyhton? dili Programming 7 06-11-2010 05:04 AM
Disk Images errorsunknownp Linux - Software 3 12-30-2008 05:00 AM
Merge INITRD images in Slack12 ?? orbit Slackware 35 05-08-2008 05:58 PM
How do you merge 4 CD ISO images into one DVD ISO image? nsydenham Linux - Software 6 01-15-2007 09:49 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 12:10 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
Open Source Consulting | Domain Registration