LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Can dd be used to create an output file larger than the input file? (https://www.linuxquestions.org/questions/linux-software-2/can-dd-be-used-to-create-an-output-file-larger-than-the-input-file-4175420253/)

R00ts 08-03-2012 04:27 PM

Can dd be used to create an output file larger than the input file?
 
I have a 10MB input file and a 30GB output file that I need to produce. What I am looking for is a way to instruct the dd program to continue reading the 10MB file as many times as needed to produce the 30GB output file. Example:

Code:

dd ifile=/root/input_file ofile=/root/output_file bs=1M count=30720
Currently if I try to do this, dd will stop once the end of the input file is reached, so the output file is the same size as (and identical to) the input file. I can't do any tricks like using piping of multiple commands, as I need to measure the time it takes for this single dd call to complete.

I've looked through man pages and have searched around and I haven't been able to find anything that would suggest that this is possible, so this is my last resort. Does anyone have any idea as to how this could be done? (Ideally, the solution is to use a command-line argument available in dd to get me this functionality, but I haven't seen such an ability). Thanks!

rknichols 08-03-2012 06:11 PM

You would have to run dd multiple times, using "conv=notrunc oflag=append" on the 2nd and subsequent invocations.

jefro 08-03-2012 07:39 PM

I might have built the 29+G file and added the input to it.

Kenhelm 08-03-2012 11:02 PM

A single dd command can create a 30M file from a 10M file by appending the file to itself twice, i.e. if the output file is the input file.
Code:

file="file.tmp"
head -c10m < /dev/zero  > "$file"
stat -c%s "$file"
10485760                # 10Mbyte

dd if="$file" of="$file" seek=10 bs=1M count=20

20+0 records in
20+0 records out

stat -c%s "$file"
31457280                # 30Mbyte


R00ts 08-06-2012 10:28 AM

Thanks Kenhelm, I think that might work for me. Ideally I'd like the input and output files to be different, because the input file is to be stored on a RAM disk and the output file is located on a hard disk that we are trying to test the performance of. But given that the input is only 10MB and the output is 30GB, I don't think it will matter too much.


All times are GMT -5. The time now is 04:46 AM.