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

0. Introduction

In order to save a life of a SD card we can move a root from it to an external drive.

It is actually pretty easy to do. We just need to copy files from a SD card's root onto a disk's partition and to modify a cmdline.txt file in a /boot directory of a SD card.

Okay, let's move on.

1. Moving / to ext. drive

I assume that you already have your new root partition on disk mades and have it and SD card's boot and root partitions mounted to the temporary directories. Let they be /mnt/sdboot, /mnt/sdroot and /mnt/hdd. /mnt/sdboot partition will be needed further when we'll edit cmdline.txt. Yes, of course you can't do that on a living system, so you need a different machine.

To move files and links with all theirs 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. fstab

Since Raspberry Pi boots from a FAT partition on a SD card, needed line must be already there. But it's always good to double-check, so this is the line I'm talking of:

/dev/mmcblk0p1  /boot  vfat  defaults  0  0

3. cmdline.txt

I have to mention that there is one nuance exists. Unfortunately I didn't made it to work with neither UUIDs nor PARTUUIDs. AFAIK you need to place PART-/UUID this way root=PARTUUID=<PARTUUID>.

But /dev/sdXY works completely fine especially if you have only one disk attached so it can't change its name by any chance. I previously ran two disks on my Raspberry Pi and they worked like a charm tho. They has never swapped their names.

You need to change root=/dev/mmcblk0p2 rw at the beginning of the file to root=/dev/sdXY rw, where X is a letter of your drive and Y is a number of a partition.

Also you need to add an option rootwait=5 after root option. It seems like 5 seconds is perfectly enough for successful mounting of the drive. Full example:

root=/dev/sda1 rw rootwait=5

That's it. Now put an SD card and plug in a drive and let the juice flow the lanes! (I hope you didn't forget to unmount them first, hehe)