I have a set of 6 RPi that I'm going to be taking around 7 schools for after school/clubs ICT Lessons.
And that's ignoring going to RaspberryJams and testing at home
So I really would like to avoid 7xsetting up DHCP servers
Simon
I have a set of 6 RPi that I'm going to be taking around 7 schools for after school/clubs ICT Lessons.
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.
Wouldn't running dnsmasq (on another, "master", Pi server) solve this problem?
simplesi wrote:Every network the RPis would be connected to would need to have one setup for it
simplesi wrote:My original problem (and title of the threadis 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
#! /bin/sh
### BEGIN INIT INFO
# Provides: cy_hostname
# Required-Start: $local_fs
# Required-Stop:
# X-Start-Before hostname
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Set hostname based on /boot/cy_hostname.txt
# Description: Read the machines hostname from /boot/cy_hostname.txt, and
# updates /etc/hostname
### END INIT INFO
. /lib/lsb/init-functions
log_daemon_msg "Starting cy_hostname"
if [ -f /boot/cy_hostname.txt ]
then
OLDHOST=`cat /etc/hostname`
NEWHOST=`cat /boot/cy_hostname.txt`
echo "Changing $OLDHOST to $NEWHOST..."
echo $NEWHOST > /etc/hostname
sed -i "s/127.0.1.1.*/127.0.1.1\t$NEWHOST/g" /etc/hosts
#rm /boot/newhost
log_daemon_msg "cy_hostname complete"
fi
exit 0sudo insserv cy_hostname.shSo 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
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.
simplesi wrote:seems to do the job
SERIAL=`cat /proc/cpuinfo | grep Serial | awk '{ print $3 }'`
NEWHOST=`grep $SERIAL /boot/cy_hostname.txt | awk '{ print $2 }'`
if [ ! -z "$NEWHOST" ]; then
... change hostname ...
fi
00000000de13eab1 pi1
00000000de12eac2 pi2
00000000de10ef9e pi3
00000000de119945 pi4
etc.
simplesi wrote: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)
you probably don't want to call insserv directly, instead use "update-rc.d sickbeard-daemon defaults" - the details are in "man insserv".
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.
http://cymplecy.wordpress.com/2012/08/09/auto-install-a-simple-samba-setup/simplesi wrote: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
Why on earth would you just pull the power?
simplesi wrote:I hadn't realised how long the RPi takes to finally write its cache to disc
simplesi wrote:Why on earth would you just pull the power?
MY RPi doesn't have a nice integrated button that initiates a clean shutdown and its a lot quicker than typing sudo shutdown
Simon
#! /bin/sh
### BEGIN INIT INFO
# Provides: serial_hostname
# Required-Start: $local_fs
# Required-Stop:
# X-Start-Before hostname
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Set hostname based on /boot/serial_hostname.txt
# Description: Read the machines hostname from /boot/serial_hostname.txt,
# based on machine serial number
### END INIT INFO
. /lib/lsb/init-functions
log_daemon_msg "Starting serial_hostname"
if [ -f /boot/serial_hostname.txt ]
then
SERIAL=`cat /proc/cpuinfo | grep Serial | awk '{ print $3 }'`
NEWHOST=`grep $SERIAL /boot/serial_hostname.txt | awk '{ print $2 }'`
if [ -z "$NEWHOST" ]; then
sed -i "$ a${SERIAL} ${SERIAL}" /boot/serial_hostname.txt
NEWHOST=$SERIAL
fi
if [ ! -z "$NEWHOST" ]; then
OLDHOST=`cat /etc/hostname`
echo "Changing $OLDHOST to $NEWHOST..."
echo $NEWHOST > /etc/hostname
sed -i "s/127.0.1.1.*/127.0.1.1\t$NEWHOST/g" /etc/hosts
#rm /boot/newhost
log_daemon_msg "serial_hostname complete"
fi
fi
exit 0