Migrate Root Partition To NVMe On Arch Linux

by Viktoria Ivanova 45 views

Hey guys! Upgrading your storage can be a game-changer, especially when moving to a blazing-fast NVMe drive. If you're like me and rocking Arch Linux, you'll appreciate this guide on how to move your root partition to a new drive while ensuring you can mount both your old and new drives. I recently went through this process, swapping my root partition from a 480GB SATA SSD to a spacious 2TB NVMe drive, and I'm here to share the steps and insights I gained along the way.

Understanding the Goal

The primary goal here is to seamlessly transition your Arch Linux installation from an older drive (in my case, a SATA SSD) to a new, faster NVMe drive. This involves cloning your existing root partition to the new drive, updating the bootloader to point to the new drive, and ensuring that you can still access the old drive for any data you might need. This process might seem daunting, but with careful planning and execution, it's totally achievable. The benefits are immense – faster boot times, quicker application loading, and an overall snappier system. Before we dive in, let's outline the steps we'll be taking to make this happen.

Prerequisites and Planning

Before we get our hands dirty, let's make sure we have everything we need and a solid plan in place. First off, you'll need a live Arch Linux environment. This is crucial because you can't modify the partitions of a mounted system. Grab the latest Arch Linux ISO and create a bootable USB drive. Next, identify your drives. Use lsblk to list all block devices, and note the device names for both your old and new drives (e.g., /dev/sda, /dev/nvme0n1). Make sure you know which is which to avoid any accidental data loss. Planning your partition scheme on the new drive is also essential. Will you create separate partitions for /boot, /home, and swap, or keep it simple with a single root partition? Consider your needs and preferences. Lastly, back up your important data! This is non-negotiable. While the process is generally safe, things can go wrong, and having a backup ensures you won't lose your precious files.

Key Preparations:

  • Arch Linux Live Environment: Download the latest ISO and create a bootable USB.
  • Identify Drives: Use lsblk to determine the device names of your old and new drives.
  • Partition Scheme: Plan how you want to partition your new drive.
  • Data Backup: Back up all important data before proceeding.

Step-by-Step Guide to Migrating Your Root Partition

Now, let's get into the nitty-gritty. Boot into your Arch Linux live environment. Once you're in, the real fun begins! The first step is to partition the new drive. Use a tool like fdisk, gdisk, or parted to create the necessary partitions according to your planned scheme. If you're unsure, a simple setup with a root partition and a swap partition is a good starting point. Next, format the partitions. Use mkfs.ext4 for your root partition (or another filesystem if you prefer) and mkswap for your swap partition. Remember to enable the swap partition with swapon. Now comes the cloning part. We'll use rsync for this, as it's a powerful and flexible tool for synchronizing files. Mount both your old root partition and the newly formatted partition on your NVMe drive. Then, use rsync with the -aAXHv flags to copy all files from the old root partition to the new one. This command preserves permissions, ownership, and other important attributes. Be patient; this might take a while depending on the size of your root partition. Once the cloning is complete, it's time to configure the new system. This involves generating a new fstab file, installing the bootloader, and making any necessary adjustments to the bootloader configuration.

Detailed Steps:

  1. Boot into Arch Linux Live Environment
  2. Partition the New Drive:
    • Use fdisk, gdisk, or parted to create partitions.
    • Example using fdisk:
      fdisk /dev/nvme0n1
      
  3. Format the Partitions:
    • Format root partition:
      mkfs.ext4 /dev/nvme0n1p1
      
    • Format swap partition:
      mkswap /dev/nvme0n1p2
      swapon /dev/nvme0n1p2
      
  4. Mount Partitions:
    • Mount old root partition (e.g., /dev/sda1) to /mnt/old:
      mount /dev/sda1 /mnt/old
      
    • Mount new root partition (e.g., /dev/nvme0n1p1) to /mnt/new:
      mount /dev/nvme0n1p1 /mnt/new
      
  5. Clone Files with Rsync:
    rsync -aAXHv /mnt/old/ /mnt/new/
    
  6. Configure the New System:
    • Generate a new fstab file:
      genfstab -U /mnt/new >> /mnt/new/etc/fstab
      
    • Install the bootloader (e.g., GRUB):
      arch-chroot /mnt/new
      pacman -S grub efibootmgr
      grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=arch_new
      grub-mkconfig -o /boot/grub/grub.cfg
      exit
      

