Reserve 16 bits of address space for the RaspPis, say 10.255.x.x, then give each Pi a static IP address either using a /boot config file or by making a 16-bit CRC of the serial number. Then provide a hosts file with all the 65536 pi addresses in and distribute that to all the machines that need to access them.

Surely I'm going to have to do this 7x over? - unless I'm missing something ?Each school has a different 10.x.y.0/24 address space so statics are completely out

Simon

Seeking help with Scratch and I/O stuff for Primary age children http://cymplecy.wordpress.com/ @cymplecy on twitter

1. Get the hostname stuff working and then use Reverse Address Resolution Protocol (RARP) to get the IP address. You'll need a RARP server sufficiently intelligent to work out what the IP addresses should be. There's some programming there, but it would be on your RaspPi or laptop. It's not trivial to write.

or

2. Use DHCP on the RaspPis to get a normal IP allocation and then broadcast the address and an identifier later in the boot process. A process on listening machines -- your RaspPi or laptop -- receives those broadcasts and constructs a host file with an entry of each RaspPi. That's also programming, but not as complex. Note that the identifier does not have to be the hostname. If you can get to email from the Raspis there's a quick and dirty halfway house here, but it doesn't do the laptop half and probably makes it more complex.

There's also the very easy bodge,

3. At any point during boot, copy the hostname to /etc/hostname, then reboot. Use SAMBA to propagate the IP address. It may work well enough, and it wouldn't need any R&D.

I assume you have a Pi or a laptop or something. That could run dnsmasq and implement a private network, say 192.168.x.x.

If your machine had two network connections you could route the private network to the school network. That might be useful if you wanted to monitor the traffic for debugging student work.

There is of course, an even simpler solution; get the RaspPis to announce their IP address in big letters, ask the kids what the numbers are and hand-edit your hosts file. They will probably keep the same IP address for days, weeks or months, so that only needs to be done once.

simplesi wrote:Every network the RPis would be connected to would need to have one setup for it

That isn't the problem the OP is trying to solve - his problem seems to relate solely to his classroom situation. What hostname the Pi has outside of the classroom is irrelevant, he's not going to be VNC'ing into the Pi's when they are outside of the classroom.

My original problem (and title of the thread is to read hostname from a config file held in /boot so that cards can be imaged and pre-seeded with a known hostname from a windows PC before being inserted into an RPi

Part 2 (not that part 1 has gone well ) was put all my RPi serialnums in the txt file in /boot and do the same trick of setting the hostname automatically following card imaging.

Simon

Seeking help with Scratch and I/O stuff for Primary age children http://cymplecy.wordpress.com/ @cymplecy on twitter

simplesi wrote:My original problem (and title of the thread is to read hostname from a config file held in /boot so that cards can be imaged and pre-seeded with a known hostname from a windows PC before being inserted into an RPi

Part 2 (not that part 1 has gone well ) was put all my RPi serialnums in the txt file in /boot and do the same trick of setting the hostname automatically following card imaging.

Simon

Right, but it's not possible (or likely) with current firmware, possibly you could add a start-up script to each device that reads a config file, but this is reinventing the wheel when other solutions being offered should work automatically.

So my question is this: Is #1 dependent on the devices being on a particular network? The justification you initially gave (now that I realise you are the OP...) for wanting a known hostname is that you would be accessing these devices over your classroom network using VNC - is this still the case, or do you want the hostname to be fixed for other reasons, and thus network independent ? Would the child need to know or care about their hostname when booting the Pi outside of the classroom environment?

If you have these devices connecting to a classroom network you're going to want to issue them with IP addresses (unless you give them static IP address which will cause problems when booting those devices outside of the classroom, but this is unlikely if you are cloning images), so it seems obvious to me that you would want to run a DHCP server of some kind, and since you could also combine this with a DNS server in the form of dnsmasq, it would solve your initial problem of allocating hostnames to specific devices based on MAC address.

It reads in the text from the /boot/cy_hostname.txt file and sticks it into /etc/hostname and /etc/hosts BEFORE hostname.sh is run (unless its just a fluke but it seems to repeatably work fine)So the answer to my original question seems to be solved:)

But before I move onto the "Why on earth are you trying to do it this way - are you mad???" discussions I've come across a little issue that was obviously clouding my earlier testsIf I change the contents of my /boot/cy_hostname.txt file and then issue a re-boot or shutdown comand - everthing is fine.

But if I edit the file do a cat /boot/cy_hostname.txt to make sure the edit is good and then just pull the power off - my edit is lost!

The contents of /boot/cy_hostname.txt are the same as before the edit!

So it looks something like the /boot folder is being cached and if you just pull the power - its not re-written back to the card (or something like that anyway)

regards

Simon

Seeking help with Scratch and I/O stuff for Primary age children http://cymplecy.wordpress.com/ @cymplecy on twitter

So my question is this: Is #1 dependent on the devices being on a particular network? The justification you initially gave (now that I realise you are the OP...) for wanting a known hostname is that you would be accessing these devices over your classroom network using VNC - is this still the case

I want my RPis to keep the same name so I can mark each PI with a number 1- 6 and know that they will respond to say pi1, pi2,pi3 etc no matter which school I take them to or whether they are on my desk back at home.

If you have these devices connecting to a classroom network you're going to want to issue them with IP addresses (unless you give them static IP address which will cause problems when booting those devices outside of the classroom, but this is unlikely if you are cloning images), so it seems obvious to me that you would want to run a DHCP server of some kind, and since you could also combine this with a DNS server in the form of dnsmasq, it would solve your initial problem of allocating hostnames to specific devices based on MAC address.

I'm the network manager of these schools - we have DHCP servers - I just want them to pick up any IP address the DHCP server wishes to allocate to them - I don't want to bother knowing what these are - I just want to use pi1,pi2,pi3 etc.

I could configure each school and add DNS records etc etc etc but I like the easy life.

Since the serial numbers of my RPi's won't change - it seemed liek a good idea to just have a simple lookup config file in /boot with all 6 serial numbers in it and have each RPi effectively auto-allocate their own name even if I re-image the SD card (plus I thought it was a good script writing exercise )

regardsSimon

Seeking help with Scratch and I/O stuff for Primary age children http://cymplecy.wordpress.com/ @cymplecy on twitter

So with that script, if Pi #6 is booted with the SD card from Pi #5, Pi #6 will take on the Pi5 hostname - presumably this isn't what you want?

In which case /boot/cy_hostname.txt needs to contain all of the possible hostnames, keyed against something unique to each Pi device, such as serial number (MAC address would also work as this is based on the serial number, but serial number is probably easier to obtain than the MAC address before the network is up).

Selecting the correct hostname based on serial number should be trivial:

The difficulty you will have now is that just because the RaspPi knows its own name, it doesn't mean that your computer will know it. SAMBA should solve that, if you have it installed on the RaspPis, but it can take a while to propagate the names.

you probably don't want to call insserv directly, instead use "update-rc.d sickbeard-daemon defaults" - the details are in "man insserv".

I'd really like to have a Raspbian/Debian guru tell me which of the many contradicting pieces of info on this subject are correct

The difficulty you will have now is that just because the RaspPi knows its own name, it doesn't mean that your computer will know it. SAMBA should solve that, if you have it installed on the RaspPis, but it can take a while to propagate the names.

MY RPi doesn't have a nice integrated button that initiates a clean shutdown and its a lot quicker than typing sudo shutdown

Seriously though, if I'm sitting at a plain desktop with nothing open then I just switch it off and on again at the mains as its the quickest method to reboot. ) Along with 100,000s of others I'd suspect )

I hadn't realised how long the RPi takes to finally write its cache to disc - it must be going for a world record - certainly exceeds my attention span anyway

But now I know, I will be better in future

Simon

Seeking help with Scratch and I/O stuff for Primary age children http://cymplecy.wordpress.com/ @cymplecy on twitter

Linux is Unix. Theoretically Unix used to cache its disk forever. After all, you never know when the cache might be obsoleted by data you overwrite it with. In practise, there was generally a process that sync'd the filesystems every minute. I'm not sure how Linux works, but it's probably something similar. Most Linux filesystems have journals that allow unfinished updates to be completed if the system crashes. However FAT does not have a journal.

Windows has to cope with users who pull the plug without shutting down properly. So it will flush the cache to disk more frequently.

I've added in a bit extra so that if the machines serial number is not in the serial_hostname.txt file - it will be automatically added (and its serial number used as the name) so that I can semi-automatically harvest my RPi serial numbers and all I'll have to do is edit the file once its been in all machines.

regardsSimon

Seeking help with Scratch and I/O stuff for Primary age children http://cymplecy.wordpress.com/ @cymplecy on twitter

Still not fully there yet Came to use the setup in proper use - swapped my working SD card from one Rpi (where name was pi01) to another (that should have changed it to pi02 based on serial number) but its didn't change

When I VNCed into the RPi, (Using pi01 name) /etc/hostname was showing pi02 so the script had run but seemingly not before Samab had used the old hostname.

I rebooted again and it appeared as pi02 on the network so at least its half working

Simon

Seeking help with Scratch and I/O stuff for Primary age children http://cymplecy.wordpress.com/ @cymplecy on twitter