To the OP....
Just for giggles I thought I'd give this a shot...
First I tried to create a init.d script that would execute before hostname.sh did... Not as easy as I thought... it would require modifying other init.d scripts... and I didn't want to go that far....
So instead, I modified the original /etc/init.d/hostname.sh script by adding a new section in the do_start () section.
The section I added looks like:
- Code: Select all
if [ -f /boot/newhost ]
then
OLDHOST=`cat /etc/hostname`
NEWHOST=`cat /boot/newhost`
echo "Changing $OLDHOST to $NEWHOST..."
echo $NEWHOST > /etc/hostname
sed -i "s/127.0.1.1.*$OLDHOST/127.0.1.1\t$NEWHOST/g" /etc/hosts
rm /boot/newhost
fi
I did a couple tests and it worked great.
Source CodeSource of Changed /etc/init.d/hostname.sh
https://gist.github.com/3993105I put it there rather than in this posting so that updates can be made if necessary... Can't change the posting here after it is posted (very annoying)...Installing it...MAKE A BACKUP OF THE ORIGINAL SCRIPT! I just copied the original to /boot/hostname.sh.original
Then just copy the entire contents of the source in the link above (use raw to display just the source) and replace the contents of the original hostname.sh script.
It should have the same permissions as before which would be
- Code: Select all
sudo chmod 0755 /etc/init.d/hostname.sh
You should not need to do anything else as it is already setup by the system using the original filename
Then it is ready to rumble...
How it worksCreate a /boot/newhost file with just the new hostname you want in it... for this test I made it look like:
/boot/newhost
- Code: Select all
hippo123
Note that I just typed in the hippo123 and didn't even use a newline... just saved it.
Before rebooting... the contents of the two files it will modify were:
/etc/hostname
- Code: Select all
raspi01
/etc/hosts
- Code: Select all
127.0.0.1 localhost
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
127.0.1.1 raspi01
I then just rebooted the RPi... I was doing this headless..
When it came up the contents of the two files were:
/etc/hostname
- Code: Select all
hippo123
/etc/hosts
- Code: Select all
127.0.0.1 localhost
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
127.0.1.1 hippo123
And the system was using it.
The usual precautions should be taken.... act as if you will lose your disk... so you don't lose anything important if something goes terribly wrong, but this should be fine.