User avatar
GTR2Fan
Posts: 1601
Joined: Sun Feb 23, 2014 9:20 pm
Location: South East UK

Help With BASH Script Boot Menu Please?

Wed Mar 05, 2014 11:11 am

Hi,

I've recently started running my favourite three Pi OSes from an external USB hard drive but, at the moment, the only way I can choose which OS to boot is by SSH-ing in to the Pi from my Windows PC using Putty.

The three OSes are mounted as '/dev/sda2', '/dev/sda3', and '/dev/sda4', so to simplify matters, I've created directories on the boot SD card named 'sda2', 'sda3', and 'sda4' containing copies of the original boot files for the relevant OS with appropriate 'root=' modifications.

At present, to change OS, I SSH in with Putty and type...

Code: Select all

cd /boot
sudo rm *.*
cd sda2
sudo cp *.* /boot
sudo reboot
...to launch Raspbmc,

Code: Select all

cd /boot
sudo rm *.*
cd sda3
sudo cp *.* /boot
sudo reboot
...to launch Raspbian, and

Code: Select all

cd /boot
sudo rm *.*
cd sda4
sudo cp *.* /boot
sudo reboot
...to launch RetroPie.

Unfortunately, I have zero knowledge of BASH scripting, but I was wondering if it's possible to write a simple text-based menu system in BASH that goes on the SD card to allow this to be achieved directly from the Pi, both on initial boot-up, and on exit from each OS.

For example...

Code: Select all

Raspberry Pi Boot Menu
======================
    PRESS A KEY... 
     1/ Raspbmc
     2/ Raspbian
     3/ RetroPie
======================
...with a 10 second pause before launching the previously loaded OS if no key is pressed.

If someone is prepared to help me with the scripting then I'd be happy to throw together a guide for the Raspberry Pi forum to help others achieve the same thing. :)
Pi2B Mini-PC/Media Centre: ARM=1GHz (+3), Core=500MHz, v3d=500MHz, h264=333MHz, RAM=DDR2-1200 (+6/+4/+4+schmoo). Sandisk Ultra HC-I 32GB microSD card on '50=100' OCed slot (42MB/s read) running Raspbian/KODI16, Seagate 3.5" 1.5TB HDD mass storage.

User avatar
DougieLawson
Posts: 39121
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Help With BASH Script Boot Menu Please?

Wed Mar 05, 2014 11:28 am

Take a look at /usr/bin/raspi-config that's a bash script that has all sorts of text based menus.

Code: Select all

  if [ $ASK_TO_REBOOT -eq 1 ]; then
    whiptail --yesno "Would you like to reboot now?" 20 60 2
    if [ $? -eq 0 ]; then # yes
      sync
      reboot
    fi
  fi
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

User avatar
GTR2Fan
Posts: 1601
Joined: Sun Feb 23, 2014 9:20 pm
Location: South East UK

Re: Help With BASH Script Boot Menu Please?

Wed Mar 05, 2014 11:33 am

Thank you. I hadn't realised that was generated by a BASH script. I'll take a look and have a fiddle. :)
Pi2B Mini-PC/Media Centre: ARM=1GHz (+3), Core=500MHz, v3d=500MHz, h264=333MHz, RAM=DDR2-1200 (+6/+4/+4+schmoo). Sandisk Ultra HC-I 32GB microSD card on '50=100' OCed slot (42MB/s read) running Raspbian/KODI16, Seagate 3.5" 1.5TB HDD mass storage.

User avatar
GTR2Fan
Posts: 1601
Joined: Sun Feb 23, 2014 9:20 pm
Location: South East UK

Re: Help With BASH Script Boot Menu Please?

Wed Mar 05, 2014 3:44 pm

Well, I've made a little headway. :P

After attempting to simultaneously learn BASH and write it, I've temporarily given up on the idea of writing an all-in-one script to deal with the above, and prepended '#!/bin/bash' to all of the above code snippets and saved them out as files named 'os1', 'os2', and 'os3' respectively into all three OS boot file directories.

At least I can now just type, for example, '/boot/os1' at a terminal prompt to reboot in to Raspbmc.

I guess that's about as far as my current level of numptiness is going to get me. :oops:
Pi2B Mini-PC/Media Centre: ARM=1GHz (+3), Core=500MHz, v3d=500MHz, h264=333MHz, RAM=DDR2-1200 (+6/+4/+4+schmoo). Sandisk Ultra HC-I 32GB microSD card on '50=100' OCed slot (42MB/s read) running Raspbian/KODI16, Seagate 3.5" 1.5TB HDD mass storage.

Return to “Other programming languages”