Linux system migration record (from HDD to SSD)

created at 07-28-2021 views: 2

I migrated the Linux on the HDD to the SSD. It was too much trouble to reinstall the system, so I copied the entire system directly, and then rebuilt the boot recovery. The following is the record.
Two hard drives

First, replace the SSD, and connect the HDD with a hard disk box.

After booting from the U disk, partition the SSD and mount the SSD system disk and HDD system disk to a certain path, for example:

For SSD, I divide it into /dev/sda1 and /dev/sda2. The former is used for EFI boot and the latter is the system disk.

  • Mount the SSD system disk to /data
  • Mount the HDD system disk to /mnt

Then use rsync to synchronize data:

rsync -av --progress /mnt/ /data/

After the synchronization is complete, go to /data/etc to edit the fstab file and replace the original path with the new one. You can use blkid or lsblk -f to view UUID.

The next step is to rebuild the boot.

A hard drive

If it is a hard disk, I want to change the file system, for example, I switched from btrfs to ext4, the plan is as follows:

  1. First look at the current data, divide the hard disk into two, leave enough size
  2. Create a file system for the new partition
  3. Enter the live system, mount the btrfs partition to /mnt, and mount the new partition to /opt
  4. Compress /mnt and save the file to /opt: cd /opt && tar cvf data.tgz /mnt
  5. Unmount the partition where btrfs is located, and rebuild the file system: sudo umount /mnt && mkfs.ext4 /dev/<the drive letter where the btrfs file system is located, for example, mine is sda2>
  6. Remount the formatted partition to /mnt, and unzip the compressed file under /opt: tar xvf data.tgz -C /

After the decompression is complete, enter /mnt/ etc to edit the fstab file, and replace the original path with the new one. You can use blkid or lsblk -f to view UUID.

The next step is to rebuild the boot.

Update grub

Before updating grub, you must mount something, otherwise an error will be reported:

$ sudo mount --bind /dev /data/dev
$ sudo mount --bind /sys /data/sys
$ sudo mount --bind /proc /data/proc
$ sudo mount /dev/sda1 /data/boot/efi

Then chroot in and update the EFI boot:

$ sudo chroot /data
$ sudo apt-get install --reinstall grub-efi
$ sudo grub-install /dev/sda
$ sudo update-grub

Optimize file mounting options for SSD

Because I use ext4, optimized for SSD, change fstab, add the following options discard, noatime, so it looks like this:

UUID= UUID just updated /   ext4 discard, noatime, errors=remount-ro 0 1

If the startup encounters Gave up waiting for suspend/resume device

First check if there is a problem with fstab, if so, change it; then check if there is any problem with the UUID of /etc/initramfs-tools/conf.d/resume, if so, change it.

Then execute sudo update-initramfs -u and restart.

Get it done! This is much faster than reinstalling the system, too lazy to reinstall and reconfigure.

created at:07-28-2021
edited at: 07-28-2021: