partition cloning question

Topics about disk partitioning (fdisk, parted, gparted, partimage), Volumes Management (lvm, evms, dmraid), Storage, file systems, ...
BabaG
Posts: 7
Joined: 16 Mar 2016, 17:42

partition cloning question

Postby BabaG » 16 Mar 2016, 18:05

i have a system disk i want to clone before upgrading to w10. the disk is in a hackintosh box and contains several partitions:

osx
user home for osx
w7
user home for w7

i've been using this system for a couple of years now and don't remember exactly how everything was set up originally. i've followed an online tutorial in the past on simpler systems and had no problem cloning a partition or disk:

https://www.youtube.com/watch?v=gh6cnP4rP7Y

in this case i felt i should ask first regarding the sizes of various parameters. can i use default settings for both systems (osx ans w7) or do i need to find out how each is set up and enter specific parameters for each? i'm thinking specifically about things like:

block size
bitmap size
bytes per sector
sectors per cluster
file record size

per the tutorial, i also have copied the mbr using bs=512. also not sure if that is always going to be appropriate or if things may be different in a different system. fwiw, i'm wanting to clone a 250gb ssd to a 500gb ssd.

thanks for any clarification on these questions,
BabaG

vanepp
Posts: 85
Joined: 22 Jun 2012, 02:24

Re: partition cloning question

Postby vanepp » 17 Mar 2016, 01:01

Probably the first thing you want to do is run either parted (or startx and run gparted which is the graphical version) to see what your
partition table looks like now and to see if it is msdos (in which case a dd if=/dev/sdx of=filename bs=512 count=64 will back it up
to filename if you replace /dev/sdx with the appropriate drive such as /dev/sda) or is gpt in which case you need to use sgdisk as
gpt is more complex than the old msdos format. I don't know anything about OS X, so I can't offer help there but Win7 has several
options with booting from the Win7 partition being bootable, to a separate boot partition to uefi boot with a fat32 boot partition and
msft key file system (which needs to be backed up with dd). The parted/gparted should tell you what you have. Of note is that (at
least in my experience) Win10 always uses a separate boot partition and will create one if the Win7 install is itself bootable. For fat
or ntfs file systems partcline or ntfsclone (which is what I usually use) will figure out the necessary parameters for itself.

Peter Van Epp

BabaG
Posts: 7
Joined: 16 Mar 2016, 17:42

Re: partition cloning question

Postby BabaG » 22 Mar 2016, 01:58

here's the output from fdisk -l:

Disk /dev/sdb: 232.9 GiB, 250059350016 bytes, 488397168 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
Disklabel type: gpt
Disk identifier: 04CCEE4A-C188-4C39-857C-F3096DF46685

Device Start End Sectors Size Type
/dev/sdb1 40 409639 409600 200M EFI System
/dev/sdb2 409640 244608223 244198584 116.5G Apple HFS/HFS+
/dev/sdb3 244871168 488396799 243525632 116.1G Microsoft basic data


there's a gap between sdb2 and sdb3. that seems to be something the apple bootcamp system likes: a certain amount of space between the apple system and another os.

thanks,
BabaG

vanepp
Posts: 85
Joined: 22 Jun 2012, 02:24

Re: partition cloning question

Postby vanepp » 22 Mar 2016, 04:05

Your disk is indeed gpt/uefi so you need to use sgdisk to backup the partition table. A dd of the first 64 sectors won't back up the alternate
partition table at the end of the disk (experience speaking :-)).

sgdisk -b filename.gpt /dev/sdb

will back up the partition table to filename.gpt

and
sgdisk -l filename.gpt /dev/sdb

will restore it.

I expect that sdb1 is a fat32 file system so partclone.fat as in

partclone.fat -c -s /dev/sdb1 -O filename

will back it up (getting only the used blocks) and

partclone.restore -s filename -O /dev/sdb1

will restore it.

Likely

dd if=/dev/sdb2 of=filename.mac bs=1M

