Solved

Trying to copy windows system partition and boot partition from hdd to ssd using Linux

Posted on 2015-01-02
11
489 Views
Last Modified: 2015-01-03
I am trying to copy windows system partition and boot partition from hdd to ssd using Linux.
I used this guide as a base: http://www.nilbus.com/linux/disk-copy.php

Seems like everything went OK, but computer I put the SSD in wont boot from the ssd.
Here is my whole progress and descriptions of what I was doing, please read through it and check where I went wrong(mainly pasting info from  the disks in question, /dev/sdb is the new ssd disk and /dev/sdc is the disk I am copying from):

:~# fdisk -l

Disk /dev/sda: 32.0 GB, 32017047552 bytes
255 heads, 63 sectors/track, 3892 cylinders, total 62533296 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: 0x0001d924

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048    54149119    27073536   83  Linux
/dev/sda2        54151166    62531583     4190209    5  Extended
/dev/sda5        54151168    62531583     4190208   82  Linux swap / Solaris

Disk /dev/sdb: 64.0 GB, 64023257088 bytes
255 heads, 63 sectors/track, 7783 cylinders, total 125045424 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: 0x00000000

Disk /dev/sdb doesn't contain a valid partition table

Disk /dev/sdc: 1000.2 GB, 1000204886016 bytes
255 heads, 63 sectors/track, 121601 cylinders, total 1953525168 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: 0x539a49d7

   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1            2048    41945087    20971520   27  Hidden NTFS WinRE
/dev/sdc2   *    41945088    42149887      102400    7  HPFS/NTFS/exFAT
/dev/sdc3        42149888   148645887    53248000    7  HPFS/NTFS/exFAT


 I am not using the -u switch to fdisk, displaying sectors are default now. From above we can see three partitions on the source disk. The first partition is a hidden backup partition for system restore of the operating system that came with the computer. I am not interested in that partition and will therefore not take that with me. The second partition is a ntfs boot partition as of what I have understood, and the third one is the data partition that I need and contains the OS. I need both the second and the third partition. Before I create the partitions on the destination disks, I need to know the sector sizes of these partitions. I can't just copy the start and end sectors from the output above, since the destination disk is alot smaller then the source disk and we are also making the second partition on the source disk the first one on the destination disk, and also letting it start at sector 2048.

The amount of sectors are:
/dev/sdc2       42149887 - 41945088 = 204799
/dev/sdc3       148645887 - 42149888 = 106495999

The destination disk partitions start and end sectors are therefore:
Device Boot      Start         End
/dev/sdb1       2048      206847 (2048 + 204799)
/dev/sdc2       206848      106702847 (206848 + 106495999)

~# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x9126b635.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

Command (m for help): p

Disk /dev/sdb: 64.0 GB, 64023257088 bytes
255 heads, 63 sectors/track, 7783 cylinders, total 125045424 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: 0x9126b635

   Device Boot      Start         End      Blocks   Id  System

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-125045423, default 2048): 2048
Last sector, +sectors or +size{K,M,G} (2048-125045423, default 125045423): 206847

Command (m for help): n
Partition type:
   p   primary (1 primary, 0 extended, 3 free)
   e   extended
Select (default p): p
Partition number (1-4, default 2): 2
First sector (206848-125045423, default 206848): 206848
Last sector, +sectors or +size{K,M,G} (206848-125045423, default 125045423): 106702847

Notice that we are not changing units to sectors as in the guide, this is now default in fdisk.

Command (m for help): a  
Partition number (1-4): 1

Command (m for help): t
Partition number (1-4): 1
Hex code (type L to list codes): 7
Changed system type of partition 1 to 7 (HPFS/NTFS/exFAT)

Command (m for help): t
Partition number (1-4): 2
Hex code (type L to list codes): 7
Changed system type of partition 2 to 7 (HPFS/NTFS/exFAT)


Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

# fdisk -l /dev/sdb

Disk /dev/sdb: 64.0 GB, 64023257088 bytes
255 heads, 63 sectors/track, 7783 cylinders, total 125045424 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: 0x539a49d7

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1   *        2048      206847      102400    7  HPFS/NTFS/exFAT
/dev/sdb2          206848   106702847    53248000    7  HPFS/NTFS/exFAT


For the new disk to boot, I must copy the boot code from the Master Boot Record (MBR) to the new disk.

