(using 100% free tools)


The point to this is to explain how to Mirror from a LARGE drive TO a SMALLER DRIVE.  This will contain a lot of basic information you know.. but will include one extra step you might not have thought of.  This aims at people trying to clone Windows 10 drives to a smaller SSD drive.  Windows 10 likes to put partitions to the right of the main windows partition.  At the time of writing this white paper.. Clonezilla does not know how to deal with that.  This document will manage that as well as give you step by step directions on how to get through this process.

Note: This document assumes you have figured out how to create and boot to a Clonezilla medium and have gotten past the basic default settings.  It also assumes you are tech savvy but the directions are very basic so even if you do not know a lot you should be able to manage it.  Ether way, I am not responsible for your blunders.  Make sure you backup.  (:

Note: BACK UP YOUR DATA FIRST.  Make sure you have a clean backup of your data.  A full drive backup is always advised.

Note: If your drive is encrypted.. DEcrypt it first.  I have NO IDEA what encryption will do to this process.


To Advanced Techs That Already Know the Process

If you are a more advanced tech and have, like me, been struggling with Clonezilla recently because of the additional partitions on the end.  You do not need to read this entire document.  In this small section I will share with you the small change you need to make to your already established process.  If you have not completed this process already at some point.. SKIP THIS SECTION…

When going through the final dialog’s of Clonezilla and you get to the prompt about creating partitions.  Choose -k2 to be dropped to a prompt and manually create the partitions (This is compatible with -batch mode).  Once you are dropped to the prompt you will need to type the following command to copy the partition table from the source to the destination drive.  NOTE: The destination comes BEFORE the source.  If you do this backwards you will wipe your partition table.  In the below example “sdb” is the blank or smaller target drive and “sda” is the source or larger drive.

WARNING: Pay attention to the order of the source and destination.  Also, it may not show but “replicate” has TWO hyphens in front of it.. Not one.

sgdisk ‐‐replicate=$dest $source
or
sgdisk ‐‐replicate=<destination drive> <source drive>


Example: sgdisk ‐‐replicate=/dev/sdb /dev/sda


Alternatively if you have GPT issues with sgdisk or it does not work try using these two lines.  This will export and import the partition table.

sfdisk -d <source>   > partitions.txt
sfdisk <destination>   < partitions.txt

Example….
sfdisk -d /dev/sda > partitions.txt
sfdisk /dev/sdb < partitions.txt


Shrinking and Moving the Partitions

Explanation:  This is necessary so that the data on the larger drive can fit on the smaller SSD/Solid State Drive.  You need to shrink the free space out of the larger operating system partition or data partition and move any partitions to the right of that to the left so it is all grouped at the front (left) of the drive and the data used by the collection of partitions is less than the total of space of the drive you are moving to.  I like to shrink it down as much as possible, however you really only need to shrink it down to a few gig smaller than the destination drive.  When this is done  you will be able to move the partitions back to fill the new drive.

I almost always do this portion through remote control on the machine before the client brings me the computer to me because it can be very time consuming.  But also can mostly be done in background.  I will recommend both Linux and windows tools for this.  I like to start with basic windows tools and then move my way out.  You can go right to the linux GParted boot media if you like.

Notes…

  • Fragmentation on the drive can cause the drive not to shrink.  This is why we defragment it first.  However, you can try to shrink it without defragging it.  Locked files cannot be moved so even after being defragmented a locked bit of data from a file can prevent the partition from shrinking.  The most common locked data comes from 3 things.  We address the first 2 of them in this document..  Windows System Restore and the Windows Page file.  Some Virus shields can have locked data, but it is not that common.
  • If, as mentioned above you think you have files locked on the partition you may need to boot to a separate operating system and defrag to get around that.
  • This section assumes this is a Windows computer and you ARE booted to the windows drive/partition you plan to shrink…
  • If you want to create a System Rescue CD boot media (Flash Drive or CD) you can jump right to that and use GParted on that to shrink/move the partitions.  Remember to run “startx” to get to Windows Manager if you do.
  • On linux/MAC you can skip defragging.
  • I hope you backed up your data!

On Windows, the page/swap file (Virtual Memory) and system restore files lock on the drive, and must be removed.  To do this….

  • Go to “System” in your control panel
  • Select “Advanced System Settings” on the left.
  • Select the “Advanced” tab then “Settings” under “Performance”..
  • Then another “Advanced” tab and press the “Change” button under “Virtual Memory” section.
  • Uncheck “Automatically Manage…” at the top, then select “No paging file” then press the “Set” button.
  • Press “Ok” twice so you are back to the “System Properties”/”Advanced” tab.
  • Go to the “System Protection” tab and press the “Configure” button.
  • Select “Disable System Protection” and press the “Delete” button.
  • Click “Ok” on all menus you are done with this part.

NOTE: When this is all done  you will want to come back to this section and set everything you just undid back to what it was.  You will be given brief and possibly unhelpful directions on how to do that.

  • Open Windows Explorer so it lists the Drives.
  • Right click on the “C:” drive and choose “Properties”.
  • On the “Tools” tab choose “Optimize” for defrag.
  • In the list select the “C:” drive row
  • Click the “Optimize” button.  (Wait for this process to finish)
  • No settings to save, close all the windows.

Using the Windows Defragment is often enough.  I would try to shrink the drive in the “Shrinking the partition” section, and if it will not shrink, come back up and do the MyDefrag section.

You are in this section because Windows Defrag was not enough and you were unable to shrink the partition.  If you have not already tried I suggest trying to shrink before you waste your time doing more defrags.

Note: The advantage to this tool, the thing I like, is that you can see the data it is moving and where it is.  If there is locked data you will be able to see it as it will be marked in red.

  • Go to http://www.mydefrag.net and download MyDefragGUI (THIS IS A FREE TOOL)
  • Run MyDefragGUI as administrator by right clicking on the app and selecting “Run as Administrator”.
  • “Defrag and Optimize” should already be selected.
  • Choose “Start” and wait for it to finish.

Note: Other tools mentioned in this document can shrink the Windows primary partition.  And if you have other partitions after the primary partition you will need those.  So if you are wondering why we are here using this one…  I always like to use the Windows built in tools when possible FIRST to avoid complications.

  • In windows search the start menu for “Computer Management” and then run it as Administrator.  (On newer OS’s you can right click on the start menu button)
  • Once “Computer Management” loaded, go to the “Disk Management Section”
  • Right click on the “C:” Drive and choose “Shrink Volume”.
  • It should default to the max amount of space you can shrink.  I like to tweak it and leave a few gig of working space.  After you hit the “Shrink” button expect it to hang for a long time (sometimes) just wait it out..
  • Go to the Drives list and look at the properties of the C: drive to see how big the partition is now registering in total space.  It should be less than the drive you are moving to including any addition partitions.
    • Note: that the boot partition to the left is measured in MB not Gig.  And possibly any partitions to the right as well.
  • If there are any partitions in the bar to the right of the C: drive, windows will not allow you to move them.  You must use a 3rd party tool listed below…
  • For Windows, I recommend MiniTool Partition Wizard found here: https://www.partitionwizard.com (ALSO AVAILABLE FREE)
  • Run the App as Administrator and choose “Lauch Application”
  • If you were already able to shrink the Primary “C:” partition then skip this step and move on to moving the other partitions left…
    • In the Partition Wizard Right click on the “C:” drive and select “Move/Resize”.  On the resulting dialog simply grab the right edge of the bar and drag it left to S!  Then click “OK”
  • If there are no partitions to the right of the Primary “C:” partition then skip this step too…
    • If you shrunk any partition than all partitions to the right that partition MUST BE MOVED to the LEFT so all partitions group together with no space between them..  Do this by right clicking on the partitions (from left to right) and choosing “Move/Resize” then click on the middle of the bar and drag it to the free space on the left.
  • Once all this is done, if you have made any changes in this section…
    • click the “Apply” button.

After all this if you still cannot shrink the partition small enough, make sure you do not have more data then the drive you are shrinking to meet.  If you have not tried shrinking with the MyDefrag tool go above and try that..  There is a good chance it will fix this.

If you are not using windows or you want to try to shrink the partition from outside windows.  Follow the above set of directions for MiniTool Partition Wizard but instead do it through ‘GParted’.  You can make any flash drive into a bootable “GParted” partition manager by installing the Lili Linux Live USB Creator found here: http://www.linuxliveusb.com/en/download and then set it to download the “System Recovery CD” and install it on a thumbdrive, or CD.  Once you are booted to the System Rescue CD on the thumb drive type “startx” at the prompt and then run “GParted” from the taskbar icon.

Note: You can get/make a GParted flash drive or CD/DVD but I do it with SysRescueCD because I find the creation process for that is easier, it is more likely to be bootable, and the end result is  the same as far as having a working copy of GParted.  The SysRescueCD has a lot of good uses.  Also, I instructed you to use Lili to create the media instead of the tool that SysRescueCD supplies on the website because I have better luck personally that way.  Feel free to try ether.  (:


Cloning the Actual Drive

By now you should have shrunk and grouped your partitions and are ready for the clone.  This assumes you have made a boot drive for Clonezilla with a Flash Drive or CD/DVD.  You can create one using the Lili tool.  If you want the most current version of Clonezilla you can always download the ISO and use Lili to make a bootable Flash Drive from it.

This section assumes you completed the previous section and have now shrunk and moved all the partitions to the left of the drive so that collectively they are smaller than the destination drive.  You should now boot to your Clonezilla media and pass all the starting screens with the defaults till you end up on the “Start Clonezilla” prompt…

  • Start Clonzilla
  • Device-Device
  • Expert
  • disk-to-local-disk
  • Chose your Source (Large) drive.. (make a note of the device name ie “sda” or “sdb” or “sdc”)
  • Choose your Destination (Smaller) drive.. (make a note of the device name ie “sda” or “sdb” or “sdc”)
  • Options Dialog…
    • Note: Use the spacebar to toggle select and unselect
    • unselect: -g auto (Although I think the “auto” implies it does not matter if it is selected.   Only unselect this if you are cloning a Windows Drive)
    • select: -icds (VERY IMPORTANT:  this is what tells Clonezilla to ignore the fact that you are cloning to a smaller drive)
    • select: -batch (WARNING: I like to select this but apparently this is very DANGEROUS so do so at your own risk.  I just have fear issues answering “y” over and over)
    • Press the enter key to finish the options dialog…
  • Choose: -sfsck
  • Choose: -k2 (THIS is what the other how-to’s have left out.  This will lead to the magic part of this process that makes it typically work while others failed you  this will cause Clonezilla to drop us to a prompt in the process and allow us to duplicate the partitions ourself)
  • You can choose to do whatever you want after the clone, I do not care.
  • Go through the typical prompts pressing “y” and “enter” until you see a prompt that starts with “Now enter another shell”… At this point you will press Enter and be dropped to a standard prompt.  When you do.. go to the next section.

In the previous sections you were told a few key things (two)….

One was to choose -k2 option and that option is the reason you are now sitting at a shell prompt in the middle of your Clonezilla process.  We did this because the Clonezilla process tends to fail when trying to copy the partitions if you have a partition after (to the right of) your data partition.  Using the -k1 process will backfire and Clonezilla will resize THE WRONG PARTITION.  This means we need to clone them ourself.

I also asked you to note the source and destination partitions.  In this example let us assume the source destination was “sda” and destination was “sdb” so in the below example it would “/dev/sda” and “/dev/sdb”.   If you forgot or did not note this information you can type: “fdisk -l | grep Disk” at the prompt.  In this the, “-l” is a lower case “L” as in Lama.  And the bar is a pipe symbol typically found above the backslash on your keyboard.  Alternatively you can also simply type: lsblk

At the prompt you will need to clone the partition tables from the source drive to the destination drive.   There are two methods to do this.  I use sgdisk, however it has been reported that this method sometimes struggles with non-GPT partitions.  So if this does not work for you, I have also supplied an alternate method for you to use  (Thank you dr00bie from our IRC noted below).  (:


METHOD 1

  • Notes…
    •  BE  VERY CAREFUL if you do this backwards it will wipe your partition table.  To make sure it is clear I will repeat myself a few times in different ways…
      The command is formatted as: sgdisk –replicate=$dest $source  or sgdisk –replicate=<destination drive> <source drive>
    • In the below example “/dev/sdb” is the DESTINATION and “/dev/sda” is the SOURCE.
    • WARNING: The destination is listed FIRST and NOT second.  PAY ATTENTION TO THESE NOTES OR YOU WILL CRY.
  • Formatting: sgdisk –replicate=<destination> <source>
  • Example: sgdisk –replicate=/dev/sdb /dev/sda
  • (If this worked, skip Method 2)

METHOD 2 (Alternate Method)

  • Notes….
    • This is done in two lines that export to a text file then import from that same text file.
    • In the below example “/dev/sda” is the SOURCE and “/dev/sdb” is the DESTINATION.
  • sfdisk -d /dev/sda > partitions.txt
  • sfdisk /dev/sdb < partitions.txt

After using one of the above methods you can run “fdisk /dev/sdb” (or whatever your destination drive is) and then enter “p” to print out the partition table on the screen.  If you see it.. you succeeded!  But no data is there yet…  Press “q” and enter to quit fdisk.

type “exit” to exit the prompt and the clone will continue and complete.

If your clone succeeded you now need to do a few important steps…

  • Boot to the destination Windows drive and let windows do a checkdisk on boot.
  • After this you can use any of the partition manager tools mentioned in the previous preparation steps to move trailing partitions to the right and then resize the “C:” Drive to fill the space.  I like to resize the “C:” drive through the “Computer Management” console but that cannot move partitions.  Note that the “Computer Management” console can “Expand” a partition just as it “Shrunk” them.
  • Once this is done, if you are using a windows machine, boot back to windows and follow/reverse the previous steps mentioned in preparation…
    • Set the “Virtual Memory” back by going to the dialog and change the “No paging file” to “System managed size”, press the “Set” button then checkmark “Automatically manage paging file size for all drives” at the top.
    • Also on the “System Protection” set this back to “Turn on system protection”, then press “Ok” and hit the “Create” button to make sure you have at least one good restore point.  (NOTE: THIS IS THE VERY LAST THING WE DID FOR A REASON)

Need Help or Want to Chat?

We have live techs in the chat room #DesktopMasters on the FreeNode network.  You have to jump through a few hoops to get there.  If you are familiar with IRC than this will be easy.  If not you will need to download an IRC client or use the Web Interface.   Once connected you have to register a nickname before you can join our room.  To learn how to register use /ns help register and to join the room you use /join #DesktopMasters when you come back you will need to identify with /ns help identify.. there is more information here.  If you are having trouble registering, identifying or getting into the channel then check out this thread.


Thank You

Thank you to the following people who helped in creating this document…

  • _KaszpiR_ – In Freenode IRC for giving me some great suggestions of things to mention/include in this document.
  • dr00bie – In Freenode IRC for suggesting the second (alternate) method of copying the partitions