Clone whole partition or hard drive to a sparse file Unicorn Meta Zoo #1: Why another...
Where to find documentation for `whois` command options?
Protagonist's race is hidden - should I reveal it?
Getting AggregateResult variables from Execute Anonymous Window
How to translate "red flag" into Spanish?
When I export an AI 300x60 art board it saves with bigger dimensions
Was Objective-C really a hindrance to Apple software development?
Did war bonds have better investment alternatives during WWII?
Is it accepted to use working hours to read general interest books?
How would it unbalance gameplay to rule that Weapon Master allows for picking a fighting style?
What does the black goddess statue do and what is it?
Was there ever a LEGO store in Miami International Airport?
France's Public Holidays' Puzzle
Processing ADC conversion result: DMA vs Processor Registers
Why is arima in R one time step off?
Does Prince Arnaud cause someone holding the Princess to lose?
TV series episode where humans nuke aliens before decrypting their message that states they come in peace
Why does Java have support for time zone offsets with seconds precision?
Arriving in Atlanta after US Preclearance in Dublin. Will I go through TSA security in Atlanta to transfer to a connecting flight?
When speaking, how do you change your mind mid-sentence?
How was Lagrange appointed professor of mathematics so early?
Why did Israel vote against lifting the American embargo on Cuba?
Israeli soda type drink
Does a Draconic Bloodline sorcerer's doubled proficiency bonus for Charisma checks against dragons apply to all dragon types or only the chosen one?
Why I cannot instantiate a class whose constructor is private in a friend class?
Clone whole partition or hard drive to a sparse file
Unicorn Meta Zoo #1: Why another podcast?
Announcing the arrival of Valued Associate #679: Cesar Manara
2019 Community Moderator Election Results
Why I closed the “Why is Kali so hard” questionvolcopy for Linux?From a sparse file to a block deviceHow to clone RFS on NAND on ARM Chip?Stripping null byte blocks with a sparse file?How to use DD to clone a partition off a disk image?Ext4 exhibits unexpected write latency variance vs. ext2From a sparse file to a block deviceWhat is the correct syntax for cloning a ntfs partition to a sparse file on another ntfs drive?Can I mount a partition from a full drive image?Create and use sparse file as non-privileged userUnderstanding sparse files, dd, seek, inode block structureDisk space error when using DD to write to raw disk in external reader?Dumping a single partition with dd (not the entire disk)
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}
I like to clone a whole partition or a whole hard drive onto a larger external disk but like to create a sparse file. I often use dd
for cloning, but it doesn't support sparse files. As a workaround I used something like:
cp --sparse=always <(dd if=/dev/sda1 bs=8M) /mount/external/backup/sda1.raw
However this is a little too tricky for my taste and doesn't allow me to resume the process if aborted. It is funny that there is a NTFS tool for this (ntfsclone
) but no such tool exists for the native file systems of Linux (EXT2-4).
Is there some better tool for this, e.g. a dd
variant with sparse support?
I do not look for some proprietary software for disk backups but simply want to make a sparse clone copy which I can mount as loop device if required.
dd cloning sparse-files
add a comment |
I like to clone a whole partition or a whole hard drive onto a larger external disk but like to create a sparse file. I often use dd
for cloning, but it doesn't support sparse files. As a workaround I used something like:
cp --sparse=always <(dd if=/dev/sda1 bs=8M) /mount/external/backup/sda1.raw
However this is a little too tricky for my taste and doesn't allow me to resume the process if aborted. It is funny that there is a NTFS tool for this (ntfsclone
) but no such tool exists for the native file systems of Linux (EXT2-4).
Is there some better tool for this, e.g. a dd
variant with sparse support?
I do not look for some proprietary software for disk backups but simply want to make a sparse clone copy which I can mount as loop device if required.
dd cloning sparse-files
7
+1 for creative use ofcp
, it never occurred to me that you could sparse-copy a disk image. I always just compressed them if I needed to save space. Now why is that in a question not an answer?
– Caleb
Jul 20 '11 at 20:05
add a comment |
I like to clone a whole partition or a whole hard drive onto a larger external disk but like to create a sparse file. I often use dd
for cloning, but it doesn't support sparse files. As a workaround I used something like:
cp --sparse=always <(dd if=/dev/sda1 bs=8M) /mount/external/backup/sda1.raw
However this is a little too tricky for my taste and doesn't allow me to resume the process if aborted. It is funny that there is a NTFS tool for this (ntfsclone
) but no such tool exists for the native file systems of Linux (EXT2-4).
Is there some better tool for this, e.g. a dd
variant with sparse support?
I do not look for some proprietary software for disk backups but simply want to make a sparse clone copy which I can mount as loop device if required.
dd cloning sparse-files
I like to clone a whole partition or a whole hard drive onto a larger external disk but like to create a sparse file. I often use dd
for cloning, but it doesn't support sparse files. As a workaround I used something like:
cp --sparse=always <(dd if=/dev/sda1 bs=8M) /mount/external/backup/sda1.raw
However this is a little too tricky for my taste and doesn't allow me to resume the process if aborted. It is funny that there is a NTFS tool for this (ntfsclone
) but no such tool exists for the native file systems of Linux (EXT2-4).
Is there some better tool for this, e.g. a dd
variant with sparse support?
I do not look for some proprietary software for disk backups but simply want to make a sparse clone copy which I can mount as loop device if required.
dd cloning sparse-files
dd cloning sparse-files
edited May 28 '12 at 10:54
maxschlepzig
34.8k34142214
34.8k34142214
asked Jul 20 '11 at 19:48
Martin ScharrerMartin Scharrer
64511014
64511014
7
+1 for creative use ofcp
, it never occurred to me that you could sparse-copy a disk image. I always just compressed them if I needed to save space. Now why is that in a question not an answer?
– Caleb
Jul 20 '11 at 20:05
add a comment |
7
+1 for creative use ofcp
, it never occurred to me that you could sparse-copy a disk image. I always just compressed them if I needed to save space. Now why is that in a question not an answer?
– Caleb
Jul 20 '11 at 20:05
7
7
+1 for creative use of
cp
, it never occurred to me that you could sparse-copy a disk image. I always just compressed them if I needed to save space. Now why is that in a question not an answer?– Caleb
Jul 20 '11 at 20:05
+1 for creative use of
cp
, it never occurred to me that you could sparse-copy a disk image. I always just compressed them if I needed to save space. Now why is that in a question not an answer?– Caleb
Jul 20 '11 at 20:05
add a comment |
7 Answers
7
active
oldest
votes
You want dd_rescue
.
dd_rescue -a -b 8M /dev/sda1 /mount/external/backup/sda1.raw
1
Great! The manual says "If the copying process is interrupted by the user it is possible to continue at any position later." and "-a spArse file writing (default=no)". Exactly what I want! Thanks!
– Martin Scharrer
Jul 24 '11 at 21:56
3
Looking fordd_rescue
online I found out that there is also a different tool calledddrescue
(without the underscore) which was developed independently fromdd_rescue
but seems to do basically the same. I just mention that here as a general FYI.
– Martin Scharrer
Jul 24 '11 at 22:11
Yeah,dd_rescue
andddrescue
aren't the same thing. Theoretically they do the same job, but generally I've had better luck with the older/originaldd_rescue
.
– Steven Pritchard
Jul 24 '11 at 22:49
1
In case anyone is wondering, you can stop the copy at any time with Ctrl-C. It will show you your current position, and you can use that value to restart by adding-s
and the position to the original command. (So it would look likedd_rescue -a -b 8M -s 42000k /dev/sda1 /mount/external/backup/sda1.raw
.)
– Steven Pritchard
Jul 24 '11 at 23:05
1
@Steven Pritchard: No need to remember the position. Specify a third filename, which will be the logfile, and on restart it'll read that and pick up where it left off.
– Tanith Rosenbaum
Nov 9 '14 at 19:38
add a comment |
Just for completeness the call for ddrescue. The --sparse
or -S
flag allows the destination to be written sparsely:
$ ddrescue -S -b8M /dev/sda1 /mount/external/backup/sda1.raw
Or with long option:
$ ddrescue --sparse --block-size 8M /dev/sda1 /mount/external/backup/sda1.raw
Or if you prefer MiBs:
$ ddrescue -S -b8Mi /dev/sda1 /mount/external/backup/sda1.raw
To allow the rescue to be interrupted and resumed, you can also make use of a logfile:
$ ddrescue -S -b8Mi /dev/sda1 /mount/external/backup/sda1.raw ~/sda1.rescue.log
Note that GNU ddrescue
and dd_rescue
are different programs. But GNU ddrescue
seems to be more widespread. For example it is already packaged with GRML.
Does there need to be any special treatment of the image when restoring, can you provide the command used to restore a ddrescue?
– user12439
Apr 6 '16 at 22:46
In theory the storage medium you're using for the rescue is supposed to be more reliable, so you can typically just use dd to write to the replacement disk:dd if=sda1.raw of=/dev/sdb1
. However, to use ddrescue for the restore, you just change the source/destination you used for the rescue to the new source/destination, preferably with a new log file. If possible (often not), you can of course use ddrescue to copy data directly from the bad source disk to a replacement disk.
– zaTricky
May 15 '18 at 7:49
add a comment |
There was a patch offered in 2007 to provide sparse file support in GNU dd, but it looks to have not made it into coreutils (at least not as of 8.4). I doubt dd has changed too much since then, the patch might apply against the current version without a lot of work.
I'm also really impressed by the creative use of cp
in your question, and it got me on the track of using it to accomplish resuming (here resuming from ~80M into the source):
cp --sparse=always
<(dd if=/dev/sda1 bs=8M skip=10) /dev/stdout
| dd bs=8M seek=10 of=/mount/external/backup/sda1.raw
Edit: scratch that. The second dd
would of course be seeking to the wrong position in the output file, since it's not the same length as the input.
As is the case with bhinesley's answer, it would be best to log dd's progress for accurate resuming. If you were to use this approach for both the first run and resumes, and log both parallel dd's independently, then you could know how far into the output to seek. If I have time I'll try to work this up.
– Eli Heady
Jul 22 '11 at 18:48
2
Thanks for the link to the patch. I was starting to think about programming something like it by myself :-) Sparse files can't be pipped so your code won't work.
– Martin Scharrer
Jul 22 '11 at 18:50
Yup, I just discovered that myself. Oh well, it was fun finding crazy new uses ofcp
- thanks!
– Eli Heady
Jul 22 '11 at 18:58
dd commit at 2012: git.savannah.gnu.org/cgit/coreutils.git/commit/… "dd: add support for the conv=sparse option" ("(iwrite): Convert a write of a NUL block to a seek if requested.")
– osgx
May 19 '18 at 5:12
add a comment |
Just adding my 2 cents. Another way to create a sparse file from a raw disk is with qemu-img using something like:
qemu-img convert -f raw /dev/sda /tmp/sda.raw
You can use this on a single partition as well. Also, you have the option to convert the raw disk/partition to any other format that qemu-img supports (QCOW2, VHD[x], vmdk, etc)
add a comment |
Note: this doesn't work for the reasons described in the comments, I'm leaving it here for reference.
Monitor the statistics of dd by using kill -USR1:
$ cp --sparse=always <(dd if=/dev/urandom bs=8M)
/mount/external/backup/sda1.raw&
$ watch kill -USR1 `pidof -s /bin/dd`
Resume by using skip/seek:
$ i_bytes= # get from the last dd statistic
$ o_bytes=`du -b /mount/external/backup/sda1.raw | cut -f 1`
$ cp --sparse=always <(dd if=/dev/urandom bs=8M skip=$i_bytes
seek=$o_bytes) /mount/external/backup/sda1.raw&
$ watch kill -USR1 `pidof -s /bin/dd`
Without $i_bytes it would be more difficult to resume. It's probably easiest to log the dd statistics to a file in case the machine crashes or whatever.
The secondcp
will just overwrite the existing file, wouldn't it? I know theskip
and other options ofdd
. The issue is thecp
part.
– Martin Scharrer
Jul 21 '11 at 18:14
Hm, yeah, you're right.
– bhinesley
Jul 21 '11 at 18:18
add a comment |
There are xfsdump and xfsrestore for XFS which has been a native Linux filesystem for quite a long time.
add a comment |
Why not simply:
cp --sparse=always /dev/sda1 /mount/external/backup/sda1.raw
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f17087%2fclone-whole-partition-or-hard-drive-to-a-sparse-file%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
7 Answers
7
active
oldest
votes
7 Answers
7
active
oldest
votes
active
oldest
votes
active
oldest
votes
You want dd_rescue
.
dd_rescue -a -b 8M /dev/sda1 /mount/external/backup/sda1.raw
1
Great! The manual says "If the copying process is interrupted by the user it is possible to continue at any position later." and "-a spArse file writing (default=no)". Exactly what I want! Thanks!
– Martin Scharrer
Jul 24 '11 at 21:56
3
Looking fordd_rescue
online I found out that there is also a different tool calledddrescue
(without the underscore) which was developed independently fromdd_rescue
but seems to do basically the same. I just mention that here as a general FYI.
– Martin Scharrer
Jul 24 '11 at 22:11
Yeah,dd_rescue
andddrescue
aren't the same thing. Theoretically they do the same job, but generally I've had better luck with the older/originaldd_rescue
.
– Steven Pritchard
Jul 24 '11 at 22:49
1
In case anyone is wondering, you can stop the copy at any time with Ctrl-C. It will show you your current position, and you can use that value to restart by adding-s
and the position to the original command. (So it would look likedd_rescue -a -b 8M -s 42000k /dev/sda1 /mount/external/backup/sda1.raw
.)
– Steven Pritchard
Jul 24 '11 at 23:05
1
@Steven Pritchard: No need to remember the position. Specify a third filename, which will be the logfile, and on restart it'll read that and pick up where it left off.
– Tanith Rosenbaum
Nov 9 '14 at 19:38
add a comment |
You want dd_rescue
.
dd_rescue -a -b 8M /dev/sda1 /mount/external/backup/sda1.raw
1
Great! The manual says "If the copying process is interrupted by the user it is possible to continue at any position later." and "-a spArse file writing (default=no)". Exactly what I want! Thanks!
– Martin Scharrer
Jul 24 '11 at 21:56
3
Looking fordd_rescue
online I found out that there is also a different tool calledddrescue
(without the underscore) which was developed independently fromdd_rescue
but seems to do basically the same. I just mention that here as a general FYI.
– Martin Scharrer
Jul 24 '11 at 22:11
Yeah,dd_rescue
andddrescue
aren't the same thing. Theoretically they do the same job, but generally I've had better luck with the older/originaldd_rescue
.
– Steven Pritchard
Jul 24 '11 at 22:49
1
In case anyone is wondering, you can stop the copy at any time with Ctrl-C. It will show you your current position, and you can use that value to restart by adding-s
and the position to the original command. (So it would look likedd_rescue -a -b 8M -s 42000k /dev/sda1 /mount/external/backup/sda1.raw
.)
– Steven Pritchard
Jul 24 '11 at 23:05
1
@Steven Pritchard: No need to remember the position. Specify a third filename, which will be the logfile, and on restart it'll read that and pick up where it left off.
– Tanith Rosenbaum
Nov 9 '14 at 19:38
add a comment |
You want dd_rescue
.
dd_rescue -a -b 8M /dev/sda1 /mount/external/backup/sda1.raw
You want dd_rescue
.
dd_rescue -a -b 8M /dev/sda1 /mount/external/backup/sda1.raw
edited Apr 13 '12 at 14:12
earl
1033
1033
answered Jul 24 '11 at 21:50
Steven PritchardSteven Pritchard
1,9381013
1,9381013
1
Great! The manual says "If the copying process is interrupted by the user it is possible to continue at any position later." and "-a spArse file writing (default=no)". Exactly what I want! Thanks!
– Martin Scharrer
Jul 24 '11 at 21:56
3
Looking fordd_rescue
online I found out that there is also a different tool calledddrescue
(without the underscore) which was developed independently fromdd_rescue
but seems to do basically the same. I just mention that here as a general FYI.
– Martin Scharrer
Jul 24 '11 at 22:11
Yeah,dd_rescue
andddrescue
aren't the same thing. Theoretically they do the same job, but generally I've had better luck with the older/originaldd_rescue
.
– Steven Pritchard
Jul 24 '11 at 22:49
1
In case anyone is wondering, you can stop the copy at any time with Ctrl-C. It will show you your current position, and you can use that value to restart by adding-s
and the position to the original command. (So it would look likedd_rescue -a -b 8M -s 42000k /dev/sda1 /mount/external/backup/sda1.raw
.)
– Steven Pritchard
Jul 24 '11 at 23:05
1
@Steven Pritchard: No need to remember the position. Specify a third filename, which will be the logfile, and on restart it'll read that and pick up where it left off.
– Tanith Rosenbaum
Nov 9 '14 at 19:38
add a comment |
1
Great! The manual says "If the copying process is interrupted by the user it is possible to continue at any position later." and "-a spArse file writing (default=no)". Exactly what I want! Thanks!
– Martin Scharrer
Jul 24 '11 at 21:56
3
Looking fordd_rescue
online I found out that there is also a different tool calledddrescue
(without the underscore) which was developed independently fromdd_rescue
but seems to do basically the same. I just mention that here as a general FYI.
– Martin Scharrer
Jul 24 '11 at 22:11
Yeah,dd_rescue
andddrescue
aren't the same thing. Theoretically they do the same job, but generally I've had better luck with the older/originaldd_rescue
.
– Steven Pritchard
Jul 24 '11 at 22:49
1
In case anyone is wondering, you can stop the copy at any time with Ctrl-C. It will show you your current position, and you can use that value to restart by adding-s
and the position to the original command. (So it would look likedd_rescue -a -b 8M -s 42000k /dev/sda1 /mount/external/backup/sda1.raw
.)
– Steven Pritchard
Jul 24 '11 at 23:05
1
@Steven Pritchard: No need to remember the position. Specify a third filename, which will be the logfile, and on restart it'll read that and pick up where it left off.
– Tanith Rosenbaum
Nov 9 '14 at 19:38
1
1
Great! The manual says "If the copying process is interrupted by the user it is possible to continue at any position later." and "-a spArse file writing (default=no)". Exactly what I want! Thanks!
– Martin Scharrer
Jul 24 '11 at 21:56
Great! The manual says "If the copying process is interrupted by the user it is possible to continue at any position later." and "-a spArse file writing (default=no)". Exactly what I want! Thanks!
– Martin Scharrer
Jul 24 '11 at 21:56
3
3
Looking for
dd_rescue
online I found out that there is also a different tool called ddrescue
(without the underscore) which was developed independently from dd_rescue
but seems to do basically the same. I just mention that here as a general FYI.– Martin Scharrer
Jul 24 '11 at 22:11
Looking for
dd_rescue
online I found out that there is also a different tool called ddrescue
(without the underscore) which was developed independently from dd_rescue
but seems to do basically the same. I just mention that here as a general FYI.– Martin Scharrer
Jul 24 '11 at 22:11
Yeah,
dd_rescue
and ddrescue
aren't the same thing. Theoretically they do the same job, but generally I've had better luck with the older/original dd_rescue
.– Steven Pritchard
Jul 24 '11 at 22:49
Yeah,
dd_rescue
and ddrescue
aren't the same thing. Theoretically they do the same job, but generally I've had better luck with the older/original dd_rescue
.– Steven Pritchard
Jul 24 '11 at 22:49
1
1
In case anyone is wondering, you can stop the copy at any time with Ctrl-C. It will show you your current position, and you can use that value to restart by adding
-s
and the position to the original command. (So it would look like dd_rescue -a -b 8M -s 42000k /dev/sda1 /mount/external/backup/sda1.raw
.)– Steven Pritchard
Jul 24 '11 at 23:05
In case anyone is wondering, you can stop the copy at any time with Ctrl-C. It will show you your current position, and you can use that value to restart by adding
-s
and the position to the original command. (So it would look like dd_rescue -a -b 8M -s 42000k /dev/sda1 /mount/external/backup/sda1.raw
.)– Steven Pritchard
Jul 24 '11 at 23:05
1
1
@Steven Pritchard: No need to remember the position. Specify a third filename, which will be the logfile, and on restart it'll read that and pick up where it left off.
– Tanith Rosenbaum
Nov 9 '14 at 19:38
@Steven Pritchard: No need to remember the position. Specify a third filename, which will be the logfile, and on restart it'll read that and pick up where it left off.
– Tanith Rosenbaum
Nov 9 '14 at 19:38
add a comment |
Just for completeness the call for ddrescue. The --sparse
or -S
flag allows the destination to be written sparsely:
$ ddrescue -S -b8M /dev/sda1 /mount/external/backup/sda1.raw
Or with long option:
$ ddrescue --sparse --block-size 8M /dev/sda1 /mount/external/backup/sda1.raw
Or if you prefer MiBs:
$ ddrescue -S -b8Mi /dev/sda1 /mount/external/backup/sda1.raw
To allow the rescue to be interrupted and resumed, you can also make use of a logfile:
$ ddrescue -S -b8Mi /dev/sda1 /mount/external/backup/sda1.raw ~/sda1.rescue.log
Note that GNU ddrescue
and dd_rescue
are different programs. But GNU ddrescue
seems to be more widespread. For example it is already packaged with GRML.
Does there need to be any special treatment of the image when restoring, can you provide the command used to restore a ddrescue?
– user12439
Apr 6 '16 at 22:46
In theory the storage medium you're using for the rescue is supposed to be more reliable, so you can typically just use dd to write to the replacement disk:dd if=sda1.raw of=/dev/sdb1
. However, to use ddrescue for the restore, you just change the source/destination you used for the rescue to the new source/destination, preferably with a new log file. If possible (often not), you can of course use ddrescue to copy data directly from the bad source disk to a replacement disk.
– zaTricky
May 15 '18 at 7:49
add a comment |
Just for completeness the call for ddrescue. The --sparse
or -S
flag allows the destination to be written sparsely:
$ ddrescue -S -b8M /dev/sda1 /mount/external/backup/sda1.raw
Or with long option:
$ ddrescue --sparse --block-size 8M /dev/sda1 /mount/external/backup/sda1.raw
Or if you prefer MiBs:
$ ddrescue -S -b8Mi /dev/sda1 /mount/external/backup/sda1.raw
To allow the rescue to be interrupted and resumed, you can also make use of a logfile:
$ ddrescue -S -b8Mi /dev/sda1 /mount/external/backup/sda1.raw ~/sda1.rescue.log
Note that GNU ddrescue
and dd_rescue
are different programs. But GNU ddrescue
seems to be more widespread. For example it is already packaged with GRML.
Does there need to be any special treatment of the image when restoring, can you provide the command used to restore a ddrescue?
– user12439
Apr 6 '16 at 22:46
In theory the storage medium you're using for the rescue is supposed to be more reliable, so you can typically just use dd to write to the replacement disk:dd if=sda1.raw of=/dev/sdb1
. However, to use ddrescue for the restore, you just change the source/destination you used for the rescue to the new source/destination, preferably with a new log file. If possible (often not), you can of course use ddrescue to copy data directly from the bad source disk to a replacement disk.
– zaTricky
May 15 '18 at 7:49
add a comment |
Just for completeness the call for ddrescue. The --sparse
or -S
flag allows the destination to be written sparsely:
$ ddrescue -S -b8M /dev/sda1 /mount/external/backup/sda1.raw
Or with long option:
$ ddrescue --sparse --block-size 8M /dev/sda1 /mount/external/backup/sda1.raw
Or if you prefer MiBs:
$ ddrescue -S -b8Mi /dev/sda1 /mount/external/backup/sda1.raw
To allow the rescue to be interrupted and resumed, you can also make use of a logfile:
$ ddrescue -S -b8Mi /dev/sda1 /mount/external/backup/sda1.raw ~/sda1.rescue.log
Note that GNU ddrescue
and dd_rescue
are different programs. But GNU ddrescue
seems to be more widespread. For example it is already packaged with GRML.
Just for completeness the call for ddrescue. The --sparse
or -S
flag allows the destination to be written sparsely:
$ ddrescue -S -b8M /dev/sda1 /mount/external/backup/sda1.raw
Or with long option:
$ ddrescue --sparse --block-size 8M /dev/sda1 /mount/external/backup/sda1.raw
Or if you prefer MiBs:
$ ddrescue -S -b8Mi /dev/sda1 /mount/external/backup/sda1.raw
To allow the rescue to be interrupted and resumed, you can also make use of a logfile:
$ ddrescue -S -b8Mi /dev/sda1 /mount/external/backup/sda1.raw ~/sda1.rescue.log
Note that GNU ddrescue
and dd_rescue
are different programs. But GNU ddrescue
seems to be more widespread. For example it is already packaged with GRML.
edited May 15 '18 at 8:50
zaTricky
23327
23327
answered May 28 '12 at 10:24
maxschlepzigmaxschlepzig
34.8k34142214
34.8k34142214
Does there need to be any special treatment of the image when restoring, can you provide the command used to restore a ddrescue?
– user12439
Apr 6 '16 at 22:46
In theory the storage medium you're using for the rescue is supposed to be more reliable, so you can typically just use dd to write to the replacement disk:dd if=sda1.raw of=/dev/sdb1
. However, to use ddrescue for the restore, you just change the source/destination you used for the rescue to the new source/destination, preferably with a new log file. If possible (often not), you can of course use ddrescue to copy data directly from the bad source disk to a replacement disk.
– zaTricky
May 15 '18 at 7:49
add a comment |
Does there need to be any special treatment of the image when restoring, can you provide the command used to restore a ddrescue?
– user12439
Apr 6 '16 at 22:46
In theory the storage medium you're using for the rescue is supposed to be more reliable, so you can typically just use dd to write to the replacement disk:dd if=sda1.raw of=/dev/sdb1
. However, to use ddrescue for the restore, you just change the source/destination you used for the rescue to the new source/destination, preferably with a new log file. If possible (often not), you can of course use ddrescue to copy data directly from the bad source disk to a replacement disk.
– zaTricky
May 15 '18 at 7:49
Does there need to be any special treatment of the image when restoring, can you provide the command used to restore a ddrescue?
– user12439
Apr 6 '16 at 22:46
Does there need to be any special treatment of the image when restoring, can you provide the command used to restore a ddrescue?
– user12439
Apr 6 '16 at 22:46
In theory the storage medium you're using for the rescue is supposed to be more reliable, so you can typically just use dd to write to the replacement disk:
dd if=sda1.raw of=/dev/sdb1
. However, to use ddrescue for the restore, you just change the source/destination you used for the rescue to the new source/destination, preferably with a new log file. If possible (often not), you can of course use ddrescue to copy data directly from the bad source disk to a replacement disk.– zaTricky
May 15 '18 at 7:49
In theory the storage medium you're using for the rescue is supposed to be more reliable, so you can typically just use dd to write to the replacement disk:
dd if=sda1.raw of=/dev/sdb1
. However, to use ddrescue for the restore, you just change the source/destination you used for the rescue to the new source/destination, preferably with a new log file. If possible (often not), you can of course use ddrescue to copy data directly from the bad source disk to a replacement disk.– zaTricky
May 15 '18 at 7:49
add a comment |
There was a patch offered in 2007 to provide sparse file support in GNU dd, but it looks to have not made it into coreutils (at least not as of 8.4). I doubt dd has changed too much since then, the patch might apply against the current version without a lot of work.
I'm also really impressed by the creative use of cp
in your question, and it got me on the track of using it to accomplish resuming (here resuming from ~80M into the source):
cp --sparse=always
<(dd if=/dev/sda1 bs=8M skip=10) /dev/stdout
| dd bs=8M seek=10 of=/mount/external/backup/sda1.raw
Edit: scratch that. The second dd
would of course be seeking to the wrong position in the output file, since it's not the same length as the input.
As is the case with bhinesley's answer, it would be best to log dd's progress for accurate resuming. If you were to use this approach for both the first run and resumes, and log both parallel dd's independently, then you could know how far into the output to seek. If I have time I'll try to work this up.
– Eli Heady
Jul 22 '11 at 18:48
2
Thanks for the link to the patch. I was starting to think about programming something like it by myself :-) Sparse files can't be pipped so your code won't work.
– Martin Scharrer
Jul 22 '11 at 18:50
Yup, I just discovered that myself. Oh well, it was fun finding crazy new uses ofcp
- thanks!
– Eli Heady
Jul 22 '11 at 18:58
dd commit at 2012: git.savannah.gnu.org/cgit/coreutils.git/commit/… "dd: add support for the conv=sparse option" ("(iwrite): Convert a write of a NUL block to a seek if requested.")
– osgx
May 19 '18 at 5:12
add a comment |
There was a patch offered in 2007 to provide sparse file support in GNU dd, but it looks to have not made it into coreutils (at least not as of 8.4). I doubt dd has changed too much since then, the patch might apply against the current version without a lot of work.
I'm also really impressed by the creative use of cp
in your question, and it got me on the track of using it to accomplish resuming (here resuming from ~80M into the source):
cp --sparse=always
<(dd if=/dev/sda1 bs=8M skip=10) /dev/stdout
| dd bs=8M seek=10 of=/mount/external/backup/sda1.raw
Edit: scratch that. The second dd
would of course be seeking to the wrong position in the output file, since it's not the same length as the input.
As is the case with bhinesley's answer, it would be best to log dd's progress for accurate resuming. If you were to use this approach for both the first run and resumes, and log both parallel dd's independently, then you could know how far into the output to seek. If I have time I'll try to work this up.
– Eli Heady
Jul 22 '11 at 18:48
2
Thanks for the link to the patch. I was starting to think about programming something like it by myself :-) Sparse files can't be pipped so your code won't work.
– Martin Scharrer
Jul 22 '11 at 18:50
Yup, I just discovered that myself. Oh well, it was fun finding crazy new uses ofcp
- thanks!
– Eli Heady
Jul 22 '11 at 18:58
dd commit at 2012: git.savannah.gnu.org/cgit/coreutils.git/commit/… "dd: add support for the conv=sparse option" ("(iwrite): Convert a write of a NUL block to a seek if requested.")
– osgx
May 19 '18 at 5:12
add a comment |
There was a patch offered in 2007 to provide sparse file support in GNU dd, but it looks to have not made it into coreutils (at least not as of 8.4). I doubt dd has changed too much since then, the patch might apply against the current version without a lot of work.
I'm also really impressed by the creative use of cp
in your question, and it got me on the track of using it to accomplish resuming (here resuming from ~80M into the source):
cp --sparse=always
<(dd if=/dev/sda1 bs=8M skip=10) /dev/stdout
| dd bs=8M seek=10 of=/mount/external/backup/sda1.raw
Edit: scratch that. The second dd
would of course be seeking to the wrong position in the output file, since it's not the same length as the input.
There was a patch offered in 2007 to provide sparse file support in GNU dd, but it looks to have not made it into coreutils (at least not as of 8.4). I doubt dd has changed too much since then, the patch might apply against the current version without a lot of work.
I'm also really impressed by the creative use of cp
in your question, and it got me on the track of using it to accomplish resuming (here resuming from ~80M into the source):
cp --sparse=always
<(dd if=/dev/sda1 bs=8M skip=10) /dev/stdout
| dd bs=8M seek=10 of=/mount/external/backup/sda1.raw
Edit: scratch that. The second dd
would of course be seeking to the wrong position in the output file, since it's not the same length as the input.
answered Jul 22 '11 at 18:44
Eli HeadyEli Heady
1,184618
1,184618
As is the case with bhinesley's answer, it would be best to log dd's progress for accurate resuming. If you were to use this approach for both the first run and resumes, and log both parallel dd's independently, then you could know how far into the output to seek. If I have time I'll try to work this up.
– Eli Heady
Jul 22 '11 at 18:48
2
Thanks for the link to the patch. I was starting to think about programming something like it by myself :-) Sparse files can't be pipped so your code won't work.
– Martin Scharrer
Jul 22 '11 at 18:50
Yup, I just discovered that myself. Oh well, it was fun finding crazy new uses ofcp
- thanks!
– Eli Heady
Jul 22 '11 at 18:58
dd commit at 2012: git.savannah.gnu.org/cgit/coreutils.git/commit/… "dd: add support for the conv=sparse option" ("(iwrite): Convert a write of a NUL block to a seek if requested.")
– osgx
May 19 '18 at 5:12
add a comment |
As is the case with bhinesley's answer, it would be best to log dd's progress for accurate resuming. If you were to use this approach for both the first run and resumes, and log both parallel dd's independently, then you could know how far into the output to seek. If I have time I'll try to work this up.
– Eli Heady
Jul 22 '11 at 18:48
2
Thanks for the link to the patch. I was starting to think about programming something like it by myself :-) Sparse files can't be pipped so your code won't work.
– Martin Scharrer
Jul 22 '11 at 18:50
Yup, I just discovered that myself. Oh well, it was fun finding crazy new uses ofcp
- thanks!
– Eli Heady
Jul 22 '11 at 18:58
dd commit at 2012: git.savannah.gnu.org/cgit/coreutils.git/commit/… "dd: add support for the conv=sparse option" ("(iwrite): Convert a write of a NUL block to a seek if requested.")
– osgx
May 19 '18 at 5:12
As is the case with bhinesley's answer, it would be best to log dd's progress for accurate resuming. If you were to use this approach for both the first run and resumes, and log both parallel dd's independently, then you could know how far into the output to seek. If I have time I'll try to work this up.
– Eli Heady
Jul 22 '11 at 18:48
As is the case with bhinesley's answer, it would be best to log dd's progress for accurate resuming. If you were to use this approach for both the first run and resumes, and log both parallel dd's independently, then you could know how far into the output to seek. If I have time I'll try to work this up.
– Eli Heady
Jul 22 '11 at 18:48
2
2
Thanks for the link to the patch. I was starting to think about programming something like it by myself :-) Sparse files can't be pipped so your code won't work.
– Martin Scharrer
Jul 22 '11 at 18:50
Thanks for the link to the patch. I was starting to think about programming something like it by myself :-) Sparse files can't be pipped so your code won't work.
– Martin Scharrer
Jul 22 '11 at 18:50
Yup, I just discovered that myself. Oh well, it was fun finding crazy new uses of
cp
- thanks!– Eli Heady
Jul 22 '11 at 18:58
Yup, I just discovered that myself. Oh well, it was fun finding crazy new uses of
cp
- thanks!– Eli Heady
Jul 22 '11 at 18:58
dd commit at 2012: git.savannah.gnu.org/cgit/coreutils.git/commit/… "dd: add support for the conv=sparse option" ("(iwrite): Convert a write of a NUL block to a seek if requested.")
– osgx
May 19 '18 at 5:12
dd commit at 2012: git.savannah.gnu.org/cgit/coreutils.git/commit/… "dd: add support for the conv=sparse option" ("(iwrite): Convert a write of a NUL block to a seek if requested.")
– osgx
May 19 '18 at 5:12
add a comment |
Just adding my 2 cents. Another way to create a sparse file from a raw disk is with qemu-img using something like:
qemu-img convert -f raw /dev/sda /tmp/sda.raw
You can use this on a single partition as well. Also, you have the option to convert the raw disk/partition to any other format that qemu-img supports (QCOW2, VHD[x], vmdk, etc)
add a comment |
Just adding my 2 cents. Another way to create a sparse file from a raw disk is with qemu-img using something like:
qemu-img convert -f raw /dev/sda /tmp/sda.raw
You can use this on a single partition as well. Also, you have the option to convert the raw disk/partition to any other format that qemu-img supports (QCOW2, VHD[x], vmdk, etc)
add a comment |
Just adding my 2 cents. Another way to create a sparse file from a raw disk is with qemu-img using something like:
qemu-img convert -f raw /dev/sda /tmp/sda.raw
You can use this on a single partition as well. Also, you have the option to convert the raw disk/partition to any other format that qemu-img supports (QCOW2, VHD[x], vmdk, etc)
Just adding my 2 cents. Another way to create a sparse file from a raw disk is with qemu-img using something like:
qemu-img convert -f raw /dev/sda /tmp/sda.raw
You can use this on a single partition as well. Also, you have the option to convert the raw disk/partition to any other format that qemu-img supports (QCOW2, VHD[x], vmdk, etc)
answered Jan 24 at 9:32
Gabriel SamfiraGabriel Samfira
1133
1133
add a comment |
add a comment |
Note: this doesn't work for the reasons described in the comments, I'm leaving it here for reference.
Monitor the statistics of dd by using kill -USR1:
$ cp --sparse=always <(dd if=/dev/urandom bs=8M)
/mount/external/backup/sda1.raw&
$ watch kill -USR1 `pidof -s /bin/dd`
Resume by using skip/seek:
$ i_bytes= # get from the last dd statistic
$ o_bytes=`du -b /mount/external/backup/sda1.raw | cut -f 1`
$ cp --sparse=always <(dd if=/dev/urandom bs=8M skip=$i_bytes
seek=$o_bytes) /mount/external/backup/sda1.raw&
$ watch kill -USR1 `pidof -s /bin/dd`
Without $i_bytes it would be more difficult to resume. It's probably easiest to log the dd statistics to a file in case the machine crashes or whatever.
The secondcp
will just overwrite the existing file, wouldn't it? I know theskip
and other options ofdd
. The issue is thecp
part.
– Martin Scharrer
Jul 21 '11 at 18:14
Hm, yeah, you're right.
– bhinesley
Jul 21 '11 at 18:18
add a comment |
Note: this doesn't work for the reasons described in the comments, I'm leaving it here for reference.
Monitor the statistics of dd by using kill -USR1:
$ cp --sparse=always <(dd if=/dev/urandom bs=8M)
/mount/external/backup/sda1.raw&
$ watch kill -USR1 `pidof -s /bin/dd`
Resume by using skip/seek:
$ i_bytes= # get from the last dd statistic
$ o_bytes=`du -b /mount/external/backup/sda1.raw | cut -f 1`
$ cp --sparse=always <(dd if=/dev/urandom bs=8M skip=$i_bytes
seek=$o_bytes) /mount/external/backup/sda1.raw&
$ watch kill -USR1 `pidof -s /bin/dd`
Without $i_bytes it would be more difficult to resume. It's probably easiest to log the dd statistics to a file in case the machine crashes or whatever.
The secondcp
will just overwrite the existing file, wouldn't it? I know theskip
and other options ofdd
. The issue is thecp
part.
– Martin Scharrer
Jul 21 '11 at 18:14
Hm, yeah, you're right.
– bhinesley
Jul 21 '11 at 18:18
add a comment |
Note: this doesn't work for the reasons described in the comments, I'm leaving it here for reference.
Monitor the statistics of dd by using kill -USR1:
$ cp --sparse=always <(dd if=/dev/urandom bs=8M)
/mount/external/backup/sda1.raw&
$ watch kill -USR1 `pidof -s /bin/dd`
Resume by using skip/seek:
$ i_bytes= # get from the last dd statistic
$ o_bytes=`du -b /mount/external/backup/sda1.raw | cut -f 1`
$ cp --sparse=always <(dd if=/dev/urandom bs=8M skip=$i_bytes
seek=$o_bytes) /mount/external/backup/sda1.raw&
$ watch kill -USR1 `pidof -s /bin/dd`
Without $i_bytes it would be more difficult to resume. It's probably easiest to log the dd statistics to a file in case the machine crashes or whatever.
Note: this doesn't work for the reasons described in the comments, I'm leaving it here for reference.
Monitor the statistics of dd by using kill -USR1:
$ cp --sparse=always <(dd if=/dev/urandom bs=8M)
/mount/external/backup/sda1.raw&
$ watch kill -USR1 `pidof -s /bin/dd`
Resume by using skip/seek:
$ i_bytes= # get from the last dd statistic
$ o_bytes=`du -b /mount/external/backup/sda1.raw | cut -f 1`
$ cp --sparse=always <(dd if=/dev/urandom bs=8M skip=$i_bytes
seek=$o_bytes) /mount/external/backup/sda1.raw&
$ watch kill -USR1 `pidof -s /bin/dd`
Without $i_bytes it would be more difficult to resume. It's probably easiest to log the dd statistics to a file in case the machine crashes or whatever.
edited Jul 21 '11 at 18:24
answered Jul 21 '11 at 18:10
bhinesleybhinesley
55847
55847
The secondcp
will just overwrite the existing file, wouldn't it? I know theskip
and other options ofdd
. The issue is thecp
part.
– Martin Scharrer
Jul 21 '11 at 18:14
Hm, yeah, you're right.
– bhinesley
Jul 21 '11 at 18:18
add a comment |
The secondcp
will just overwrite the existing file, wouldn't it? I know theskip
and other options ofdd
. The issue is thecp
part.
– Martin Scharrer
Jul 21 '11 at 18:14
Hm, yeah, you're right.
– bhinesley
Jul 21 '11 at 18:18
The second
cp
will just overwrite the existing file, wouldn't it? I know the skip
and other options of dd
. The issue is the cp
part.– Martin Scharrer
Jul 21 '11 at 18:14
The second
cp
will just overwrite the existing file, wouldn't it? I know the skip
and other options of dd
. The issue is the cp
part.– Martin Scharrer
Jul 21 '11 at 18:14
Hm, yeah, you're right.
– bhinesley
Jul 21 '11 at 18:18
Hm, yeah, you're right.
– bhinesley
Jul 21 '11 at 18:18
add a comment |
There are xfsdump and xfsrestore for XFS which has been a native Linux filesystem for quite a long time.
add a comment |
There are xfsdump and xfsrestore for XFS which has been a native Linux filesystem for quite a long time.
add a comment |
There are xfsdump and xfsrestore for XFS which has been a native Linux filesystem for quite a long time.
There are xfsdump and xfsrestore for XFS which has been a native Linux filesystem for quite a long time.
answered Nov 27 '15 at 3:15
Cristian CiupituCristian Ciupitu
2,10911722
2,10911722
add a comment |
add a comment |
Why not simply:
cp --sparse=always /dev/sda1 /mount/external/backup/sda1.raw
add a comment |
Why not simply:
cp --sparse=always /dev/sda1 /mount/external/backup/sda1.raw
add a comment |
Why not simply:
cp --sparse=always /dev/sda1 /mount/external/backup/sda1.raw
Why not simply:
cp --sparse=always /dev/sda1 /mount/external/backup/sda1.raw
answered 4 hours ago
ZazZaz
1,4491213
1,4491213
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f17087%2fclone-whole-partition-or-hard-drive-to-a-sparse-file%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
7
+1 for creative use of
cp
, it never occurred to me that you could sparse-copy a disk image. I always just compressed them if I needed to save space. Now why is that in a question not an answer?– Caleb
Jul 20 '11 at 20:05