Skip to content

Instantly share code, notes, and snippets.

@dayne
Last active December 4, 2017 04:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dayne/805c2a3b97b00e9d089674b1acb89491 to your computer and use it in GitHub Desktop.
Save dayne/805c2a3b97b00e9d089674b1acb89491 to your computer and use it in GitHub Desktop.
Migrating Windows to a new drive

Migrating an OS drive to a new drive

Sometimes it is nice to migrate an existing operating system drive to a new drive without having to reinstall or do weird migration things with odd commercial/custom software.

Why do this? A few reasons: My old spinning disk isn't as much fun as a new SSD. My SSD is too small and I need wiggle room!

The following are the steps needed for migrating a windows OS drive to a new drive. Covering two different scenarios:

  1. Scenario 1: Current existing drive smaller than new drive
  2. Scenario 2: Existing drive is larger than new drive.

Tools needed:

  • Ubuntu Live USB disk
    • lsblk - list block devices
    • dd - disk duplicator
    • gparted - GUI tool to manage and resize partitions and filesytems.
  • A new drive

Basic steps overview - Scenario 1 - Current drive smaller than new drive:

  • duplicate current drive to new drive
  • resize new drive partition to allow full use of new space
  • remove old original drive and replace with new drive

Basic steps overview - Scenario 2 - Current drive larger than new drive:

For this scenario to work you have to have a bunch of un-used space you don't mind not having available in the future. The reason you might be in this scenario is you have a larger spinning drive and you are using a tiny fraction of it and would like to enjoy the performance of an SSD instead of having that extra space. For this example here I'll assume a 1TB spinning drive with only 120GB of OS and data used on it going over to a new 500GB SSD.

  • shrink the filesystem smaller than new drive - for example shrink 1TB down to a 450GB
  • duplicate drive partition info to new drive
  • duplicate each partition into new drive
  • a final resize of new drive partition to allow full use of new space
  • remove old original drive and replace with new drive

Getting started:

  • Download the Ubuntu Live USB image
  • Burn to a USB disk using the epicly easy burning tool: etcher.io
  • Shutdown the computer
  • Connect the new drive (you can let it dangle for now, you'll be removing the original drive at end)
  • Boot up computer into Ubuntu Live disk
    • don't do an install, just select the 'try live' option
  • Launch terminal

Steps for scenario 1 - larger new drive

  • in terminal run: lsblk
    • familiarize yourself with the drive letters and identify the device path of the current OS drive and the new target drive.
    • On a typical simple Windows system the original OS drive will likely be /dev/sda with a few sub partitions of /dev/sda1, /dev/sda2, /dev/sda3, and /dev/sda4
    • The new drive should be easy to identify as a drive of the expected new size, 500GB for eample, and has no partitions - so might just be /dev/sdc
  • do a full duplication of the current drive to the new drive
    • assuming /dev/sda is the current smaller drive and /dev/sdc is the new larger drive
    • dd if=/dev/sda of=/dev/sdc bs=2M
    • wait for this to finish
  • launch gparted - note: gparted might detect the new drive has un-used space and offer to fix this - say yes, let it fix that issue.
    • refamiliarize yourself with the drives and how they are setup
    • when you are comfortable you can see old drive and the new drive with it's unused space you are ready to resize the partition.
    • select the partition on the new drivec that represents the OS (C drive) and resize it - use GUI to stretch this partition to use up full space of disk and queue up the operation
    • apply this operation and wait until it completes
  • close gparted
  • in terminal run: lsblk again and review how things have changed from your original run

Now you are ready to shutdown the computer, remove the original drive, put the new drive in place of original drive and boot up your computer like normal. Enjoy the expanded wiggle room.

Steps for scenario 2 - smaller new drive

It is advisable to make sure the more important things are backed up before doing this - this is typically a safe operation these days but you never know.

Shink the current OS drive

Part 1: Familiarization with existing drives and partitions.

  • in terminal run: lsblk
    • familiarize yourself with the drive letters and identify the device path of the current OS drive and the new target drive.
    • On a typical simple Windows system the original OS drive will likely be /dev/sda with a few sub partitions of /dev/sda1, /dev/sda2, /dev/sda3, and /dev/sda4
    • The new drive should be easy to identify as a drive of the expected new size, 500GB for eample, and has no partitions - so might just be /dev/sdc
  • launch gparted
    • Familiarize yourself with the new drive and old drive. Look to top left for a drop down of each of the drives. Select /dev/sda and review it, assuming it is your current OS drive, it should look familiar. Find the new drive, it should not have any partitions. Get comfortable you know which is the original drive and which partition on that drive you need to shrink.

Phase 2: Shrink the filesystem:

  • This is the most dangerous activity and warrents having a backup of user data for safety.
  • In gparted you hopefully have a situation where /dev/sda4 is the operating system and is the largest and last partition on your current drive. This best case scenario makes it easy in gparted to do the following
  • Select the /dev/sda4 partition and resize - shink it down to about 450GB
    • recall, I'm assuming you have a 500GB SSD - goal here is to shrink this down well below size of new drive. Look to the output from lsblk to nail down exactly how much your computer actually sees. My 500GB SSD showed up as a 460GB drive.
  • Apply the operation
    • gparted works like this: queue up a series of operations to be applied, then apply them for real.
  • Exit out of gparted

Phase 3: Duplicate data over to new drive:

  • use lsblk to again review and refamiliarize yourself with the original drive and the new target drive and partitions.

    • for example: original drive of /dev/sda might have /dev/sda1, /dev/sda2, /dev/sda3, and /dev/sda4
  • copy the partition table from original drive to new drive: dd if=/dev/sda of=/dev/sdc bs=2M count=10

    • this brings over the first 20M of the drive - more than enough to bring over the partition table.
  • again use lsblk and notice how the new drive has the same partitions as the old drive - we are ready to make each of those new partitions be exact duplicates of the original drive.

  • for each of the partitions, use dd to duplicate the old partition to the new partition. Assuming we are using old as /dev/sda1 and new is /dev/sdc1 and so on through /dev/sdc4 do the following commands:

    • dd if=/dev/sda1 of=/dev/sdc1 bs=2M
    • dd if=/dev/sda2 of=/dev/sdc2 bs=2M
    • dd if=/dev/sda3 of=/dev/sdc3 bs=2M
    • dd if=/dev/sda4 of=/dev/sdc4 bs=2M
  • launch gparted - note: gparted might detect the new drive has un-used space and offer to fix this - say yes, let it fix that issue.

    • refamiliarize yourself with the drives and how they are setup
    • when you are comfortable you can see old drive and the new drive with it's unused space you are ready to resize the partition.
    • select the partition on the new drivec that represents the OS (C drive) and resize it - use GUI to stretch this partition to use up full space of disk and queue up the operation
    • apply this operation and wait until it completes
  • close gparted

  • in terminal run: lsblk again and review how things have changed from your original run

Now you are ready to shutdown the computer, remove the original drive, put the new drive in place of original drive and boot up your computer like normal. Enjoy the new performance!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment