Migrate entire server from RasPi 4 to RasPi 5 + NVMe

I have a RasPi4 w/ Dietpi 9.17.2, Nextcloud 31.0.9, and some other apps. All up to date, AFAIK. It’s working (very) well, running off an external 500 GB SSD via USB3 (32 GB root partition, the rest on BTRFS, i.e. dietpi-userdata). No SD card.

I’d like to migrate this to a Pi5 + NVMe base to prepare for many more happy years of DietPi :slight_smile:

My first attempt was to run Jeff Geerling’s rpi-cloneto copy everything to the NVMe stick, connected via a USB adapter, and then boot off that on the Pi5. I made sure that both kernels are present, and that /etc/network/interfacessets both LAN and WiFi to DHCP to avoid conflicts (to keep the existing server running until the migration is successful). I also made sure that the NVMe-via-USB stick is earlier in the boot order than the target’s NVMe base.

Partial success: the NVMe stick boots (LED activity) in the Pi5, ping works, but SSH hangs (this is OpenSSH, not DropBear). This clone is still running bookworm, BTW. I did verify that a fresh trixie install on the Pi5 works on LAN and WiFi, off its internal NVMe, so the target h/w is ok.

Unfortunately, I don’t have easy access to the Pi5’s serial port to debug console msgs.

What would be the best way forward? I could upgrade the existing setup to trixieusing this: Debian Trixie | Upgrade script support thread · Issue #7644 · MichaIng/DietPi · GitHub if that works well, nowadays. As mentioned, I’d like to keep downtime to a minimum w.r.t. Nextcloud.

Any suggestions / tips would be most welcome,

– Jean-Claude Wippler

To follow up: progress, /etc/fstabwas not mounting the 3rd partition properly, that’s the btrfs area where dietpi_userdata lives. This extra UUID was not adjusted by rpi-clone… doh.

Now the Pi5 boots with the NMVe clone via USB and properly gives SSH access \o/

First, ensure that the RPi5 boots directly from the NVMe. A pure DietPi is sufficient for testing.

Ensure that the boot order prioritizes USB. Connect your external drive to the RPI 5 and start the system as usual from the connected USB drive. You can then follow these instructions and move the system to the NVMe of the RPi5. Normally, the RPi5 should then boot from the NVMe when the USB drive is no longer connected.

Bingo, success. Complete server migration with DietPi, thanks to the help of rpi-clone( GitHub - geerlingguy/rpi-clone: A shell script to clone a booted disk on a Raspberry Pi. ). I’m still on bookworm- the trixie upgrade will have to wait, but I now have the old server to figure that out.

For reference, here’s the whole process (this was written after the fact, there may be inaccuracies):

Goal

  • transfer a server setup based on DietPi (maybe any Debian distro) from one RasPi to another

Details

  • the original is running off one external disk with multiple partitions (no SD card)
  • the disk has an extra partition (sda3) with most of the data, formatted as BTRFS
  • there are several BTRFS subvolumes, which is very convenient for instant snapshots
  • the server is connected to a wired LAN with WiFi as backup access

Hardware

  • original: Pi4 w/ 4 GB RAM and 500 GB SSD connected via USB3
  • target: Pi5 w/ 8 GB RAM and 500 GB NVMe driver using the new PCIe connector
  • end result is a small box with everything inside and all USB ports available
  • the migration uses a spare USB drive to migrate all data

Step 1: clone the original system

  • attach external drive, and use rpi-clone to copy the entire system over to it
  • my spare drive was on /dev/sdb, so I used sudo ./rpi-clone sdb
  • before unmounting (last step in rpi-clone script), check some details:
    • make sure all data has been transferred (in my case, all BTRFS subvols were missing)
      • I manually set up the subvolumes and the rsync’ed everything over to it
    • make sure the clone will properly mounts the extra partition(s)
      • see /mnt/clone/etc/fstab
    • make sure all network interfaces use DHCP to avoid static address conflicts
      • see /mnt/clone/etc/network/interfaces
  • unmount and disconnect the spare drive

Step 2: prepare the new system

  • set up the new system with a fresh install of DietPi, just to verify it’s 100% ok
  • adjust the EEPROM configuration so that an external drive boots before the internal one
    • see rpi-eeprom-config –edit
    • I changed BOOT_ORDER from 0xf461 to 0xf641(1=SD, 4=USB, 6=NVMe)
  • power down, attach spare drive, power up

Step 3: run cloned drive on the new system

  • if all is well, the new system will boot from the cloned version, using new IP addresses
  • set up networking to enable both LAN and WiFi, and very that SSH works over WiFi
  • the clone is now working while connected to WiFi, the LAN should be disconnected

Step 4: migrate from external to internal NVMe

  • this is similar to step 1: sudo ./rpi-clone nvme0n1
  • again verify that the result has all the data and does all the mounts properly
  • unmount, disconnect the spare drive, and reboot

Step 5: perform server switchover

  • make sure you’re again logged in via SSH on the WiFiadapter (LAN disconnected)
  • prepare the new server to use the same (static) IP address as the old server
  • also log into the original (still-running) server via WiFi, not LAN
  • pull the LAN cable from the original, insert LAN cable in the new server

Step 6: phew …

  • if all is well, the switch-over is now done - new server in use, old server idle
  • restore BOOT_ORDER on the new server if you want NVMe to boot before USB again
  • I skimmed over a bunch of details, such as:
    • use dietpi-services to disable all services before cloning databases, etc
    • using SSH with a clean DietPi install will complain about host key changes
  • I actually did all this twice - once to get the process right, once to grab the last changes
    • that way, the (very) long initial clone can be done with a 100% working server
    • only the final transfer needs to run with services disabled to avoid database errors

I hope this is of use to others trying to keep DietPi (and other RPi setups) working long term.

-jcw

Yep, thanks. I had already started writing my summary :slight_smile:

There are easier ways without extra tools. :wink: