Using dd to clone Windows

I’m trying to use dd to clone my Windows partitions from linux. I want to get rid of Windows and put it on another harddrive. Do not want to delete Windows since it is a OEM version.

Anyway the two first partitions on my harddrive belongs to Windows. I have connected a secondary harddrive to linux and executed dd.

username@localhost:~> sudo dd if=/dev/sda1 of=/dev/sdb1 bs=4096 conv=notrunc,noerror
106422+1 records in
106422+1 records out
435907584 bytes (436 MB) copied, 0,958252 s, 455 MB/s

username@localhost:~> sudo dd if=/dev/sda2 of=/dev/sdb2 bs=4096 conv=notrunc,noerror
dd: writing «/dev/sdb2»: No space left on device
894515+0 records in
894514+0 records out
3663929344 bytes (3,7 GB) copied, 8,3846 s, 437 MB/s

The first partition seems to go OK, but for the second it doesn’t. Drive sdb is twice the size of sba1+sda2.
I have even tried to create two partition sdb1 and sdb2 before running dd, but with same result.

So any suggestions?

Some additional information. As you can see the drive sda has my linux partition along with the Windows partition.
I have created /dev/sdb1 and /dev/sdb2 on the drive /dev/sdb with adequate disk space for the cloning.
However /dev/sda1 begins a 63, while my /dev/sdb1 begins at 2048.

Disk /dev/sda: 480.1 GB, 480103981056 bytes
255 heads, 63 sectors/track, 58369 cylinders, total 937703088 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xdac9de00

Device Boot Start End Blocks Id System
/dev/sda1 63 851444 425691 7 HPFS/NTFS/exFAT
/dev/sda2 851445 308118208 153633382 7 HPFS/NTFS/exFAT

/dev/sda3 * 308119552 937701375 314790912 f W95 Ext’d (LBA)
/dev/sda5 308121600 312336383 2107392 82 Linux swap / Solaris
/dev/sda6 312338432 442365951 65013760 83 Linux
/dev/sda7 442368000 937682943 247657472 83 Linux

Disk /dev/sdb: 320.1 GB, 320072933376 bytes
255 heads, 63 sectors/track, 38913 cylinders, total 625142448 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x9a09bb3d

Device Boot Start End Blocks Id System
/dev/sdb1 2048 1124351 561152 7 HPFS/NTFS/exFAT
/dev/sdb2 1124352 625141759 312008704 7 HPFS/NTFS/exFAT

Please post computer text between CODE tags to keep it readable. Use the # button in the toolbar above the post editor.

Any administrator/moderator who could open my post so I could edit it to include CODE tags?

Anyway another update:
I tried both gparted and KDE partitionmanager to copy both partitions over to /dev/sdb, but unsuccessful.

KDE partitionmanager failed when trying to check file system.


Create a new partition table on ‘/dev/sdb’ 
Job: Create new partition table on device ‘/dev/sdb’ 
Create new partition table on device ‘/dev/sdb’: Success
Create a new partition table on ‘/dev/sdb’: Success

Copy partition ‘/dev/sda1’ (415,71 MiB, ntfs) to unallocated space (starting at 31,50 KiB) on ‘/dev/sdb’ and grow it to 423,56 MiB 
Job: Check file system on partition ‘/dev/sda1’ 
Command: ntfsresize -P -i -f -v /dev/sda1 
ntfsresize v2012.1.15 (libntfs-3g)
Device name        : /dev/sda1
NTFS volume version: 3.1
Cluster size       : 4096 bytes
Current volume size: 435905024 bytes (436 MB)
Current device size: 435907584 bytes (436 MB)
Checking for bad sectors ...
Checking filesystem consistency ...
Accounting clusters ...
Space in use       : 28 MB (6.3%)
Collecting resizing constraints ...
Estimating smallest shrunken size supported ...
File feature         Last used at      By inode
$MFT               :        24 MB             0
$MFTMirr           :         1 MB             1
Ordinary           :        28 MB             6
You might resize at 27590656 bytes or 28 MB (freeing 408 MB).
Please make a test run using both the -n and -s options before real resizing! 
Check file system on partition ‘/dev/sda1’: Success

Job: Create new partition ‘Copy of /dev/sdb1’ 
Create new partition ‘/dev/sdb1’: Success

Job: Copy file system on partition ‘/dev/sda1’ to partition ‘/dev/sdb1’ 
Command: ntfsclone -f --overwrite /dev/sdb1 /dev/sda1 
ntfsclone v2012.1.15 (libntfs-3g)
NTFS volume version: 3.1
Cluster size       : 4096 bytes
Current volume size: 435904512 bytes (436 MB)
Current device size: 435907584 bytes (436 MB)
Scanning volume ...
  0.00 percent completed 39.22 percent completed 78.43 percent completed100.00 percent completed
Accounting clusters ...
Space in use       : 28 MB (6.3%)   
Cloning NTFS ...
  1.48 percent completed  2.97 percent completed  4.45 percent completed  5.94 percent completed  7.42 percent completed  8.91 percent completed 10.39 percent completed 11.88 percent completed 13.36 percent completed 14.85 percent completed 16.33 percent completed 17.81 percent completed 19.30 percent completed 20.78 percent completed 22.27 percent completed 23.75 percent completed 25.24 percent completed 26.72 percent completed 28.21 percent completed 29.69 percent completed 31.18 percent completed 32.66 percent completed 34.14 percent completed 35.63 percent completed 37.11 percent completed 38.60 percent completed 40.08 percent completed 41.57 percent completed 43.05 percent completed 44.54 percent completed 46.02 percent completed 47.51 percent completed 48.99 percent completed 50.48 percent completed 51.96 percent completed 53.44 percent completed 54.93 percent completed 56.41 percent completed 57.90 percent completed 59.38 percent completed 60.87 percent completed 62.35 percent completed 63.84 percent completed 65.32 percent completed 66.81 percent completed 68.29 percent completed 69.77 percent completed 71.26 percent completed 72.74 percent completed 74.23 percent completed 75.71 percent completed 77.20 percent completed 78.68 percent completed 80.17 percent completed 81.65 percent completed 83.14 percent completed 84.62 percent completed 86.10 percent completed 87.59 percent completed 89.07 percent completed 90.56 percent completed 92.04 percent completed 93.53 percent completed 95.01 percent completed 96.50 percent completed 97.98 percent completed 99.47 percent completed100.00 percent completed
Syncing ... 

Command: dd of=/dev/sdb1 bs=1 count=8 seek=72 
8+0 records in
8+0 records out
8 bytes (8 B) copied, 4.8516e-05 s, 165 kB/s 

Updating boot sector for NTFS file system on partition ‘/dev/sdb1’. 
Copy file system on partition ‘/dev/sda1’ to partition ‘/dev/sdb1’: Success

Job: Check file system on partition ‘/dev/sdb1’ 
Command: ntfsresize -P -i -f -v /dev/sdb1 
ntfsresize v2012.1.15 (libntfs-3g)
Error reading bootsector: Invalid argument
ERROR(22): Opening '/dev/sdb1' as NTFS failed: Invalid argument
The device '/dev/sdb1' doesn't have a valid NTFS.
Maybe you selected the wrong partition? Or the whole disk instead of a
partition (e.g. /dev/hda, not /dev/hda1)? This error might also occur
if the disk was incorrectly repartitioned (see the ntfsresize FAQ). 
Check file system on partition ‘/dev/sdb1’: Error

Checking target partition ‘/dev/sdb1’ after copy failed. 
Copy partition ‘/dev/sda1’ (415,71 MiB, ntfs) to unallocated space (starting at 31,50 KiB) on ‘/dev/sdb’ and grow it to 423,56 MiB: Error


Useless, the layout is gone and can not be reconstructed by putting CODE tags later. You should copy direct from your terminal in between the tags. Which you managed to do in your last post :slight_smile:

I tried to assess this using your first two posts, but either the clue is not there, or I still am misreading because of the failing columns. Also I see a blank line somewhere where it shouldn’t be.

