stevepedwards.com/DebianAdmin linux mint IT admin tips info

DD and Cloning Windows System Drives

Be careful with the newer  "free Refresh/Install" fix Win10 ISO from MS - it still tries to conceal the wifi-sense section, off the screen bottom - in the custom install section! Devious bastards!

DON'T use the Express option - all defaults are ON.

------------------------------------------------------------------------------

I have had an older SATA caddy that has served me well from years back, so you can use this style along with the prior Post mains powered type to try and clone hard drives provided the one you are copying to is the same size or larger obviously - although you may get away with a smaller drive if there is no data at the end of the last partition and your source drive is defragmented nicely - see the page bottom tests for that success:

Just make sure you copy the right drive to the other!

Mint makes this easy in the GUI, as the mouse hovering tell you the device ID of the Windows drive and blank drive, with their partition sizes and free space:

The Win10 Upgrade drive is /dev/sdd:

The blank drive is the 320GB /dev/sde

The beauty of DD is it can clone it's own linux system drive when running! It doesn't stop at directories like /proc or /sys that stop tools like cp or rsync. So mounted or unmounted drives don't bother it - it just wants an input and output device, set at it's default block size - which is 512B - and other useful things to know:

man dd

ibs=BYTES
read up to BYTES bytes at a time (default: 512)

noerror
continue after read errors

obs=BYTES
write BYTES bytes at a time (default: 512)

Sending a USR1 signal to a running 'dd' process makes it print I/O sta‐
tistics to standard error and then resume copying.

$ dd if=/dev/zero of=/dev/null& pid=$!
$ kill -USR1 $pid; sleep 1; kill $

pid18335302+0 records in 18335302+0 records out 9387674624 bytes
(9.4 GB) copied, 34.6279 seconds, 271 MB/s

Start Cloning...

stevee@T3400 ~ $ sudo dd conv=noerror if=/dev/sdd of=/dev/sde
[sudo] password for stevee:

Unfortunately it gives no feedback until it completes successfully or errors, so you just have to let it go, but the man page shows how you can read progress seen below later.

As the Win10 drive is 80GB in total, there is plenty of space on the 320GB.

DD copies from bit 1 at the start of the MBR (by default but can start or end anywhere you define) right to the last byte of the drive which is why it can clone an exact copy of a drive or any portion of it - an MBR for example - see the man page.

The issues later may be that different drive geometries mess up the exact data block/sector boundaries (why 512B is a generally safe fit default for most file systems), which are usually re-ordered by Windows chkdsk at boot when it finds the problem.

Linux ext4 file systems are journalled so are better at recovering the data order for cloned linux drives at boot in general - but why bother? Just re-install, it's much quicker.

You won't know if it has worked until you put the clone back in the Windows PC the original drive came from and boot it...for this 80GB drive, I'd allow about 3 hours...it's 18.50..

At least the new mains gizmo has a flashing light on data transfer so you know it's doing something...

If you really want to know how far along you are, you can interrupt the terminal process using a neat trick from an old Post/man page:

http://www.stevepedwards.com/DebianAdmin/cool-command-1-dd-progress/

To get a progress report while dd is running, you need to open another virtual terminal, and then send a special USR1 signal to the dd process.

First, find out the process id of the dd process by running the following in the new virtual terminal.

stevee@T3400 ~ $ pgrep -l '^dd$'
4259 dd

In a 2nd terminal send the USR1 signal to the dd process:

stevee@T3400 ~ $ sudo kill -USR1 4259
[sudo] password for stevee:

Note that as soon as the USR1 signal is detected, dd will print out the current statistics to its STDERR in it's original terminal.

29796945+0 records in
29796945+0 records out
15256035840 bytes (15 GB) copied, 1981.41 s, 7.7 MB/s

You may also view a running PID with:

