1
0
Fork 0
dwelling-home/web/articles/rpi_root_on_external_drive.md

38 lines
2.2 KiB
Markdown

### Contents
1. [Introduction](#art-1)
2. [Moving / to an external drive](#art-2)
3. [cmdline.txt](#art-3)
### 1. Introduction {#art-1}
Raspberry Pi is known for how it wears off the SD cards (that's mostly because of logs). 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 ~~SystemD~~GNU/Linux distribution for that.
There's nothing different from a regular partitioning of the drives as you usually do when install a Linux distro. Just two things you need to do and be aware of.
First thing is that Raspberry Pi models up to version 3 rev B+ can boot only from a microSD card. Hopefully, that changed with release of 4th version.
Second thing is that you need to edit one file called [cmdline.txt](#art-3).
### 2. Moving / to an external drive {#art-2}
So you have your disk(s) partitioned and mounted. A boot partition on a microSD card should be formated to FAT32. You can do this with this command: `mkfs.vfat -F32 /dev/sdXY`.
Now you can unpack your distro to your disk's root partition and move files from `/boot` to a microSD card.
If you have a system previously installed on a microSD card, then move the files to a new root partition using `cp -a /path/to/sdcard/root/* /path/to/new/root`. `-a` stands for archive, which recursively copies everything preserving all the attributes and links.
Then after repartitioning of a microSD card, move content of a `/boot` directory to a new boot partition you made on a microSD card using `mv /path/to/new/root/boot/* /path/to/sdcard/new/boot`.
Of course, don't forget to add a boot mount to a `fstab` file: `UUID=xxx /boot vfat defaults 0 0`.
### cmdline.txt {#art-3}
So, the main part is done, now it is time to tell Raspberry where is a root partition.
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`.
Instead of `/dev/sdXY` you may try to use a `PARTUUID=`, but it didn't work for me, fully it would look like `root=PARTUUID=XXXX`.
And, `UUID` and `PARTUUID` can be gotten with `blkid` utility.