should back the Mac partition up (although as noted I've never done that before) and

dd if=filename.mac of=/dev/sdb2 bs=1M

should restore it (the bs=1M may make it somewhat faster or may not).

I'd guess that sdb3 is ntfs and thus

ntfsclone --save-image /dev/sdb3 -O filename.img

should back it up and

ntfsclone --restore-image filename.img -O /dev/sdb3

will restore it. However the blank space between sdb2 and sdb3 may be a problem. None of the above will back that up and Win10 may well
choose to use it as "free space" if it wants to create a boot partition (it really shouldn't if since there is already an uefi boot partition, but
better safe than sorry!). I'd suggest you may want to dd the "empty space" to a file so you can restore it if you need to by something like

dd if=/dev/sdb of=filename.blank skip=244608223 count=262945

which should (note that I haven't tried it :-) ) copy the blank space and

dd if=filename.blank of =/dev/sdb seek=244608223

should restore it (note you want to do this first in the restore and then do the real file system restores in case this overwrites something
in the file system partitions!). As well note you want to leave the default 512 byte BS setting on DD as the seeks and skips are in BS units
and want to be 512 bytes in this case.
Hope this helps and good luck!

Peter Van Epp

BabaG
Posts: 7
Joined: 16 Mar 2016, 17:42

Re: partition cloning question

Postby BabaG » 22 Mar 2016, 16:40

thanks, peter! lots to chew on here. start of a busy day today so i'll look over this in more detail later but seems like enough to go ahead with a test. what i'm basically trying to do is clone my complicated drive to a larger one so i can try the w10 upgrade without jeopardizing the original: i'll clone the original and then upgrade the clone. looking forward to trying.

thanks again,
BabaG

vanepp
Posts: 85
Joined: 22 Jun 2012, 02:24

Re: partition cloning question

Postby vanepp » 22 Mar 2016, 18:38

Good plan :-) a new disk makes life easier and much safer. Note (as you may already know) that Windows will object and may decide it is not
authentic if too much changes though. Only the disk I don't think is a problem, changing the entire machine probably would be. I do this on identical disks (same model, I have hot swap carrierless removable disk containers on most of my machines). Windows used to (a long time ago though :-)) be sometimes unhappy about underlying geometry changes. With LBA that shouldn't really be a problem anymore but this is Windows. In any case it won't hurt to try it at most it won't work and you will need to try something else. Good luck!

Peter Van Epp

BabaG
Posts: 7
Joined: 16 Mar 2016, 17:42

Re: partition cloning question

Postby BabaG » 23 Mar 2016, 17:18

hmmm. how old are the programs on systemrescuecd? i was able to backup using the steps detailed above but have not yet tried a restore. wanted to do some further tests.

i see that partclone supports hfs+ but got an error when trying to use it here. partimage, i think, also is supposed to support hfs+ now. will give that a try but, since a forum search for hfs turned up posts from 7 or 8 years ago, i'm getting the impression that these current, hfs-supporting, programs are not up to date on the cd. is that right?

edit:
yeah. just tried partimage and it says hfs is not supported.
/edit

also, is there a way to tell ntfsclone a specific sector to restore to?

thanks and continuing to test,
BabaG

vanepp
Posts: 85
Joined: 22 Jun 2012, 02:24

Re: partition cloning question

Postby vanepp » 23 Mar 2016, 17:45

As noted I don't have any Macs so can't provide advise on hfs+ support. Partimage is no longer developed as far as I know so its support will be old I expect.
Partclone is still developed and should be the better bet if it supports hfs+. If neither work correctly a dd of the entire hfs+ partition should work (just not be as efficient because it copies all sectors not only those in use). Perhaps someone with experience with Macs will chime in with a better suggestion if you are lucky! Ntfsclone will only restore to the partition specified, you would need to use parted of gparted (and X) or possibly fdisk (I've not used fdisk before) to adjust the partition that you are restoring to to start on the sector boundary that you want. gparted can also increase (and possibly reduce) the size of an ntfs partition after it is restored if you want to change the partition sizes. It is possible to restore a ntfs partition with partclone to a larger partition (the initial restore will only use the amount of space in the original partition) and then use gparted to increase the size of the partition to use the new space.

Peter Van Epp

BabaG
Posts: 7
Joined: 16 Mar 2016, 17:42

Re: partition cloning question

Postby BabaG » 27 Mar 2016, 18:24

thanks for all your help on this, vanepp.

i've been able to successfully clone using this as well as other methods (clonezilla) but am always running up against the same wall. i seem only to be able to duplicate my existing disk exactly, which does not allow me to take advantage of the new, larger hard drive.

i currently have a 250gb drive, divided in half between osx and windows. that's roughly 120gb each after formatting etc. the new drive is 500gb and i'd like to be able to set it up as ~200gb for osx and ~250gb for windows. i've not been able to do any of that so far. some, or all, of the copy drive always becomes unbootable. if i move the windows partition, windows becomes unbootable. i can enlarge the osx partition then but i lose windows. if i reclone it to place it after the enlarged osx partition, it is unrecoverably (as far as i know) unbootable. if i leave the windows partition in place, i can enlarge it to use the empty space of the drive but, while that works, it leaves me unable to give osx any more space.

do you have any info on how to move a windows partition without having it become unbootable? or, maybe, how to recover its bootability after moving. seems like i've tried about a million different things but none have worked. seems like there should be a more flexible way to move partitions. i just can't seem to find it. makes me wish i could use linux for my system. i'm sure this is all relatively trivial there.

thanks again and happy easter,
BabaG

vanepp
Posts: 85
Joined: 22 Jun 2012, 02:24

Re: partition cloning question

Postby vanepp » 27 Mar 2016, 19:54

Unfortunatly the only way I've ever managed to move (as opposed to increase the size of) a Windows partition is to reinstall from scratch. Windows is
basically brain dead around that issue :-). You could allocate the extra space as a D: drive in Windows and at least be able to use the space.

Peter Van Epp

BabaG
Posts: 7
Joined: 16 Mar 2016, 17:42

Re: partition cloning question

Postby BabaG » 30 Mar 2016, 17:51

thanks, vanepp. i finally got the system running. it's not an ideal solution but, for now, it's working. will watch it for a while before i call it finished, though.

i'd been using clonezilla as an all-in-one method of getting all of my partitions and data over to the new drive. the idea was to get them there, then move them around. the suggestions here seemed a bit more cumbersome as they are discrete operations. someone on another board suggested using imaging rather than cloning, something i was gradually coming 'round to myself. that's what brought me back to these solutions and that's what worked, though, it's been a pretty rocky road. here's how the process went:

i started with trying to pre-partition the drive to the sizes i wanted. for that i used gparted. then i restored an image of the windows partition to partition 3. it had been on partition 3 on the original drive but at roughly 120gb into the drive. the new partition has it at about 200gb in.

i could never get that installation working so i went back to the w7 install disk to try repairs. none worked. then i tried a fresh install, thinking i would let windows take over. i started the install but cancelled after the formatting. that may have been what worked. it seems to have used my partitions but applied some of its own secret sauce somewhere.

i reinstalled the image, just as i had before, and went back to the w7 install disk to try to repair the installation, assuming the boot partition and folders would need work. that took many rounds of, sometimes contradictory, info and repair. sometimes the repair would find the installation and report it as 120gb (the original partition size) and sometimes as 300gb (the new size). i ran bootrec commands as well.

eventually, windows did repair itself and was able to boot. then i installed the hfs+ partition from its image and was able to use tools associated with that system to get it running as well. both systems are now booting, apparently properly, and seem to run well. the only thing that now has me scratching my head and a little dubious is that the disk reports as an mbr disk where the original was gpt. gpt is what i'd been trying to set up on the new one but, i assume, the windows installation disk had other ideas and that's where the change happened. it does seem to be working, though.

thanks and hope this is helpful to someone.
BabaG

vanepp
Posts: 85
Joined: 22 Jun 2012, 02:24

Re: partition cloning question

Postby vanepp » 31 Mar 2016, 21:43

Its good that you got it working finally. A few parting comments though, clonezilla uses partclone to do the work so you were still using the underlying tools (although the user interface may be better, I haven't used clonzilla). As to Windows, its problems are likely that the boot sector (partition 1 on your original layout) may know where the Windows partition is supposed to start (since the Windows installer installed them both). The tools will only move the Windows partition they won't modify the boot partition at all if it needs it and I suspect that may be the cause of your boot problems. I expect the best layout to use is partition 1 as the boot partition (it has to be partition 1 I think) as it doesn't change then the Windows partition. That way you can grow the Windows partition if want but the start of the Windows partition will remain the same (and Microsoft willing it may work :-). As to gpt, Windows apparantly doesn't support uefi/gpt and they have to create a old style MBR inside the gpt part table to make windows work, so I expect left to itself Windows will install a standard MBR. As long as your disk is less than the limit on the old style MBR (less than 4 terabytes I think) it should still work fine either way.

Peter Van Epp

BabaG
Posts: 7
Joined: 16 Mar 2016, 17:42

Re: partition cloning question

Postby BabaG » 01 Apr 2016, 17:50

didn't mean to disparage systemrescuecd in any way. apologies if my last post came across that way. it's my tool of choice.

this turned out to be such a stubborn problem that i wound up having to do a lot of image reinstalls to the new drive. i'd install it, it wouldn't work. i'd screw with it a bunch and, when it continued to have issues, i'd go back and reinstall again to try other things. i had the same boot issues whether using systemrescuecd or clonezilla. that's when i switched over to clonezilla. i figured that, if i was going to have to do repeated installs, it would be easier to do them all in one operation, which is how clonezilla worked. after a bunch of tinkering with that process it became clear that working with more individual images was necessary so i came back to the systemrescuecd process you recommended. a variant of that's what finally worked.

thanks again and sorry for any confusion,
BabaG


Return to “Hard-disk partitioning and storage”

Who is online

Users browsing this forum: No registered users and 1 guest