How to move a root from SD card to external drive on Raspberry Pi

0. Introduction

Of course you want your SD card to last longer. We can move a root off to an external drive.

We'll do that using Linux.

We need to copy files from a SD card's root onto a disk's partition and modify a cmdline.txt file in a /boot directory of a SD card.

1. Moving / to external drive

So, you already have your drive partitioned.

Let's create temporary directories for SD card's boot, root partitions and for disk's partitions according to how you partitioned it. I'll stick to simple case when we have everything on root.

Let they be /mnt/sdboot, /mnt/sdroot and /mnt/hdd. SD's boot partition is mounted to modify cmdline.txt file stored there.

To move files and links with all their attributes run cp -a /mnt/sdroot/* /mnt/hdd. -a option stands for archive, it's the same as cp -dR --preserve=all, where -d is the same as --no-dereference --preserve=links, -R option tells cp to recursively go through all the subdirectories.

2. cmdline.txt

When I firstly made this article back in 2018 I didn't made root= option to work with PARTUUIDs. But it should work nowadays.

/dev/sdXY would work fine, but I faced situation when my external drive suddenly reconnected during runtime. It happened with my laptop many times and never with a Raspberry Pi, but mind that anyway. In this case it gets reconnected with another letter, e.g. was /dev/sda and became /dev/sdb.

cmdline.txt has boot options written in a single line. You need root=/dev/mmcblk0p2 rw part to change to your disk's partition, e.g. root=/dev/sda1 rw. And I found an option rootwait=5 to be needful, it waits for 5 seconds before booting so your drives gets connected for sure.

2. fstab

Raspberry Pi boots from a FAT partition on a SD card mounted to /boot directory. Following line must be in fstab file:

/dev/mmcblk0p1  /boot  vfat  defaults  0  0

It should be already there, but it is always good to be sure.