Using a Foundation drive headless - questions

OK, so I’ve got my Foundation Drive formatted and connected to one of my RPi3’s and it’s working flawlessly. Installed the primary Raspian Pixel (updated and installed VNC) and four more Spaces.

Since I won’t be able to see the OS partition choice screen on VNC - how do I change which OS loads on a headless Pi?

I’d like to use the various Spaces for separate projects, but since some are robots and some will be camera based, can I select, prior to reboot, which OS/Space loads on the next boot? I know it will boot into whichever Space was being used unattended, but what about switching?

I didn’t think this would be that unusual of a question. In fact, I was surprised to see others had not asked it before.
Any hints, folks?

Hi, sorry for the delay. There’s no user-friendly way to switch the launch OS remotely, but after discussing with the NOOBS developer, you can try below.

The game plan:
Prepare: identify the partition numbers corresponding to the OSes you’ve loaded (using fdisk and some guessing, and possible trial ‘n’ error to confirm the mapping).
Execute: to change OS while running the system, ssh into it, change the parameter associated with the reboot partition, reboot.

To test this, I did a new install with Raspbian (PIXEL) and one 8GB Project Space, with Pi3 connected via Ethernet (WiFi could be done too).

Launch any installed OS with terminal access, then enter the following commands in bold {comments in brackets}::

sudo -i
ifconfig
{review the output of ifconfig to identify the Pi’s IP address so you can ssh into it later from a remote computer}
fdisk -l

{my fdisk output is below}

Device Boot Start End Sectors Size Id Type
/dev/mmcblk0p1 8192 4371093 4362902 2.1G e W95 FAT16 (LBA)
/dev/mmcblk0p2 4371094 4714495 343402 167.7M 5 Extended
/dev/mmcblk0p5 4374528 4440061 65534 32M 83 Linux
/dev/mmcblk0p6 4440064 4575231 135168 66M c W95 FAT32 (LBA)
/dev/mmcblk0p7 4579328 4714495 135168 66M c W95 FAT32 (LBA)

Disk /dev/sda: 232.9 GiB, 250025607168 bytes, 488331264 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xc0964e0f

Device Boot Start End Sectors Size Id Type
/dev/sda1 2048 2121093 2119046 1G e W95 FAT16 (LBA)
/dev/sda2 2121094 488038399 485917306 231.7G 5 Extended
/dev/sda5 2121728 2187261 65534 32M 83 Linux
/dev/sda6 2187264 471654397 469467134 223.9G 83 Linux
/dev/sda7 471654400 488038399 16384000 7.8G 83 Linux

{in above, mmcblk0p5 is (always set as) NOOBS settings partition, sda7 (7.8G, Linux) is the 8GB Project Space and sda6 (223.9G remaining space, Linux) is Raspbian PIXEL. If you have multiple Project Spaces with the same capacity, you may need to do trial ‘n’ error using the echo command below, or they may be in the same order as presented in the OS install menu (I haven’t tested it). Launch the desired item by specifying the corresponding partition number in the echo command below. Note that it’s actually the corresponding boot partition (e.g. /dev/mmcblk0p6 for sda6 for Raspbian in this case) that gets launched}

{Using a remote computer, ssh into the Pi (via IP address obtained above) and enter the following commands}

