Thank-you for the kind words, here we go, grab a cuppa - this is a bit of a long one.
ONLY DO THIS IF YOU ARE CONFIDENT and PREFERABLY have a SCREEN available initially !
Setup your PiDrive partitions so you have a “finished” setup.
Note that for this, I used all the default options, so I ended up with:
1 - Raspbian with GUI (RPID-RASP)
2 - Data partition
3 - Raspbian Lite 8GB (RPID-PS1)
4 - Raspbian Lite 8GB (RPID-PS2)
5 - Raspbian Lite 16GB (RPID-PS3)
6 - Raspbian Lite 16GB (RPID-PS4)
7 - Raspbian Lite 32GB (RPID-PS5)
8 - Raspbian Lite using remainder of disk (RPID-LITE)
Once the partitions were created, I logged into each of them and assigned each partition a unique hostname (set with raspi-config) in UPPERCASE - shown in brackets above (this is important for the script) if they seem strange it’s RaspPIDrive-ProjectSpace1 etc…
Make the names something meaningful to you !
I ended up in my last partition (RPID-LITE) and worked from there (I was ‘remote’ from the PiDrive now)
Next we need to get the data we need to identify the partitions to boot to.
You MUST be careful with these numbers, there are two main listings, one starting /dev/mmcblk0p{number} and another starting /dev/sda{number}
My highest number in /dev/sda was 13, in /dev/mmcblk0p it was 12 - this was (I think) because of the Data partition (dev/sda7 for me - I could tell from the size) Please see dwcsjca’s excellent post for details.
So, let’s create the data file - for now it can be created in $HOME in whichever partition you are working in.
It is a simple text file with two columns, tab separated - HOST and PARTITION ID:
This is what my file looks like, it’s worth sorting the spacing out to make it look nicer, so the single digits are tab + space
RPID-RASP 6
RPID-PS1 7
RPID-PS2 8
RPID-PS3 9
RPID-PS4 10
RPID-PS5 11
RPID-LITE 12
There’s nothing else in this file, but it can be changed if things change on your PiDrive, hence using the data file rather than “hard coding” it into the script.
What you call the file doesn’t matter, but you will have to change the script to suit - I called the file “partids” (partition IDs) and this is the name the script expects to find (but you can of course change the script)
Now we need to put the script and supporting data file somewhere that we can access from ALL of the partitions, we don’t want to duplicate effort.
I chose to use the Data partition for this.
There’s a subtle difference in the mounting of partitions depending on your choices of installation, what I found was that the first installation, the full blown Raspbian GUI, mounted ALL of the partitions, including the Data partition.
On each of the partitions that does not mount the Data partition, we need to create a mount point and mount the Data partition there.
I chose to create a mount point “/media/pi” for all the other partitions as below:
{data_partition} {mount_point} {options} (sorry, I can’t figure out how to do greater than/less than symbol ?)
sudo view /etc/fstab
add the following line to the bottom of the file, changing /dev/sda7 and/or /media/pi to suit:
/dev/sda7 /media/pi ext4 defaults,noatime 0 2
Next, create the mount point, grant permissions for user pi and mount the partition:
sudo mkdir /media/pi
sudo chown pi:pi /media/pi
sudo mount /media/pi
Now, I want two directories here, bin (for the script) and data (for the data file) - this we do as user pi
cd /media/pi
mkdir bin data
We can now put/create our data file (eg. partids) in /media/pi/data and put/create the script (eg. reboot-drive) in /media/pi/bin
NOTE: the reboot-drive script is expecting the board type to be bcm2709.
If your board is different, you MUST change the line “ARCH=bcm2709” in the script to suit.
We’re now going to take advantage of a bit of default behaviour to save ourselves some work
In /media/pi/bin, we will create another script, let’s call it “make-links”
copy and paste the following (remove the single ticks before the hash sign, it just tidies up the format in the post !):
'#!/bin/bash
echo “I am here pwd
”
ln -s pwd
$HOME/bin
'# move up and over
cd …/data
echo “I am now here pwd
”
ln -s pwd
$HOME/data
cd -
then make sure it’s executable We’ll come back to this in a moment.
We should now have:
/media/pi/bin/reboot-drive (the main script)
/media/pi/bin/make-links (this does what it says and will become clear later)
with 755 perms
/media/pi/partids
with 644 perms
from the /media/pi/bin directory, execute the make-links script:
./make-links
This will create symbolic links in pi’s home directory
if we now “cd” (to $HOME) we should see:
lrwxrwxrwx 1 pi pi 13 Feb 23 01:07 bin → /media/pi/bin
lrwxrwxrwx 1 pi pi 14 Feb 23 01:07 data → /media/pi/data
So, log out and back in and check that you path has been modified, the default .profile will add $HOME/bin to the start of the $PATH if $HOME/bin exists, which of course it does now - we have a link there
if we now type “reboot-drive” (we are in /home/pi now) we should get something like this:
pi@RPID-LITE:~ $ reboot-drive
checking datafiles…OK
Current partition :
RPID-LITE 12
Reboot options:
HOST ID
RPID-RASP 6
RPID-PS1 7
RPID-PS2 8
RPID-PS3 9
RPID-PS4 10
RPID-PS5 11
RPID-LITE 12
Choose number:
enter a valid number and press enter (eg.)
Choose number: 11
setting RPID-PS5 for next reboot
Partition set to 11 = OK
now ‘sudo reboot’ to restart
OR rerun the script to change your choice !
pi@RPID-LITE:~ $
So, do a restart and make sure you boot into your chosen partition
I started off from (my) Partition 12, so worked back through the list using the script each time.
For each remaining partition;
1 - boot into it
2 - make the mount point (/media/pi) if it doesn’t exist
3 - chown the mount point (see above)
4 - edit /etc/fstab to mount the Data partition (see above)
5 - mount the directory (see above)
Once the directory is mounted, the bin and data directories will be visible, so
cd /media/pi/bin
./make-links
now log out and back in and enter
reboot-drive
If everything’s worked, you should be looking at a familiar menu, so carry on as above until done.
Note that I found the default Raspbian install already had a convenient mount point, so I just navigated to the (created) bin directory there, and ran ./make-links (it should work out the changes)
I tested this reasonably thoroughly for several cycles through, the last loop I ran through, I used ssh-copy-id (eg. ssh-copy-id pi@rpid-lite.local) to setup SSH key exchange, then ran the script and worked through the list until all of the partitions were “SSH’ed”
A final note, use at your own risk, the code in reboot-drive is pretty well commented - so have a look at it BEFORE you use it. I have DELIBERATELY chosen NOT to give a reboot option directly from the script, it is a simple change to make, but I think having a chance to check before typing ‘sudo reboot’ is sensible. Look at what the script has told you it’s going to do if you reboot.
I have tried to cover most errors with input that I can, but I may have missed something - you have been warned.
Ah, just found out I can’t upload files - so getting the script up’s going to be a problem - can I email it to someone to post ?
Congratulations for sticking with this - it sounds worse than it is
Good luck
Simon
Off to set this up on a brand new PiDrive Node Zero now