# dd if=/dev/sdc of=/dev/sdb bs=446 count=1
1+0 records in
1+0 records out
446 bytes (446 B) copied, 0,0364022 s, 12,3 kB/s

Now I want to copy the ntfs partition content from the source disk(/dev/sdc) to the destination disk(/dev/sdb):

# ntfsclone --overwrite /dev/sdb1 /dev/sdc2
ntfsclone v2013.1.13AR.1 (libntfs-3g)
NTFS volume version: 3.1
Cluster size       : 4096 bytes
Current volume size: 104853504 bytes (105 MB)
Current device size: 104857600 bytes (105 MB)
Scanning volume ...
100.00 percent completed
Accounting clusters ...
Space in use       : 27 MB (25,4%)  
Cloning NTFS ...
100.00 percent completed
Syncing ...

# ntfsclone --overwrite /dev/sdb2 /dev/sdc3
ntfsclone v2013.1.13AR.1 (libntfs-3g)
NTFS volume version: 3.1
Cluster size       : 4096 bytes
Current volume size: 54525947904 bytes (54526 MB)
Current device size: 54525952000 bytes (54526 MB)
Scanning volume ...
100.00 percent completed
Accounting clusters ...
Space in use       : 24872 MB (45,6%)  
Cloning NTFS ...
100.00 percent completed
Syncing ...

I then tried to boot from the SSD and all I get is a black screen with a blinking underscore in the upper left corner.
I then retried the following:

# ntfsclone --overwrite /dev/sdb1 /dev/sdc2
# dd if=/dev/sdc of=/dev/sdb bs=446 count=1

Then I tried to boot from the disk again(after moving it back to the computer that the OS was originally installed on ofcourse), but this failed with a black screen with a blinking underscore in the upper left corner.
0
Comment
Question by:itnifl
  • 4
  • 4
  • 2
  • +1
11 Comments
 
LVL 61

Expert Comment

by:gheist
ID: 40528169
No need to partition.
Check dmesg which disk is which and:

from X to Y, all partitions included.
dd if=/dev/sdX of=/dev/sdY bs=4k conv=noerror,notunc

And 1TB of data does not fit in 32GB.
0
 
LVL 2

Author Comment

by:itnifl
ID: 40528222
Hello Gheist and thank you for your comment.
There is no doubt which disk is which. If you read the start of my endeavour, you will see the following as a part of the output from fdisk -l initially:
Disk /dev/sdb: 64.0 GB, 64023257088 bytes
255 heads, 63 sectors/track, 7783 cylinders, total 125045424 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: 0x00000000

Disk /dev/sdb doesn't contain a valid partition table

This disk has no partitions, it is empty. This is the new ssd disk I want to transfer my partitions to. My destination disk.

Also you will see that /dev/sdc has three partitions, one hidden and two ntfs partitions. That is the only disk with windows file system. So this is my source disk.

I have not made an attempt to fit 1 TB into a 32GB disk. The 32GB disk is /dev/sda, which is neither the source nor destination disk. The size of the disk is also unrelevant, it is the size of the partitions going to fit on the disk that is relevant.

As you can see further down from ntfsclone:
Current volume size: 104853504 bytes (105 MB)
Current device size: 104857600 bytes (105 MB)

And:
Current volume size: 54525947904 bytes (54526 MB)
Current device size: 54525952000 bytes (54526 MB)

The partitions I am reying to clone are 105 MB and 54526 MB, and they will both fit on the destination disk which is 64 GB.

After creating the partitions that I need on my new drive (/dev/sdb) and that I am going to clone, i veryfy the setup with fdisk -l:
# fdisk -l /dev/sdb

Disk /dev/sdb: 64.0 GB, 64023257088 bytes
255 heads, 63 sectors/track, 7783 cylinders, total 125045424 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: 0x539a49d7

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1   *        2048      206847      102400    7  HPFS/NTFS/exFAT
/dev/sdb2          206848   106702847    53248000    7  HPFS/NTFS/exFAT

This is the exact same amount of blocks on each partition in question as there was on /dev/sdc2 and /dev/sdc3. I have also checked and verified that the sizes are the same.

Please read through the information I have posted carefully. It is if most importance if we are to be able to analyze this. I have taken carefulness in posting all the information in all the steps I have made. Please take care to read it. Otherwise we will only be guessing.
0
 
