The default pi kernel may or may not have the right drivers built in to mount the external drive without the root filesystem,1 so the first thing you'll have to do is investigate that and if it doesn't, build a kernel that does. It's probably okay (various blog posts online imply a custom kernel is not generally needed), but this is important to note just in case.
Once you have that, make a copy of your primary partition (the 2nd one) from the SD card onto the HDD to test with. Do not do this naively while the pi is running. It should reflect the state of the filesystem while the system is off, so take the card out of the pi to copy it.
If you make the copy by duplicating the entire filesystem, you'll need to change the UUID, since otherwise it will be the same as the second partition on the SD card. To get the UUID under linux, if the partition is /dev/sdb3
:
> blkid /dev/sdb3
/dev/sdb3: LABEL="whatever" UUID="8f30e12b-8a7c-4121-86f7-1134f39c66d5" TYPE="ext4"
If the UUIDs are the same, you need to change the one on the HDD. To do that: tune2fs -U random /dev/sdb3
.
Next, edit cmdline.txt
from the first partition on the SD card (the one that gets mounted as /boot
). Change this part:
root=/dev/mmcblk0p2
to:
root=UUID=c2b2016e-629a-4010-bf1f-563fd4c50e72
Or whatever the new UUID is for the HDD partition. Don't accidentally add a newline into this file or anything. If all this doesn't work, all you have to do is change that back to what it was (/dev/mmcblk0p2
).
The reason you need to use the UUID instead of the device node is unless you add a udev
rule to set it, the device node of the HDD partition is unpredictable (although it may often be the same).
Finally, before you try this, edit the /etc/fstab
on the HDD partition. Change this:
/dev/mmcblk0p2 /
to:
UUID=c2b2016e-629a-4010-bf1f-563fd4c50e72 /
Leave everything else the same.
1. Modules can be either built-in or loadable. Loadable modules are .ko
files in /lib/modules
directories, which are part of the root filesystem. A just loaded kernel can't mount the root filesystem if it requires stuff from /lib/modules
in order to do it. Those modules either have to be built-in to the kernel, or put into an initramfs.