Skip to content

Instantly share code, notes, and snippets.

@ervinb
Last active August 11, 2023 17:08
Show Gist options
  • Save ervinb/558504748b3bff1ff0226ab3f9e0f8e1 to your computer and use it in GitHub Desktop.
Save ervinb/558504748b3bff1ff0226ab3f9e0f8e1 to your computer and use it in GitHub Desktop.

Migrate a Fedora 27 installation to a NVMe SSD drive with rsync

Prepare partitions

Create partitions with GParted:

Device Label File system Flag
/dev/nvme01p1 fedora-nvme-root ext4 n\a
/dev/nvme01p2 fedora-nvme-boot ext4 n\a
/dev/nvme01p3 fedora-efi fat16 flags: boot, eps
/dev/nvme01p4 fedora-nvme-home ext4 n\a

The important thing is to have a separate EFI partition -- the rest comes down to personal preference.

Create mount points and mount:

$ sudo mkdir -p /mnt/nvme-{root,boot,home}

# copy root
$ sudo mount /dev/nvme0n1p1 /mnt/nvme-root
$ sudo rsync -aAXS --info=progress2 --exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","/lost+found","/home/*","/boot/*"} / /mnt/nvme-root

# copy boot -- important not to copy the 'efi' dir
$ sudo mount /dev/nvme0n1p2 /mnt/nvme-boot
$ sudo rsync -aAXS --info=progress2 --exclude={"/boot/efi/*"} /boot/ /mnt/nvme-boot/

# copy home
$ sudo mount /dev/nvme0n1p4 /mnt/nvme-home
$ sudo rsync -aAXS --info=progress2 --exclude={"/home/*/.thumbnails/*","/home/*/.cache/mozilla/*","/home/*/.local/share/Trash/*"} /home/ /mnt/nvme-home/

Takes around 15 minutes in total.

Configure GRUB EFI in chroot

$ - host shell

$$ - chroot shell

  1. Mount required file systems and chroot:
# to have a functional chroot
$ for fs in (proc sys dev run); do sudo mount --bind /$fs /mnt/nvme-root/$fs; done

# prepare boot partition for chroot
$ sudo mount --bind /dev/nvme01p2 /mnt/nvme-root/boot

# mount EFI partition
$ sudo mkdir -p /mnt/nvme-root/boot/efi
$ sudo mount --bind /dev/nvme01p3 /mnt/nvme-root/boot/efi

# start chroot
$ sudo chroot /mnt/nvme-root
  1. Edit fstab
$$ ls -l /dev/disk/by-uuid | grep nvme

lrwxrwxrwx. 1 root root 15 Aug  4 13:03 85DA-A891 -> ../../nvme0n1p3
lrwxrwxrwx. 1 root root 15 Aug  4 13:03 9d78f34a-4ab0-4ab9-a48b-7682a4b52188 -> ../../nvme0n1p1
lrwxrwxrwx. 1 root root 15 Aug  4 13:03 a4debf2a-5c07-47e6-95bf-fc87a544d9f9 -> ../../nvme0n1p2
lrwxrwxrwx. 1 root root 15 Aug  4 13:03 ffa22844-a6c3-4e60-b806-1fa5683e794c -> ../../nvme0n1p4

$$ vi /etc/fstab

# /etc/fstab
# Created by anaconda on Tue Jan  3 09:09:17 2017
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=9d78f34a-4ab0-4ab9-a48b-7682a4b52188 /                       ext4    defaults        1 1
UUID=a4debf2a-5c07-47e6-95bf-fc87a544d9f9 /boot                   ext4    defaults        1 2
UUID=85DA-A891                            /boot/efi               vfat    umask=0077,shortname=winnt 0 2
UUID=ffa22844-a6c3-4e60-b806-1fa5683e794c /home                   ext4    defaults        1 2
  1. Generate GRUB config
$$ dnf reinstall grub2-efi shim
$$ grub2-mkconfig -o /boot/efi/EFI/fedora/grub.cfg
  1. Rebuild initramfs with support for NVMe

This is vital. Without it, the NVMe disk can't be located, and the splash screen will eventually drop you into dracut rescue, stating that the drive with UUID=<nvme-root-uuid> can not be found. This is why we need to explicitly enable the NVMe driver, so don't fall into the rabbit hole of using efibootmgr to create new UEFI entries.

$$ echo 'add_drives+=" nvme "' | tee /etc/dracut.conf.d/nvme.conf
$$ dracut -f

Boot Fedora from the NVMe drive

At this point, Fedora 27 should boot after the Fedora (<nvme-drive-name>) is selected from your motherboard's the boot menu.

@no1knows
Copy link

Well that's put an end to about 24 hours of hair pulling... the initramfs rebuild is what I'd missed, and my raid 1 setup (both disks on nvme) complicated matters. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment