Page 1 of 1

Passing options to OS using only files in the boot partition

Posted: Fri Feb 07, 2014 8:24 pm
by socialdefect
At the moment I'm working on a new Pi managing tool for Mac that will be replacing PiWriter and PiCloner. I'm also adding some extra features that require detecting the Pi's IP address. This is where I'm having some problems, for example:
The need to install extra software on the Mac, scans that take quite some time even on a small network or require interaction or at least basic networking knowledge from the end user. Since I'd like to keep things as simple as possible these options will not make it into the app.

Another way of handling this would be by using a reverse method by starting a ssh server on the Pi that set's up a proxy tunnel with the osX client since determining the client's IP is simple and fast. Since I'd like to do this without the need for any user interaction and make it compatible with any RasPi OS image the next problem has occured. osX cannot mount ext4 partitions without any extra software being installed first which leaves me with only the files on the boot partition. I hoped that I could edit the config.txt or cmdline.txt files to pass an alias to the shell so I can manipulate the ssh command but this does not seem to work.

Is there a way to pass extra config to the shell by using only the files in the boot partition????

Re: Passing options to OS using only files in the boot parti

Posted: Thu Feb 13, 2014 6:03 am
by socialdefect
Anyone any thoughts on this issue??

Re: Passing options to OS using only files in the boot parti

Posted: Thu Feb 13, 2014 8:41 am
by DeeJay
This tutorial show how to use /boot/cmdline.txt to pass kernel parameters at boot time. Maybe you could find a way of exploiting that technique for attributes other than the ip address? This isn't quite the same as 'passing an alias to the shell', but it might give you a clue?

Another possible approach: there is an option in the NOOBS installer to boot into a system with the Scratch application running. I don't know how that is implemented, but if you could reverse-engineer it you might be able to adapt that? You could look at the NOOBS github repository for implementation details.

Re: Passing options to OS using only files in the boot parti

Posted: Thu Feb 13, 2014 11:01 am
by ghans
I am too in favor of a method integrating with NOOBS.
Sooner or later NOOBS will have to solve problems like this
and duplication of effort should be minimized.


ghans

Re: Passing options to OS using only files in the boot parti

Posted: Fri Feb 14, 2014 1:59 pm
by socialdefect
As it turns out the whole issue is not at all as complicated as I thought. Afther puzzling for some hours I went seeking for help in the Kali Linux IRC where all the networking guru's hang out. As it turns out the first approach I had attempted was the right one, the version of the arp binary in my osX install is extremely outdated, is extremely slow and needs some extra help.

The solution:
Check the arp cache and filter out the static part of the Pi's mac address and then print the column holding the ip address. If the device is not found then use ping/arping/nmap or some other tool and use it to ping the network connected to your PC and Pi.

Filter the pi's ip from the arp cache:

Code: Select all

/usr/sbin/arp -a | grep 'b8:27:eb:' | awk '{ print $2 }' | tr -d '()'
If the device is not cached yet detect the subnet:

Code: Select all

NETWORK=`ifconfig en0 | grep 'inet ' | awk '{ print $2 }' | cut -c -10`
If you don't have nmap installed you can use ping: (much slower than nmap)

Code: Select all

for ip in {1..254}; do
        ping -c 1 ${NETWORK}$ip>/dev/null
        [ $? -eq 0 ]
        echo "${NETWORK$ip" || : 
done
Use nmap to list active ip's:

Code: Select all

nmap -sP  ${NETWORK}/24 | awk '{ print $5 }' | grep  ${NETWORK}
Once the Pi's ip has been pinged it's info can be found in the arp cache. So if you have to use the ping option in a script it would be wise to run it in the background while monitoring if the device has been found using arp.

It took me a while to figure it all out but I guess this approach might become quite stable once it's wrapped in the GUI.
Since I thought finding a different way to connect to the Pi would be less likely to fail I've started working on a wrapper daemon for SSH that will start a tunnel to the client. This way you're only required to run the network discovery once which speeds-up the process a lot and is also just a really nice feature that makes SSH a bit more easy to use for beginners.

Re: Passing options to OS using only files in the boot parti

Posted: Sat Feb 15, 2014 10:25 am
by ghans
Glad you found a solution. IMHO way neater than hacking
something into NOOBS.

ghans