Post-Migration Configuration and Mounting Both Drives

Once you've cloned your root partition and configured the bootloader, it's time to reboot and see if everything worked. Fingers crossed! If all goes well, you should boot into your Arch Linux system from the new NVMe drive. Congratulations! But our journey doesn't end here. We still need to ensure we can mount the old drive to access any remaining data. To do this, we'll need to update our /etc/fstab file. This file tells the system how to mount different partitions at boot. Identify the UUID of your old root partition using blkid. Then, add a new entry to /etc/fstab specifying the UUID, mount point (e.g., /mnt/old_root), filesystem type, and mount options. A typical entry might look like this: UUID=your_uuid /mnt/old_root ext4 defaults 0 0. Save the file and then create the mount point directory (mkdir /mnt/old_root). You should now be able to mount the old drive manually with mount /mnt/old_root or automatically at boot. This gives you access to all your old files, allowing you to migrate them as needed or simply keep them for backup.

Post-Migration Steps:

  1. Reboot and Test: Reboot your system and ensure it boots from the new NVMe drive.
  2. Identify Old Partition UUID: Use blkid to find the UUID of your old root partition.
  3. Edit /etc/fstab: Add an entry for the old drive.
    • Example entry:
      UUID=your_uuid /mnt/old_root ext4 defaults 0 0
      
  4. Create Mount Point:
    mkdir /mnt/old_root
    
  5. Mount the Old Drive:
    mount /mnt/old_root
    

Troubleshooting Common Issues

Okay, let's be real – things don't always go perfectly the first time. If you encounter issues, don't panic! One common problem is the system not booting from the new drive. This often boils down to bootloader configuration. Double-check that you've installed the bootloader correctly and that the boot order in your BIOS/UEFI settings is set to the new drive. Another issue might be related to the fstab file. If the UUIDs are incorrect or the mount options are wrong, the system might fail to mount the old drive or even fail to boot. Carefully review your /etc/fstab entries and make sure everything is accurate. If you're using a different filesystem on your old drive, ensure you specify the correct type in /etc/fstab. Sometimes, hardware compatibility can be a factor. If you're having trouble with your NVMe drive being recognized, check your motherboard's documentation and ensure that it supports NVMe booting. Updating your BIOS/UEFI firmware might also help. And of course, the Arch Linux wiki is your best friend! It's a treasure trove of information and troubleshooting tips.

Common Issues and Solutions:

  • System Not Booting:
    • Verify bootloader installation and configuration.
    • Check boot order in BIOS/UEFI settings.
  • Mounting Issues:
    • Double-check UUIDs and mount options in /etc/fstab.
    • Ensure correct filesystem type is specified.
  • Hardware Compatibility:
    • Check motherboard documentation for NVMe support.
    • Update BIOS/UEFI firmware.
  • Consult Arch Linux Wiki: It is an invaluable resource for troubleshooting.

Conclusion: Enjoy Your Speedy New Drive!

So there you have it! Migrating your root partition to a new NVMe drive on Arch Linux can be a bit of a journey, but the speed boost is totally worth it. By following these steps, you can seamlessly transition to your new drive while still retaining access to your old data. Remember to plan carefully, back up your data, and double-check your configurations. And if you hit any snags, don't hesitate to consult the Arch Linux community and resources. Now go forth and enjoy the blazing-fast performance of your new NVMe drive! You've earned it! This comprehensive guide ensures a smooth transition, providing not only the technical steps but also the context and troubleshooting tips needed for a successful migration. The conversational tone and detailed explanations make it accessible and engaging for Arch Linux users of all levels.