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:
- Scenario 1: Current existing drive smaller than new drive
- Scenario 2: Existing drive is larger than new drive.
- Ubuntu Live USB disk
lsblk- list block devicesdd- disk duplicatorgparted- GUI tool to manage and resize partitions and filesytems.
- A new drive
- For example: Fancy 500GB SSD
- 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
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
- 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
- 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/sdawith 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/sdais the current smaller drive and/dev/sdcis the new larger drive dd if=/dev/sda of=/dev/sdc bs=2M- wait for this to finish
- assuming
- 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:
lsblkagain 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.
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.
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/sdawith 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/sdaand 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.
- Familiarize yourself with the new drive and old drive. Look to top left for a drop down of each of the drives. Select
Phase 2: Shrink the filesystem:
- This is the most dangerous activity and warrents having a backup of user data for safety.
- In
gpartedyou hopefully have a situation where/dev/sda4is 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/sda4partition 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
lsblkto nail down exactly how much your computer actually sees. My 500GB SSD showed up as a 460GB drive.
- 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
- 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
lsblkto again review and refamiliarize yourself with the original drive and the new target drive and partitions.- for example: original drive of
/dev/sdamight have/dev/sda1,/dev/sda2,/dev/sda3, and/dev/sda4
- for example: original drive of
-
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
lsblkand 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
ddto duplicate the old partition to the new partition. Assuming we are using old as/dev/sda1and new is/dev/sdc1and so on through/dev/sdc4do the following commands:dd if=/dev/sda1 of=/dev/sdc1 bs=2Mdd if=/dev/sda2 of=/dev/sdc2 bs=2Mdd if=/dev/sda3 of=/dev/sdc3 bs=2Mdd 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:
lsblkagain 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!