LVL 61

Expert Comment

by:gheist
ID: 40528262
Windows bootloader will not boot from foreign partitions. You need to clone entire disk, sorry.
0
 
LVL 2

Author Comment

by:itnifl
ID: 40528837
What is your definition of foreign partitions?
I have used the mentioned guide before (http://www.nilbus.com/linux/disk-copy.php), but then I had only two partitions to clone  instead of three. I cloned the boot partition and the OS partition, also the boot loader. That worked fine and I could boot.

This time there is a hidden partition that is the first partition, the boot partition is the second one and the OS partition is the third one. I am guessing the boot loader is looking for the second and third partitions to boot from, while on the new disk I have not included the hidden partition, so there is different content in its second partition and there is no third partition.

I am hoping maybe I could find a way to edit the boot loader and see if this is true.
0
 
LVL 61

Expert Comment

by:gheist
ID: 40529004
This time you dont have space for all of them.
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 18

Accepted Solution

by:
TobiasHolm earned 200 total points
ID: 40529016
Hi!

You have to rebuild the BCD after cloning.

REPAIR W7 BOOT AFTER DD/GHOST/CLONEZILLA CLONE:
- Boot Win7 from a USB-stick or DVD.
- Do NOT do automatic repair!
- Start command prompt.
- Change directory (CD) to USB folder \Boot
- Run: bootrec /RebuildBcd
  Select: [A] All
- Shutdown, remove USB or DVD, test
0
 
LVL 46

Assisted Solution

by:noxcho
noxcho earned 300 total points
ID: 40529022
You can make your task very simple and easy if you perform the cloning with Paragon Migrate OS to SSD. In few clicks it will move the OS partition and correlating boot partition to SSD. Also the partitions will be aligned properly.
0
 
LVL 2

Author Comment

by:itnifl
ID: 40529230
Thanks for comments. Here is how it went:
1. I booted from the Windows 7 installation DVD and chose the menu item "Repair my computer" in order to reach the command prompt. I don't actually have to repair it, like Tobias Holm says I should not, but I accidentally did.
2. I then rebooted and went into the same menu, started the command prompt and ran bootrec /RebuildBcd. Bootrec didn't find any windows 7 installation, even though the menu listing right after the  "Repair my computer" did.
3. I then decided to clone the partitions again. This time the destination disk got 3 partitions instead of 2, but the first one just a bogus empty partition in case the number of partitions played a role for the boot manager.
4. After I was done I inserted the disk in the computer that I was going to boot from it, and got the message that there was a boot error/disk read error. I then booted into the Windows 7 DVD and correctly entered the command prompt.
5. I ran bootrec /RebuildBcd and bootrec told me it found one Windows partition with D:\Windows. I chose A like Tobias Holm suggested, and rebooted. But still I received the error that there was a boot error/disk read error.

So I gave this up. My daughter is getting her SSD with Ubuntu, I am not bothering with this Windows stuff anymore.

I did manage to clone my wifes hdd to ssd and she was using Windows 7, but the partition setup was different. The boot partition and the OS partitions were the two first partitions. The third partition was a ntfs data partition and I could without problem not include it in the process. This time the boot partition and OS partition are the second and third partitions, and somehow that is messing things up for the boot manager or boot loader or something.

noxcho: I am sure you are right, I just wanted to master it the hard and nerdy way :)
0
 
LVL 46

Assisted Solution

by:noxcho
noxcho earned 300 total points
ID: 40529340
Yes, if you want to play a nerd and have lots of nerves to spend then you were on right track. But with Migrate OS to SSD is really easy. Itntakes care of everything itself.
0
 
LVL 2

Author Closing Comment

by:itnifl
ID: 40529408
Thanks for all good suggestion. Trying to award points fairly here.
I think we touched the right possible solutions for doing it the way I was wanting to do it, and the way I was most interested in getting it done (for the purpose of the challenge). Alternative suggestions are also viable solutions.
0
 
LVL 61

Expert Comment

by:gheist
ID: 40529424
Hidden partition is OEM windows reinstall partition.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
Linux users are sometimes dumbfounded by the severe lack of documentation on a topic. Sometimes, the documentation is copious, but other times, you end up with some obscure "it varies depending on your distribution" over and over when searching for …
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now