I wanted to upgrade my old 250GB WD Blue HDD to a newer 512GB Crucial SSD, but was having problems getting the data transfered over. I tried clonezilla to no avail probably probably because the HDD had sector size of 512 bytes and the SSD uses 4k bytes. In the end, I resorted to copying everything over manually. Here are the steps that I used For these steps /dev/sdX is the existing drive and /dev/sdZ is the new one, which became one letter less after the existing drive is removed (sdY).
Prequisites
- Have a linux live USB to be able to boot with
- Install grub-efi-amd64:
- sudo apt-get install grub-efi-amd64
Linux Live USB Steps
Existing Partition Formats
- sdX1 - EFI - 512MiB - flags hidden
- sdX2 - root - 95.37GiB
- sdX3 - home - 129.48GiB
- sdX4 - swap - 7.54GiB
Create new partitions using gparted
- sdZ1
- description: EFI
- Free space preceding: 1MiB (This is the default that came up for me and from what I read should be used for aligning the physical sectors)
- size: 512MiB
- type: fat32
- flags: hidden, esd, boot
- sdZ2
- description: root
- size: 153,600MiB
- type: ext4
- sdZ3
- description: home
- size: 257,291MiB
- type: ext4
- sdZ4
- description: swap
- size: 65,536MiB (I went with 64GiB as the server has 20GiB of RAM and I am thinking of upgrading to 32GiB and this would put me at 2x of that)
- type: linux-swap
Mount
- sudo mount /dev/sdX1 /mnt/hdd1
- sudo mount /dev/sdX2 /mnt/hdd2
- sudo mount /dev/sdX3 /mnt/hdd3
- sudo mount /dev/sdZ1 /mnt/ssd1
- sudo mount /dev/sdZ2 /mnt/ssd2
- sudo mount /dev/sdZ3 /mnt/ssd3
Copy the data
- a - archive mode; equals -rlptgoD (no -H,-A,-X)
- A - preserve ACLs (implies -p)
- H - preserve hard links
- X - preserve extended attributes
- x - don't cross filesystem boundaries (this is very important)
- v - increase verbosity
- cd /mnt/hdd1
- sudo rsync -aAHXxv --stats --progress . /mnt/ssd1
- cd /mnt/hdd2
- sudo rsync -aAHXxv --stats --progress . --exclude={"dev/*","proc/*","sys/*","tmp/*","run/*","mnt/*","media/*","lost+found"} /mnt/ssd2
- cd /mnt/hdd3
- sudo rsync -aAHXxv --stats --progress . /mnt/ssd3 --exclude={"lost+found"}
Edit the UUIDs copied
- sudo blkid /dev/sdZ2 # for /
- sudo blkid /dev/sdZ3 # for /home
- sudo blkid /dev/sdZ4 # for swap
- sudo vi /mnt/ssd2/etc/fstab
Replace the UUID for swap in initramfs resume
- sudo vi /mnt/ssd2/etc/initramfs-tools/conf.d/resume
Change booting to use new drive
GRUB
- boot using old install
- sudo update-grub
- check /boot/grub/grub.cfg to ensure it is using the correct UUID for sdZ2
- boot using new install
- sudo mkdir /boot/efi
- sudo mount /dev/sdZ1 /boot/efi
- sudo grub install --target=x86_64-efi /dev/sdZ
- sudo update-grub
- shutdown
- remove old hd
- boot using new install
- sudo update-grub
Bonus Section
Because I did not get grub installed on the new drive before removing the old one, I got stuck at the grub prompt so the steps that I used to boot were:
- ls
- set root=(hd2,2)
- linux /boot/vmlinuz<tab complete to most recent version> root=/dev/sdY2
- initrd /boot/init<tab complete to same version as above>
- boot
TRIM
Ensure that trim is enabled and works:
- Check that it is enabled to run weekly
- systemctl status fstrim.timer
- Check that trimming actually works
- sudo fstrim -v /
Update 2022-07-26: NOATIME
- UUID=XXXX / ext4 defaults,noatime 0 1
Update 2023-02-03: Swappiness
- in /etc/sysctl.conf add:
- vm.swappiness = 10
- reboot
- check the setting:
- cat /proc/sys/vm/swappiness
Sources
- https://newbedev.com/how-to-best-clone-a-running-system-to-a-new-harddisk-using-rsync
- https://ostechnix.com/backup-entire-linux-system-using-rsync/
- https://itectec.com/ubuntu/ubuntu-how-to-transfer-ubuntu-to-ssd-but-keeping-home-on-hdd/
- https://askubuntu.com/questions/1116778/how-to-set-the-resume-variable-to-override-these-issues
- https://www.howtogeek.com/449691/what-is-swapiness-on-linux-and-how-to-change-it/
- https://askubuntu.com/questions/103915/how-do-i-configure-swappiness