Now it seems that it is of not much use to ask you to show in one unitnerrupted sweep the fdisk -l and the two dd commands because you already changed the situation by using all sorts of other tools. So I am completely lost on what your present situation is.

On 2013-02-15 15:26, DJViking wrote:
>
> I’m trying to use dd to clone my Windows partitions from linux. I want
> to get rid of Windows and put it on another harddrive. Do not want to
> delete Windows since it is a OEM version.

I would attempt a blunt dd of the entire disk. It will fail at some
point because of the different size, at which point you have to remove
the extra partition entries beyond sdb2.

Why your dd of sda2 fails I can not see. It should work, I believe.


Cheers / Saludos,

Carlos E. R.
(from 12.1 x86_64 “Asparagus” at Telcontar)

hcvv wrote:

>
> I tried to assess this using your first two posts, but either the clue
> is not there, or I still am misreading because of the failing columns.
> Also I see a blank line somewhere where it shouldn’t be.
>
> Now it seems that it is of not much use to ask you to show in one
> unitnerrupted sweep the fdisk -l and the two dd commands because you
> already changed the situation by using all sorts of other tools. So I am
> completely lost on what your present situation is.
>
>
I may be wrong about this but was your b drive partitioned in any way. If I
recall correctly I had much the same problem. If your b drive had only one
partition that occupied the drive dd will copy your partition from a to be
but will not truncate the b drive partition to the size of the partition on
the a drive therefore it doesn’t find any free space on the b drive. You
might try dd if=/dev/sda of=/dev/sdb instead of trying each partition
separately.

What I read from his (distorted) fdisk listing in post #2 is that sdb has two partitions that are both bigger then the partitions with the same sequence number on sda. I might misread as I said earlier, but I do not understand how you see that there are no parttitions at all on sdb. The more so because the dd of sda1 to sdb1 is successfully, thus there must be at least one partition.

Also when there isn’t a partition sdb2 at all there would be an error message from dd that /dev/sdb2 doesnot exist, which is not the case. tehre is even a lot of blocks copied.

Also dd does not “truncate” partitions. dd simply copies blocks from the input file to output file. It does not even have any real knowledge about partitions. When there are no more blocks to copy (End-of-file on input from the kernel) it stops and does not do anything whether there are more blocks available out the output file or not. When, during writing, it gets an End-of file from the kernel it then says: No space left.

(BTW it is not my “b drive”, but the OP’s disk).

Will try cloning the entrie sda drive on monday when I get back to work. I hate unfinished work before weekend.
Anyway when it will fail due to lack of space will not the sdb drive have a incomplete partition table?

Since linux had problems creating the sdb drive I could perhaps try create the sdb1 and sdb2 drive formatted in NTFS within Windows before I try to clone it.

The reason fdisk -l showed 2 partitions on /dev/sdb is because I created them before I preceded with the cloning with the same size as the /dev/sda partitions I was trying to clone. As stated I have tried the cloning with or without partitions on /dev/sdb. That time I tried without partitions and the first clone worked without problems there was none on the receiving end.

Trying to copy the whole disk and see how it does is not a bad advice given above. But be prepared for the same error message because disk sdb is smaller then sda.

It will have exactly the same partition table. You copied is with dd (do you have any idea what dd is supposed to do?). That will mean that sdb is not realy usable before you used e.g. fdisk to remove the not need partitions db3 and upwards (as Carlos clearly explained in his post).

That is nonsense.

That is clear to me. But they are NOT of the same size (both are a bit larger then need I guess). And what you planned to do is correct:
. create on another disk two partitions with the same size (or larger, but same size is best);
. dd both partitions.

But I am a bit at the end as long as you do not post in one sweep the complete terminal session using

fdisk -l
dd if=/dev/sda1 of=/dev/sdb1 bs=4096
dd if=/dev/sda2 of=/dev/sdb2 bs=4096

I want a complete, unabridged, not thinkered with and readable listing of what happens. As Carlos once said: we are non-=believers, we want computer facts. This is the last time I ask.

Just a thought…
Depends on what your personal objective is -

Although I’m sure anyone following this thread woudl be interested why you’re encountering difficulties, if your objective is to just get the job done instead of how it’s done, there are many tools out there which will clone/copy the partitions and content for you (eg Gparted, Clonezilla, more) which are easy to use and might even do a theoretically better job (eg checksum and other verifications) than dd.

But, if you really want to learn how dd works, it’d certainly be useful to understand why you’re seeing your problem and overcome it.

TSU

On 2013-02-15 20:56, DJViking wrote:
>
> Will try cloning the entrie sda drive on monday when I get back to work.
> I hate unfinished work before weekend.
> Anyway when it will fail due to lack of space will not the sdb drive
> have a incomplete partition table?

No, the table will be complete, the table is at the start of the disk.
Do you really know what ‘dd’ does?

Also, the contents of the first and second partitions will be correct
and the same. The content beyond that will be truncated at some point,
but we don’t care about that. You will have to use a partitioner and
delete partition 3, 4, etc.

It is also possible to concoct a dd command that copies sda into sdb
stopping at a point just beyond sda2 and save time, but I feel lazy to
try it just now. :slight_smile:

> Since linux had problems creating the sdb drive I could perhaps try
> create the sdb1 and sdb2 drive formatted in NTFS within Windows before I
> try to clone it.

Irrelevant, format is destroyed. Again, do you really know what ‘dd’ does?

Also, please repeat your original session and post the results inside
code tags. What you posted is contaminated and distorted, specially for
those readers using hhtp and not nntp like me.


Cheers / Saludos,

Carlos E. R.
(from 12.1 x86_64 “Asparagus” at Telcontar)

Will post the complete output from fdisk and dd on monday, unless I get in the mood to go back to work tomorrow.

Anyway, used dd and dd_rescue before, but only in the capacity to put OpenSuse DVD ISO on a USB stick. Knowing just that it copies data from one drive/file to another, perhaps I’ll read up on dd this weekend.

On 2013-02-15 22:26, DJViking wrote:
>
> Will post the complete output from fdisk and dd on monday, unless I get
> in the mood to go back to work tomorrow.
>
> Anyway, used dd and dd_rescue before, but only in the capacity to put
> OpenSuse DVD ISO on a USB stick. Knowing just that it copies data from
> one drive/file to another, perhaps I’ll read up on dd this weekend.

It is really simple, it works “dumb”. It just copies bytes one by one
from input file to output file. If the files are “disks”, it copies from
the first byte of the disk to the last, be it boot sector, partition,
empty useless space… it copies everything without thinking, to the
destination. Thus:


dd if=/dev/sda of=/dev/sdb

clones the disks exactly equal byte by byte. If the destination is
smaller and will not fit, it will simply copy till the byte that fills
the destination.

It does not clever things like resizing partitions, etc.

And that makes it a very powerful tool.


Cheers / Saludos,

Carlos E. R.
(from 12.1 x86_64 “Asparagus” at Telcontar)

On Fri, 15 Feb 2013 14:26:01 +0000, DJViking wrote:

> I’m trying to use dd to clone my Windows partitions from linux. I want
> to get rid of Windows and put it on another harddrive. Do not want to
> delete Windows since it is a OEM version.
>
> Anyway the two first partitions on my harddrive belongs to Windows. I
> have connected a secondary harddrive to linux and executed dd.

I would use something like Clonezilla (indeed, I have) rather than dd.
dd will give you a sector-by-sector image, which can be useful, but is
essentially an “all or nothing” restore option.

If you needed to restore the OEM installation for some reason, you’d be
wiping out the entire hard drive. Using a better tool will make for a
smaller image and will let you be more selective in your restore if you
need to be.

Jim


Jim Henderson
openSUSE Forums Administrator
Forum Use Terms & Conditions at http://tinyurl.com/openSUSE-T-C

I can now confirm that /dev/sda1 has been successfully cloned to /dev/sdb1. Although the size of /dev/sdb1 is a little more than /dev/sda1, that should not be any problem.

Output from fdisk -l


Disk /dev/sda: 480.1 GB, 480103981056 bytes
255 heads, 63 sectors/track, 58369 cylinders, total 937703088 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xdac9de00

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1              63      851444      425691    7  HPFS/NTFS/exFAT
/dev/sda2          851445   308118208   153633382    7  HPFS/NTFS/exFAT
/dev/sda3   *   308119552   937701375   314790912    f  W95 Ext'd (LBA)
/dev/sda5       308121600   312336383     2107392   82  Linux swap / Solaris
/dev/sda6       312338432   442365951    65013760   83  Linux
/dev/sda7       442368000   937682943   247657472   83  Linux

Disk /dev/sdb: 320.1 GB, 320072933376 bytes
255 heads, 63 sectors/track, 38913 cylinders, total 625142448 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000b2459

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1              63      867509      433723+   7  HPFS/NTFS/exFAT
/dev/sdb2          867510   625137344   312134917+   7  HPFS/NTFS/exFAT

Output from dd


username@pluto:~> sudo dd if=/dev/sda2 of=/dev/sdb2 bs=2M conv=notrunc,noerror
dd: writing «/dev/sdb2»: No space left on device
1942+0 records in
1941+0 records out
4072189952 bytes (4,1 GB) copied, 10,7451 s, 379 MB/s

Last week when I ran the dd command, it would only copy 3.7GB and now it copied 4.1GB.

Output from dd without any extra options


username@pluto:~> sudo dd if=/dev/sda2 of=/dev/sdb2
dd: writing to «/dev/sdb2»: No space left on device
7953545+0 records in
7953544+0 records out
4072214528 bytes (4,1 GB) copied, 10,9205 s, 373 MB/s

To recap: you have two partitions on sdb that are both a little bit larger then needed.

Copying sda1 to sdb1 allways is flawless.

Copying sda2 to sdb2 stops every time at a different point with apparently dd getting and End-of-File indication from the kernel. Now this is strange (as it was from the beginning and you being baffledd about it is no wonder). I would interprete it as a hardware problem when it would have been on the same spot every time. But it isn’t. It may still be a hardware problem, but more difficult to pin down. As every error that comes and goes or, like here, jumps around is very difficult to pin down.

I think we could try several approaches here, but I am not sure which one will lead us along the shortest way to a solution.

  1. run a disk check program (preferable the manufacturer’s one) on the disk to see if it is broken.

  2. repartition the diks in a way that you have only one parttiotion (that will then be sdb1) large enough to accomodate sda2 and then dd sda2 to sdb1 to see if we get the error again. I am not sure if it will brings us much as the “new” sdb1 will partly overlap with the “old” sdb2 and thus the error could be in the overlap. But maybe we can then prove that it is possible to do the copy (albeith to another place).

  3. that brings another test to my mind. We could copy sda2 into the dustbin to prove that the problem is not on the input side:

dd if=/dev/sda2 of=/dev/null

Other suggestions from others following this thread are of course very welcome.

EDIT: I am also wondering why dd every time after the error message and after telling it copied “only” so many records says:

4072214528 bytes (4,1 GB) copied, 10,9205 s, 373 MB/s

as if all was done.
BTW did you try to check for the contents of sdb2 after such an aborted dd?

The content of /dev/sdb2 was corrupt. I tried to mount it but unsuccessful.

I am now running the following command
sudo dd if=/dev/sda of=/dev/sdb

It has been running for 20 minutes and still running without any errors so far. Overall size of /dev/sda is much larger than /dev/sdb, but not all space is used on /dev/sda. The totalt amount of used space on /dev/sda is less than the free space on /dev/sdb, so perhaps dd will succeed without any insufficient space error (assuming my assumption about dd that it only copies used data).

Edit: I wanted to run that with dd_rescue instead of dd. I do not like the lack of verbosity/progress information with dd. However dd_rescue returned an error that it could not find /dev/sda, but that file clearly did exist.

As far as I know it will copy everything, so you will probably have out of space errors.