Like many people, I need to upgrade from the used laptop that I am using, to a newer (still used) laptop. This is usually every 3 years or so.
Because I don't want to install the operating system that I use (Xubuntu Linux) from scratch when doing so, I used to remove the disk in the old computer, and install it in the new one, and things would work right away, with all my applications still there, and my desktop the way it is when I shutdown the older computer.
But sometimes, this method is not practical. For example, if the particular laptop is hard to open, or when the old and new disks are of different technologies (e.g. old computer has a SATA SSD, and the new one has an NVMe drive.
In this case, I need to copy the old computer's disk to the new computer's disk.
The easiest way to do this, without having to open the computers, and disconnect disks and such, is over a local area network (LAN).
But there are several steps involved. Here is an overview:
- Connect both computers to your router using Ethernet.
- Boot both computers from a live Linux drive (e.g. USB drive).
- From the terminal, dump the old disk to a pipe over the network.
- Fix the partition table using gdisk.
- Resize the root partition using GParted.
The rest of this article details the steps outlined above.
Security Notice
Before you start, you should be aware that doing this requires a LAN that is well protected from outside threat, like port scanners, bots, scans, penetration attempts and the like.
If your LAN is not well protected from outside threats threats, then you can use ssh
instead of nc
with minor modifications.
Connect Both Computers To Your LAN Over Ethernet
You can do the copy over WiFi, but any wired technology would be more stable and consistent over wireless protocols.
So, you need two Ethernet cables, one for each computer.
If your laptop lacks an Ethernet port, you need to get a USB to Ethernet Adapter.
Boot From A Live Linux Image
Because we will be copying the main disk of the old computer, we need this disk to be quiescent and not having any activity on it. To do so, we need to boot the computer from a Live Linux Image.
You can use any Live Linux Image that you are familiar with. In my case, I use the Xubuntu Live Image from a USB drive.
Once you have a desktop on each of the computers, start a terminal program.
Find Out The IP Address Of The New Computer
From the terminal, enter this command:
ip a
The output from this command will be very verbose, but you want the Ethernet interface (usually starts with enpxxxx), and to look for a line that starts with something like:
inet 192.168.0.123/24 ....
The number after the word 'inet' and before the '/' character is the IP address of the new computer.
So in this case, it is 192.168.0.123
.
Start The Listener, With Disk Dump
Then, you need to start a pipeline to consume the data from the LAN, and dump it to the disk.
We add gzip so that the data is compressed, and less time is taking copying the data.
nc -l -p 9999 |
gzip -d |
dd bs=10M conv=fsync status=progress of=/dev/nvme0n1
The port we will use is 9999.
Send The Old Computer's Disk Data To The New Computer
On the source machine (the older one that we will be copying from), you will need the IP address from the steps above, and the port:
DEST_IP=192.168.0.123
DEST_PORT=9999
dd bs=10M status=progress if=/dev/sda |
gzip -c -9 |
nc $DEST_IP $DEST_PORT
Depending on the size of the disks, this will take over an hour.
In my case, 500GB took 1 hour 41 minutes.
Fix The Partition Table
You then need to fix the partition table using gdisk, on the new computer.
Execute the following command:
sudo gdisk /dev/nvme0n1
Then enter the following:
Command (? for help): w
Warning! Secondary header is placed too early on the disk! Do you want to
correct this problem? (Y/N): Y
Have moved second header and partition table to correct location.
Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!
Do you want to proceed? (Y/N): Y
OK; writing new GUID partition table (GPT) to /dev/sdc.
The operation has completed successfully.
Resize The Root Partition
Then run GParted, which should be available if you use the Xubuntu Live Image or a similar version.
From there, you should resize the root partition and make all the unallocated space part of it.
This article by Wolfgang Ziegler shows screenshots of how to do this.
And that is it ... you are done.
Reboot your new computer and you should have the exact same desktop, applications, data and everything.
Most Comments
Most commented on articles ...