extends article.pug

block append head
	link(rel='canonical' href='https://arav.top/stuff/article/rpi_root_on_external_drive')

block article
	header
		h2 How to move a root from SD card to external drive on Raspberry Pi
		div.menu
			a(href='/stuff#articles') Go back to articles list
			time(datetime='2022-05-19') 19 May 2022
		nav
			h3 Contents
			ol
				li #[a(href='#art-1') Introduction]
				li #[a(href='#art-2') Moving / to an external drive]
				li #[a(href='#art-3') cmdline.txt]

	h3#art-1 #[a(href='#art-1') 1. Introduction]
	p 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 #[s SystemD]GNU/Linux distribution for that.
	p 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.
	p 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.
	p Second thing is that you need to edit one file called #[a(href='#art-3') cmdline.txt].

	h3#art-2 #[a(href='#art-2') 2. Moving / to an external drive]
	p 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: #[code mkfs.vfat -F32 /dev/sdXY].
	p Now you can unpack your distro to your disk's root partition and move files from #[code /boot] to a microSD card.
	p If you have a system previously installed on a microSD card, then move the files to a new root partition using #[code cp -a /path/to/sdcard/root/* /path/to/new/root]. #[code -a] stands for archive, which recursively copies everything preserving all the attributes and links.
	p Then after repartitioning of a microSD card, move content of a #[code /boot] directory to a new boot partition you made on a microSD card using #[code mv /path/to/new/root/boot/* /path/to/sdcard/new/boot].
	p Of course, don't forget to add a boot mount to a #[code fstab] file: #[code UUID=xxx  /boot  vfat  defaults  0 0].

	h3#art-3 3. #[a(href='#art-3') cmdline.txt]
	p So, the main part is done, now it is time to tell Raspberry where is a root partition.
	p In a #[code cmdline.txt] file we need to change #[code root=] part. Now it'll look like #[code root=/dev/mmcblk0p2 rw rootwait], and we need to put our drive's root partition instead of that, e.g. #[code root=/dev/sda1 rw rootwait].
	p Instead of #[code /dev/sdXY] you may try to use a #[code PARTUUID=], but it didn't work for me, fully it would look like #[code root=PARTUUID=XXXX].
	p And, #[code UUID] and #[code PARTUUID] can be gotten with #[code blkid] utility.
