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

0. Introduction.

Raspberry Pi is known for how it wears off the SD cards. Thankfully you can move the root off the SD card to an external drive and leave there just a boot partition. I'm gonna use a SystemDGNU/Linux distribution for that.

1. Moving / to an external drive.

I assume that you have your drive partitioned already. Create the temporary directories for a SD card's boot and root partitions and for a drive. Mount the partitions and issue a command cp -a path/to/sdcard/root/* path/to/drive. -a stands for archive. Which recursively copies everything preserving all the attributes and links.

1a. If you're doing a fresh install.

Then you just install it right on a drive. And then move files from /boot to a SD card's boot partition. Like that: mv path/to/boot/* path/to/sdcard. Keep in mind that the boot partition should be formatted in FAT32.

2. cmdline.txt

In a cmdline.txt. file we need to change root= part. Now it'll look like root=/dev/mmcblk0p2 rw rootwait, and we need to put our drive's root partition instead of that, e.g. root=/dev/sda1 rw rootwait.