|
Homepage: webng.com/linuxhelp How To Clone Windows Installations So, that's it, done. Pretty simple, eh? Sure beats the usual CD-installation. Four, or five commands, and voila, a new Windows installation. Couldn't be much easier. In this update, I have simplified the section on cloning NTFS partitions. The new method, is, in fact, the one I first tried. However, some mistake or other, led me to believe that the source and target partitions had to be exactly the same size, which is not true. The old version of the article has been saved, as a lesson on how to use the command fdisk. This article originally derived from an attempt to install Windows XP on an extended partition. I had assumed that this would be just as easy as installing Linux on an extended partition. But, unfortunately, it was not so. I am still not exactly sure why the Windows XP installer fails. Perhaps the installer does not recognize extended partitions of type id=5. I have previously installed Windows 2000 on W95 Ext'd (LBA) partitions, which are type id=f. Perhaps the installer needs a copy of Windows on the first partition. Perhaps the XP installer is a crippled version of the 2000 installer and simply can't install on any extended partition, no matter the type. Who knows? It seems that you need one Windows primary partition (one of the first three partitions) where the Windows boot machinery will be put. As long as one such partition exits (it may be small) Windows can be installed on an extended partition (this info is unchecked). Anyway, this got me to thinking. Clearly, the program dd could be used to copy my existing Windows XP installation to the extended partition. However, it was not clear whether one would be able to get the cloned system to boot. Coincidentally, I had been reading the documentation for the program parted and had noticed that there was a copy option. Fortuitously, at this time, my Windows XP partition was formatted with the FAT32 (vfat) filesystem and parted turned out to be just what was needed. The partition layout was: fdisk -lu
The -u option lists everything in sectors, rather than cylinders. As always, in what follows, it is assumed that you are the root user. I booted, and worked from, the /dev/hda5 partition (SUSE LINUX 10.0) but any Linux partition that will not be changed will do. It is often convenient to boot from a second hard-drive, and make the necessary changes from there. I decided my Gentoo installation on /dev/hda6 would be sacrificed for this experiment and reformatted the partition with the FAT32 filesystem (which may be necessary to coax parted to work). After formatting I tried the parted copy command: mkdosfs -F 32 /dev/hda6 (probably not necessary) parted /dev/hda cp 2 6 Parted finished after about 15 minutes. I mounted /dev/hda6 and checked to see if everything looked OK. It did. I edited the /boot/grub/menu.lst file to tell it to expect Windows on partition 6. After editing, the file looked like: emacs /boot/grub/menu.lst &
On rebooting, I choose the WINDOWS XP/2000 CLONED menu entry and was amazed when Windows booted up. However, something was wrong. Although I could see both drives from Windows Explorer, it seemed that no matter which Windows Grub entry I choose, I always booted the 2nd partition. So, I fired up Google and eventually found this site: http://www.goodells.net/multiboot/ which explains the whole subject well. After, reading what Dan Goodell (the site's author) had to say, I found that my problem was caused by my failure to edit the file C:\boot.ini. So, before you reboot, you need to mount your new Windows partition and edit this file with your favorite text editor: mount /dev/hda6 /mnt emacs /mnt/boot.ini &
You need to change the partition number to reflect the new reality. Since the new copy of Windows was on the 6th partition, I figured that one should change the two 2's to 6's. However, on rebooting, Windows choked and spat out something about not being able to find a file. After a more careful reading of Dan Goodell's work, I found that the numbering follows the partition table order. It starts at one, and extended and empty partition table entries are not counted, so the correct choice was 5, not 6. After changing the 6's to 5's and rebooting, everything worked as it should. reboot So, that's it, done. Pretty simple, eh? Sure beats the usual CD-installation. Four, or five commands, and voila, a new Windows installation. Couldn't be much easier. However, if you used the NTFS filesystem for your XP install, then things are somewhat more difficult. Thankfully, due to information provided by Petr Soucek (petr.soucek@ryston.cz), not too much more difficult. The main problem, is that parted refuses to deal with the situation, claiming: No Implementation: Support for opening ntfs file systems is not implemented yet. Of course, this is a totally bogus claim, as a partition editor like parted works "outside the filesystem". When parted copies a partition it copies the filesystem as well as the files, so it neither needs to read from, nor write to, any filesystem. Basically, parted's copy, is just a sophisticated version of dd. Anyway, the fact that parted refused to function, forced me back to my original idea, which, as it happens, can be made to work as well. Parted does a number of nice things for you when it copies a FAT32 partition. First, it copies the source partition into the target partition, then it extends the image to fill out the whole partition and adjusts the boot sector (the first 512 bytes of the partition) so that it works. With Parted now refusing to do these things for us, we will have to do them by hand. First, check that the target partition (/dev/hda6) is larger than the source partition (/dev/hda2). Then use dd to copy everything into the target partition: dd if=/dev/hda2 of=/dev/hda6 You should be very careful when using the dd command, as a small typo can cause you overwrite a whole partition, or even a whole hard disk. Now you need to expand the filesystem to fill out the partition: ntfsresize -n /dev/hda6 (the -n takes ntfsresize for a trial run) ntfsresize /dev/hda6 (the real thing) ntfsresize is part of the ntfsprogs-1.13.1.tar.gz package. There is an install guide here. Now you need to adjust the partition table: fdisk -u /dev/hda
A few words concerning the above. The text in black bold is user input. The blue text is output from fdisk. The red text is explanatory comment. Note that a Block is just 2 sectors and that a + is half a Block. Now you need to adjust the NT boot sector. echo 24418863|awk '{printf("%c%c%c%c",$1%256,$1/256,$1/65536,$1/16777216)}'|dd bs=1 count=4 seek=28 of=/dev/hda6 In UNIX, long command lines like the above can be broken into smaller lines by adding a \ at the end of the line. The \ has to be the last character on the line. So, the above command can be rewritten, in a more readable fashion, as: echo 24418863 | \ awk '{printf("%c%c%c%c",$1%256,$1/256,$1/65536,$1/16777216)}' | \ dd bs=1 count=4 seek=28 of=/dev/hda6 This strange looking command does the following: Echo feeds the number 24418863 to the stream editor awk, which converts it to a Microsoft "double word". This double word (which is a string of 4 bytes) is then written by the program dd to partition /dev/hda6. The seek=28 tells dd to start writing after skipping the first 28 bytes and bs=1 count=4 tells it to write 4 lots of one byte, i.e., 4 bytes. The number 24418863 is the number of sectors to the start of the 6th partition, /dev/hda6. It has been highlighted in yellow in the output of fdisk -lu at the top of the page. This number has to be "hard coded" into the NT boot sector of the partition, so that Windows knows where to find its files. Since, Microsoft's boot apparatus (for all bootable partitions), usually resides in the first partition, this number is in most cases 63 (since the first partition starts at sector 63). Of course, if you are following this guide, you will need to change the number 24418863 to reflect your situation. Only the number 24418863 and the partition number need to change, the rest of the command stays exactly as is. In case you are interested. This is what the NT boot sector from partition 2 looked like (in a hex-editor). The four bytes that need to be changed are backgrounded in yellow.
00000000 eb 52 90 4e 54 46 53 20 20 20 20 00 02 08 00 00 ëR.NTFS .....
00000010 00 00 00 00 00 f8 00 00 3f 00 ff 00 bb a8 9b 00 .....ø..?.ÿ.»¨..
00000020 00 00 00 00 80 00 80 00 de ba 65 00 00 00 00 00 ........Þºe.....
00000030 00 00 04 00 00 00 00 00 ad 5b 06 00 00 00 00 00 ........[......
00000040 f6 00 00 00 01 00 00 00 86 84 75 70 87 75 70 40 ö.........up.up@
00000050 00 00 00 00 fa 33 c0 8e d0 bc 00 7c fb b8 c0 07 ....ú3À.м.|û¸À.
00000060 8e d8 e8 16 00 b8 00 0d 8e c0 33 db c6 06 0e 00 .Øè..¸...À3ÛÆ...
00000070 10 e8 53 00 68 00 0d 68 6a 02 cb 8a 16 24 00 b4 .èS.h..hj.Ë..$.´
00000080 08 cd 13 73 05 b9 ff ff 8a f1 66 0f b6 c6 40 66 .Í.s.¹ÿÿ.ñf.¶Æ@f
00000090 0f b6 d1 80 e2 3f f7 e2 86 cd c0 ed 06 41 66 0f .¶Ñ.â?÷â.ÍÀí.Af.
000000a0 b7 c9 66 f7 e1 66 a3 20 00 c3 b4 41 bb aa 55 8a ·Éf÷áf£ .ôA»ªU.
000000b0 16 24 00 cd 13 72 0f 81 fb 55 aa 75 09 f6 c1 01 .$.Í.r..ûUªu.öÁ.
000000c0 74 04 fe 06 14 00 c3 66 60 1e 06 66 a1 10 00 66 t.þ...Ãf`..f¡..f
000000d0 03 06 1c 00 66 3b 06 20 00 0f 82 3a 00 1e 66 6a ....f;. ...:..fj
000000e0 00 66 50 06 53 66 68 10 00 01 00 80 3e 14 00 00 .fP.Sfh.....>...
000000f0 0f 85 0c 00 e8 b3 ff 80 3e 14 00 00 0f 84 61 00 ....è³ÿ.>.....a.
00000100 b4 42 8a 16 24 00 16 1f 8b f4 cd 13 66 58 5b 07 ´B..$....ôÍ.fX[.
00000110 66 58 66 58 1f eb 2d 66 33 d2 66 0f b7 0e 18 00 fXfX.ë-f3Òf.·...
00000120 66 f7 f1 fe c2 8a ca 66 8b d0 66 c1 ea 10 f7 36 f÷ñþÂ.Êf.ÐfÁê.÷6
00000130 1a 00 86 d6 8a 16 24 00 8a e8 c0 e4 06 0a cc b8 ...Ö..$..èÀä..̸
00000140 01 02 cd 13 0f 82 19 00 8c c0 05 20 00 8e c0 66 ..Í......À. ..Àf
00000150 ff 06 10 00 ff 0e 0e 00 0f 85 6f ff 07 1f 66 61 ÿ...ÿ.....oÿ..fa
00000160 c3 a0 f8 01 e8 09 00 a0 fb 01 e8 03 00 fb eb fe à ø.è.. û.è..ûëþ
00000170 b4 01 8b f0 ac 3c 00 74 09 b4 0e bb 07 00 cd 10 ´..ð¬<.t.´.»..Í.
00000180 eb f2 c3 0d 0a 41 20 64 69 73 6b 20 72 65 61 64 ëòÃ..A disk read
00000190 20 65 72 72 6f 72 20 6f 63 63 75 72 72 65 64 00 error occurred.
000001a0 0d 0a 4e 54 4c 44 52 20 69 73 20 6d 69 73 73 69 ..NTLDR is missi
000001b0 6e 67 00 0d 0a 4e 54 4c 44 52 20 69 73 20 63 6f ng...NTLDR is co
000001c0 6d 70 72 65 73 73 65 64 00 0d 0a 50 72 65 73 73 mpressed...Press
000001d0 20 43 74 72 6c 2b 41 6c 74 2b 44 65 6c 20 74 6f Ctrl+Alt+Del to
000001e0 20 72 65 73 74 61 72 74 0d 0a 00 00 00 00 00 00 restart........
000001f0 00 00 00 00 00 00 00 00 83 a0 b3 c9 00 00 55 aa ......... ³É..Uª
In the example above the four bytes needed to be changed to 2f 9a 74 01
Now 24418863 = 0x1749a2f in hexadecimal. To obtain the corresponding double word, you write the hexadecimal representation backwards in pairs. This gives you 2f 9a 74 01.0x2f = 00101111, 0x9a = 10011010, 0x74 = 01110100, 0x01 = 00000001. So this is the binary sequence, 00101111100110100111010000000001, that was actually written to the hard disk. Well that's pretty much it. Now, you only need to adjust the grub menu and boot.ini files, as above, reboot, and you are done. In more detail: emacs /boot/grub/menu.lst & (adjust as described above) Now you have two choices, you can mount /dev/hda6 with ntfsmount and make the necessary file changes: ntfsmount /dev/hda6 /mnt emacs /mnt/boot.ini & (adjust as described above) reboot Or, you can boot your original 2000/XP partition and use notepad to make the changes to the boot.ini file of the new partition: Once, these changes are made, everything should work as desired. Cloning partitions has many advantages over an installation: 1) it is much, much quicker, 2) you don't have to reenter those long product keys, and most importantly: 3) you do not have to install all your third party software, drivers, etc, and configure your system once again, as cloning copies a system, as is. In fact, once you have spent the many hours necessary to get a windows system totally installed and configured, you should save a copy of it on a spare partition, just in case you ever need a fully functional system in a hurry. Please add any helpful comments/suggestions here. AS ALWAYS, USE AT OWN RISK. |