ps -ef | grep if=
root 3479 2949 0 13:42 pts/2 00:00:00 sudo dd conv=noerror if=/dev/sda of=/dev/sdd
root 3480 3479 5 13:42 pts/2 00:11:04 dd conv=noerror if=/dev/sda of=/dev/sdd
stevee 4823 4737 0 17:18 pts/8 00:00:00 grep --colour=auto if=

Because the dd process is relatively resource heavy on a PC doing nothing else, it may show near the top of top when the m or c keys are pressed to show %mem/cpu use:

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
3480 root 20 0 5932 580 428 D 8.0 0.0 11:38.88 dd conv=noerror if=/dev/sda of=/dev/sdd

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
3480 root 20 0 5932 576 424 D 6.0 0.0 11:48.56 dd

Looks like my old caddy is USB1 only - max 12MB/s - as it's only copying at 7.7MB/s

So it has done about 15GB in 33 mins = 30GB/hr - so looking at about 3hrs total...

After reporting the status, dd will resume copying. You can repeat the above kill command any time you want to see the interim statistics. Alternatively, you can use the watch command to execute kill at a set seconds interval.

stevee@T3400 ~ $ sudo watch -n 10 kill -USR1 4259

checking each 1/2 hr would be -n 1800

Ctrl-C to stop the watch or DD commands.

21:35 Finished. 2hrs, 54 mins

156301488+0 records in
156301488+0 records out
80026361856 bytes (80 GB) copied, 10421.5 s, 7.7 MB/s

Windows needs to boot it and run chkdsk now to sort itself out - if possible...so it won't be mountable in Linux in this confused state.

First, Gparted will re-scan all hardware to get a look at it's general state - and it has a check option, but I'm not going to do that with Gparted until Windows has tried to do it first:

At least the system partition shows a boot flag in GP, so a good start...let's try it in the Win PC...

Can you believe it? The disk just died! I'll redo it another day...pisser.

Ok, another 4 hr dd session later, but I have a perfect W10 clone viewed remotely via rdesktop, that booted first time with not even an apparent file system correction! Due no doubt, to me changing the disk to dynamic before I re-cloned - forgot about that...

rdesktop -g 90% dellw7

So can Windows now extend into the full drive size? Yes - despite the warning, it immediately filled up the remaining space:

Can I shrink it back so I have some spare data space? 150GB should be good..

Now the new partition can be formatted and shared.

Seems the way to go here is convert Windows system drives to dynamic disks BEFORE you clone them with DD. Excellent.

So what's the story with Win10 basic system drives for cloning? It appeared to work ok yesterday but the disk failed before I booted it.

I'll try on this 160GB to 160GB layout:

sudo dd if=/dev/sde of=/dev/sdd

8hrs later...doesn't look good initially...but..

153095455232 bytes (153 GB) copied, 27110.2 s, 5.6 MB/s
dd: writing to ‘/dev/sdd’: No space left on device
312581809+0 records in
312581808+0 records out

160041885696 bytes (160 GB) copied, 28419.4 s, 5.6 MB/s

GP reads only an unallocated drive still because the linux partition table is not updated until a reboot.

It was slightly too small by 4GB, though marked at 160GB also, so all you can do is put it in the Win pc and try...

It booted no problem! Didn't need to repair either.

This proves that linux, so GP, doesn't give an accurate state reading of newly resized clones until at least a linux kernel reboot, so a seeming fail here is not necessarily so. The proof is a successful boot to allow Windows to organize the FS.

So, cloning Windows with DD can be with dynamic or basic drives - it makes no odds, as you would expect for byte by byte data transfer.

If there is only empty space at the end of a larger, defrag'd source drive, it will probably still clone ok.

The time taken to clone becomes the drawback over a fresh install as drives may get too big to be worth the wait against whether what is on the drive (special Apps etc.) can be re-installed later, in less time overall with a new Win install - or not at all - maybe due to lost software keys or tech settings that are now unknown and cannot be re-entered manually etc.

 

Comments are closed.

Post Navigation