3

I recently bought a new laptop and I would like to migrate to it with as little hassle as possible. I don't want to do a fresh install since I have made various tweaks to my current setup for things like automounting remote drives from my NAS, configuring networking etc. that I would prefer not to have to redo.

My current thinking is that I can just dump the contents of my hard drive to a file, then cat that file onto the new drive. The general idea will be:

  1. On the old computer, cat the drive into a file on an external USB disk and (as root):

    # cat /dev/sda > /mnt/externalUsb/sda.img
    
  2. I then boot into a live system on the new computer, connect the external drive and (as root):

    # cat /mnt/externalUsb/sda.img | sudo tee /dev/sda
    
  3. Shut down the live session, reboot the machine and, I hope, find myself in a working system which is a perfect clone of my old machine.

Or, perhaps more realistically, something like:

  1. Create the partitions I want on the new machine, making sure they are larger than the equivalent ones on my old machine.

  2. On the old computer, cat the partitions into files on an external USB disk (as root):

    for i in 5 6; do cat /dev/sda"$i" > /mnt/externalUsb/sda"$i".img; done
    
  3. On the new machine, after making sure the numbers are the same or modifying the command accordingly:

    for i in 5 6; do cat /mnt/externalUsb/sda"$i".img; > /dev/sda"$i"; done
    

Some relevant notes:

  • The hardware of the old and new machines is relatively similar as I will be moving from a ThinkPad T460P to a ThinkPad P14s Gen 2.
  • The new machine has a 1TB hard drive but the old one is only 512G.
  • I am using Arch, dual booted with a Windows 10. I am not particularly bothered about keeping the Windows install.

My current machine's disk setup:

$ sudo parted -l
Model: ATA SAMSUNG MZ7LN512 (scsi)
Disk /dev/sda: 512GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 

Number  Start   End     Size    File system     Name                          Flags
 1      1049kB  274MB   273MB   fat32           EFI system partition          boot, hidden, esp
 2      274MB   290MB   16.8MB                  Microsoft reserved partition  msftres
 3      290MB   86.4GB  86.1GB  ntfs            Basic data partition          msftdata
 5      86.4GB  136GB   50.0GB  ext4
 6      136GB   437GB   301GB   ext4
 9      437GB   485GB   47.3GB  ntfs                                          msftdata
 8      485GB   495GB   10.5GB  ext4
 7      495GB   511GB   16.1GB  linux-swap(v1)                                swap
 4      511GB   512GB   1049MB  ntfs            Basic data partition          hidden, diag

I am expecting the kernel to detect the new/different hardware the first time it boots and sort it out for me automatically. Am I missing something obvious here? Any specific problems I might encounter? The new drive is larger, so that shouldn't be a problem, right? I have an ecryptfs-encrypted directory (two of them, actually), am I right in assuming that won't be an issue? Will I need to do anything special to handle the EFI system partition perhaps?


I accepted MC68020's helpful answer, but I ended up taking a different approach: I booted a live system, created the root and /home partitions and then just copied all my files over using rsync as described in the Arch Wiki.

I managed to boot the "new" system, but it still needs some tweaks, notably for the graphics driver. This isn't an approach to be taken if you don't know your way around Linux and enjoy tinkering. Of course, if you don't enjoy it, it's unlikely you'll be using Arch.

10
  • If it were I, I would use clonezilla. clonezilla.org I think conceptually it does what you propose, but it seems to be able to set up grub and in general I usually end up with a system that boots on the first try. I just did this on a Lenovo Thinkpad that failed (but the SSD was ok) to migrate to a slightly different Thinkpad. Commented Jun 26, 2022 at 17:02
  • 1
    I wouldn't copy your data this way because GPT has two copies, 1MB at the begining of the drive and the last megabyte as a copy. Thus by plain copying your backup GPT partition will be missing, but that's not a big deal and I guess something like gdisk could fix it. Also, I'm not sure you'll be content with the same partitions having the same sizes, so instead of copying I'd dump/restore individual partitions but that's just me. I've used e2image and ntfsclone and both have worked perfectly. The benefit would be that you won't be copying empty space. Commented Jun 26, 2022 at 17:12
  • Also, I'd make sure that all files are OK, so I'd run something like find / -type f -print0 | xargs -0 md5sum > /tmp/md5.sum and check files (md5sum -c md5.sum) after restoring. When copying such large amounts of data bit flips might happen. Commented Jun 26, 2022 at 17:14
  • Sounds like a great answer, @ArtemS.Tashkinov! I am particularly interested in your point about the 2 copies of the GPT since that's completely new to me. Could you please explain a bit more?
    – terdon
    Commented Jun 26, 2022 at 17:17
  • I'd recommend the howto from the gdisk author: rodsbooks.com/gdisk/whatsgpt.html and this one: metebalci.com/blog/a-quick-tour-of-guid-partition-table-gpt Commented Jun 26, 2022 at 18:05

2 Answers 2

1

The following stands here only for comfort of editing reasons. As it is not worth more than a comment, please feel free to remove it.


ext4 : Starting with linux-5.10, ext4 comes with some new, lighter-weight journaling method also known as fast-commit.
Benchmarks report 20-200% improvement for local filesystems and 30-75% improvement for NFS workloads.
If running some >=5.10 kernel, no doubt that you just want that.
But since fast commits are activated at filesystem creation time, then if your filesystems were created before the availability of that feature, you do need to recreate them with the fast_commit option explicitly enabled. (see man mke2fs and man ext4)

Since linux-5.10 was launched close to the eve of 2021, then if your ext4 fs have been created before (firing as root dumpe2fs *yourdevice* | grep created will tell you that) chances are poor for this feature to be supported.
It might appear more immediate to cat /proc/fs/ext4/*yourdevice*/options to check whether this feature is actually activated or not, though.


nvidia : My bad ! So in fact moving from NVIDIA GeForce 940MX 2GB to NVIDIA Quadro T500 4GB then ? Using Nvidia proprietary drivers ?
If so then just ensure your current driver version is >= to 450.102.04 (since support for T500 was added from that release)
I would anyhow run the nvidia-settings utility after cloning in order to take advantage of new features.
And BTW, 4GB ? Hmmm… might find this a little overkill ? Might want to reallocate to other purposes.


Wifi : (Intel Wi-Fi 6 AX210 I presume, in particular)
You should be aware that some distros have reported troubles with iwlwifi under rather recent kernel versions. See in particular Red-Hat bugzilla.
From what I understand, a patch should have been committed in 5.15 times (and almost certainly backported to LTSes) but prudence commands you crosscheck first.
Apart from this, you get the nasty troubles with wifi adaptors. They always need some firmware blob to run.
Then irrespective of the fact your kernel gets and might load the appropriate driver, it might not be able to find the firmware since, depending on your distro / manufacturer & copyrights, you can be requested to install some particular package or even download it from manufacturer's repos.

1
  • That's an excellent point about the ext4 stuff, I had no idea and it does indeed sound like I would want this. That's certainly something to think about, thanks! As for the graphics card, I do play some games and do a lot of video meetings, screen sharing etc which I hope can take advantage of it. The rest I figure shold be OK since any new drivers can always be installed.
    – terdon
    Commented Jun 27, 2022 at 13:23
0

It would be much easier to install new laptop, test that it works and then either mount the other drive directly from the new OS or boot into livecd and mount it that way. Then you would move things of interest like your homedir with means of rsync or tar.

I certainly would be against any blind dd/cating data between drives, there are several caveats you are ignoring that way that might come to byte you really hard.

And second GPT copy is only one of them!

1
  • 2
    I am trying to avoid needing to install from scratch and repeat all the various tweaks and customizations I have made. I am not trying to bring over my data, that's trivial, I am trying to avoid starting from scratch again. Can you explain what these caveats I'm not thinking of are? That's exactly why I'm asking the question. Also, please see updated question for another possibility (only cloning the two partitions I really want).
    – terdon
    Commented Jun 27, 2022 at 8:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .