🕵️‍♂️ Engage in discussions ANONYMOUSLY. NO REGISTRATION is required. 💬

✅ Registered accounts earn up to $25 per thread via PayPal and BTC. 🤑 Read more in News and Announcments! Unlock the ability to chat, share, send private messages and earn money per post in our community. Just register an account. It's Free!

SignUp Now!
  • 🕵️‍♂️ Engage in discussions ANONYMOUSLY. NO REGISTRATION is required. 💬 ✅ Registered accounts earn up to $25 per thread via PayPal and BTC. 🤑 Read more... Unlock the ability to chat, share, send private messages and earn money per post in our community. Just register an account. It's Free!

Guide Migrate Boot Partition to Another Drive in Linux (+ LUKS encrypted)

Choose this one if you are writing a guide
Moderator
Joined
Aug 18, 2023
Messages
19
Credits
216

Migrating The Boot Partition to New Disk​

1. Boot from a Live CD
  • Download any Linux distro (Linux Mint, Kubuntu, Ubuntu... anything. Doesn't have to be the exact copy of the system we are rescuing.) to a USB stick using
    You must have 10 posts to see the links. Currently you had 0 posts.
    or your preferred tool. Choose "try" to boot without installing the distro.
  • When booting press F2 (open the boot menu) chose the Live CD and Boot from it.
  • Don't install it, chose TRY (safe graphics)
2. Clone the Boot Partition:
  • Use dd to clone your existing boot partition to the new disk.
  • Example:
    Bash:
    sudo dd if=/dev/old_disk_boot_partition of=/dev/new_disk_boot_partition bs=4M
    Your boot partition will be aproximately 100-512mb and only part of it will be written (example 32mbs) the rest will be free empty space.
3. Mount Necessary Partitions:
  • List your partitions
    Bash:
    lsblk
    This will show a list of your partitions but make sure to open a graphic user interface program to be certain anything like Gparted, KDE partition manager will do the job.
  • Mount the partition that has your Linux installation (nvme0n1p2 in our example)
    Bash:
    mount /dev/nvme0n1p2 /mnt
  • Mount the dev, proc, sys and chroot into the system
    Bash:
    mount --bind /dev /mnt/dev
    mount --bind /proc /mnt/proc
    mount --bind /sys /mnt/sys
    chroot /mnt
4. Update /etc/fstab:
  • After the copy is complete, edit /etc/fstab and replace the old boot partition's UUID with the new one. Find the partition ID with:
    Bash:
    blkid
  • Open the fstab with an editor of your choice nvim/nano/vim
    Bash:
    sudo nano /etc/fstab
6. Update GRUB:
  • Update GRUB to recognize the changes.
  • Example:
    Bash:
    sudo update-grub
5. ONLY IN CASE OF MIGRATING Encrypted Linux LUKS Partition to another drive:
  • Use dd or another tool to clone the LUKS partition to the new disk.
  • Example:
    Bash:
    sudo dd if=/dev/old_disk_luks_partition of=/dev/new_disk_luks_partition bs=100M
6. Rename LUKS Device:
  • After cloning, rename the LUKS device using cryptsetup luksOpen. Make sure to add the same name to /etc/crypttab as used during luksOpen.
    Bash:
    sudo cryptsetup luksOpen /dev/new_disk_luks_partition new_cryptroot
7. Update /etc/crypttab:
  • Open /etc/crypttab and replace the old LUKS device name with the new one.
    Bash:
    sudo nano /etc/crypttab
8. Update Initramfs:
  • Update the initramfs to include the changes.
    Bash:
    sudo update-initramfs -u
9. Reinstall Grub:
Make sure you are chrooted into the system that you are migrating!
Bash:
grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=grub
update-grub
If you get any errors, never ignore them but always DuckDuckGo them or ask for help! The process must finish without errors.

9. Unmount and Verify:
  • Unmount everything that we mounted
    Bash:
    umount -l /mnt/sysumount -l /mnt/proc
    umount -l /mnt/dev
    umount -l /mnt/boot/efi
    umount -R /mnt
  • Reboot your system and verify that it boots correctly from the new disk.
    Bash:
    reboot

Remove Old Windows Partition (ONLY if needed):​

Identify Windows Partition:
  • Use lsblk or fdisk -l to identify the Windows partition.
  • Bash:
    efibootmgr
    Identify the entry corresponding to Windows, usually labeled as "Windows Boot Manager."
    Bash:
     efibootmgr -b <Windows_Entry_Number> -B
  • While chrooted navigate to your new EFI/BOOT partition (replace /dev/nvme0n1p1 with the actual EFI partition).
    Bash:
    cd /boot/efi/EFI
    # Remove the Windows folder.
    rm -r Microsoft
Update Initramfs:
  • Update the initramfs to reflect the changes.
    Bash:
    sudo update-initramfs -u
Remove Windows Entry from GRUB (if dual-boot):
  • If dual-booting, remove the Windows entry from GRUB.
    Bash:
    sudo update-grub
Remove Windows Partitions (Optional):
  • Use fdisk or another partition management tool to remove the Windows partitions.
Note: Always make backups before making any changes to avoid data loss. Double-check commands and verify changes with a GUI partition manager.
 
Top