echo {partition# corresponding to desired OS} > /sys/module/bcm2709/parameters/reboot_part

reboot

{for example, to launch partition 6 (/dev/mmcblk0p6, Raspbian in my setup) enter:}
echo 6 > /sys/module/bcm2709/parameters/reboot_part
reboot

{done}

Note that the module identifier bcm2709 is related to the Pi version (in my case Pi3). A different identifier (e.g. bcm2708) might need to be used instead- I haven’t tested beyond my particular Pi3 setup.

As mentioned above, it might take some trial and error, using the echo command with different partition numbers, to confirm the partition# corresponding to each OS you’ve loaded, but once you’ve mapped it out it’s not too bad switching via remote access.

I’ve only tested it briefly, but it seems to work. Please try it out as an experiment and confirm it works in your system before committing it to anything critical!!

Hope this helps.

Thanks.

I found this post after buying a second Foundation drive setup, and as I spend most of my time “headless” I thought I would put some time in testing this out.
Thanks to dwcsjca for inspiring my efforts, I’m very pleased to say it seems to work very well, so I decided to write a simple script to enable me to do all this rather simply.
In essence, I have a data file which lists the partitions, each of which has a unique hostname and partition number, then run a script which picks up the data file and presents choices, simply select the partiton number from the list, then writes out to the parameter file and prompts the user to restart.
The data file and scripts reside on the Data partition and this is mounted and softlinks created in each partition so it can be accessed from any active partition.
Here’s what it looks like in operation:

pi@RPID-RASP:~ $ reboot-drive
checking datafiles…OK

Current partition :
RPID-PS1 7

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: 12
setting RPID-LITE for next reboot
Partition set to 12 = OK
now ‘sudo reboot’ to restart
OR rerun the script to change your choice !
pi@RPID-RASP:~ $

(the formatting’s gone a bit off I’m afraid)

If anyone’s interested, I’ll put the scripts up and more details ?
Cheers
Simon

Hi Simon, this is great work- thanks for bringing it to the forum! Yes, please provide scripts and details- this is super-useful, particularly with our platforms like PiDrive Node Zero that are intended for headless applications.

I’m glad my clunky instructions motivated you to create a great solution! :wink:

Thanks a lot!!

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 :wink:

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 :wink:

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 :wink: 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 :wink:
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 :relieved:

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 :grin:

Good luck
Simon

Off to set this up on a brand new PiDrive Node Zero now :grin:

OK, here’s the ‘reboot-drive’ script in it’s entirety

#!/bin/bash
# choose partition to reboot
# board type may change, so let's set it here
# change this to suit your requirements
ARCH=bcm2709
# required files for operation
DATFILE=${HOME}/data/partids
REBOOT_FILE=/sys/module/${ARCH}/parameters/reboot_part
# check files exist !
echo -n "checking datafiles..."
if [[ -f ${DATFILE} && -f ${REBOOT_FILE} ]]
then
  echo "OK"
else
  echo "ERROR!"
  echo "Please check these files exist:"
  echo "${DATFILE}"
  echo "${REBOOT_FILE}"
  exit 2
fi
# Let's show the 'menu'
# we'll show the current partition first
# then show the data file for the options
echo "=================="
echo "Current partition :"
echo "------------------"
echo "`grep -w ${HOSTNAME} ${DATFILE}`"
echo "=================="
echo "Reboot options:"
echo "------------------"
echo "HOST            ID"
echo "------------------"
cat ${DATFILE}
echo "=================="
echo -n "Choose number: "
# get the response
read CHOICE
# and check for various conditions
# NOTE: we DO NOT reboot in this script - there's not enough error
# checking, so I'm chickening out of doing that without a chance
# to abandon the changes or make another choice. Of course, if you
# want to do that, you can just modify the script - at your own risk !
if [ "${CHOICE}." = "." ]
then
  # user just pressed enter
  echo "no choice"
else
  # we have input - check if we can match the choice
  NEXT=`grep -w ${CHOICE} ${DATFILE} | cut -f1`
  if [ "${NEXT}." = "." ]
  then
    # we couldn't match the choice
    echo "ERROR: Invalid choice"
  else
    # we matched, but this could be on HOST OR ID, but only ID is valid
    echo "setting ${NEXT} for next reboot"
    # we're going to suppress the output and supply our own feedback
    # for debugging, remove ">/dev/null 2>&1" from the end of this line
    echo ${CHOICE} | sudo tee ${REBOOT_FILE} >/dev/null 2>&1
    if [ $? -ne 0 ]
    then
        # most likely the HOST was chosen, not the ID number ?
        echo "ERROR: unable to update value!"
        echo "Perhaps you didn't enter a number ?"
        exit 4
    else
        # we managed to write the value out to the file OK
        echo "Partition set to `cat ${REBOOT_FILE}` = OK"
        echo "now 'sudo reboot' to restart"
        echo "OR rerun the script to change your choice !"
    fi
    # we couldn't match the choice
  fi
  # user just pressed enter
fi

And pleased to say this is all working on Pi Node Zero too :grinning:
Did the basic install from the card and rebooted into the first Project Space, then completed the rest remotely for all the partitions.
A couple of things I noticed:
1 - ARCH=2708 was what I needed for the Zero
2 - I can’t be 100% sure, but I suspect rebooting too quickly with the Zero doesn’t always bring up the partition you were expecting. I believe this may be a sync (memory to file write) delay, so added a sync command into the script (doesn’t need special privileges) and issued another before the reboot having waited for around a minute. Doing this seemed to give me the expected results, but due to the noticeable performance difference between the Zero and a 2 or 3, I haven’t done as many reboot with this device yet.
Cheers
Simon

Hi Simon- thanks a lot! The detailed instructions are great, plus the well-commented code- I’ll try it this weekend- this will be really cool!

I can envision a setup where the Node Zero (or Smart Cable Module with HDD or flash drive) is used as a 24/7 surveillance or time-lapse camera, stand-alone (not connected to LAN/internet). One Project Space can be the camera recorder and another can be a webserver with WiFi AP so you can retrieve video files.

I recently did two projects for headless servers with multiple boot modes that this will be perfect for. One is a local apt mirror (raspbian and raspberrypi apt package repositories)- one boot mode to download/update the packages and another to serve the packages. The other project is a RACHEL-Pi server- one boot mode for downloading RACHEL modules and another to serve the modules. These projects are described below.

Thanks!

Hi dwcsjca - thanks for your comments (and of course the original inspiration :wink: )
I would be very interested to hear how you get on ?
I have a “normal” PiDrive (250GB/Pi2) running as an APT server and this works very well - I have around 20 Pi 2 devices on my LAN so it saves me a HUGE amount of internet bandwidth. It also has the advantage that I can just check the output of the daily cron apt-mirror job to see if there are any updates, then run a distributed shell script to do the updates/upgrades. This is just a standard Jessie Lite install as I wanted ALL of the space on the drive available for the files (currently around 80GB), but the point is the “box” provides a very neat package for it all.
Now I’m “settling in” I’ll start having a look at some of these other projects.
I would like to pass on my thanks to yourself and the other WD folks behind the forum, and the products - it’s a refreshing stance for a big manufacturer to be taking these days !
Cheers
Simon