For a more indirect approach (needed here as I have a few dozen machines and I can't see editing boot codes for each) you have two primary options:
1) If you have the ability to set up DNS for yourself, set the computer's host name in DNS (preferably by MAC)
2) If DNS isn't an option, the following is all that's needed:
a) in /opt/bootsync.sh replace the line sethostname= with the preferred host name *preferred
or
b) add etc/hostname to /opt/.filetool.lst and edit /etc/hostname to suit (and remove the command in bootsync.sh accordingly)
Hi centralware,
I don't have quite so many machines to keep track of, but between the "homeschool computer lab" (all tiny core, all the time) and the data center at work (where some of the Windows servers may only ever need to boot other than into Windows once every few years) I've found that it's convenient to be able to boot many different boxes from the same boot system (on USB flash drives) by determining which host I'm on at boot time based upon the physical characteristics of the box.
Originally, I kept only a table of the UIDs of the filesystems on each actual hard disk in each machine and it worked like a charm... until I used it on a box where the hard drive had been removed.
Then I added a table of the mac addresses of each box's ethernet cards as the primary reference and the disk IDs remain as secondary identifier.
It's been on my todo list for a couple of years now to package up the script for submission to the repo, but every time I sit down to "clean it up once and for all" I end up adding some little feature or another instead.
Below is an old'ish listing of the main script and below that some sample data. In bootsync.sh are lines like this:
WHATHOST=`/opt/bin/whathost`
/bin/hostname ${WHATHOST}
For basic host name setting, that's all you need. For more involved customizations, I have a subdirectory tree under
/opt/whathost/<hostname>
that contains, for instance, supplementary bootsync.sh and bootlocal.sh files for certain boxes. Of course, by the time bootsync.sh figures out what host we're on, it's too late to affect what extensions get loaded.
A future version will load the whathost script from an extension and run it from the extension's install script - which can then load additional extension lists (a la onboot.lst) customized for the host - so my web server can load apache and my file server can load samba and my worksation can load libreoffice, etc, etc and everybody can load openssh. At that point, the macdb and diskdb files and the per-host config file trees will live on boot media, probably alongside the grub menu file, so I can update them w/o having to actually boot each stick and w/o having to constantly rebuild the extension. Since extension loading happens before data is restored from backup, one could even maintain separate mydata.tgz files per host - though I have a slightly uneasy feeling about that idea.
#!/bin/sh
# whathost - determine on what physycal host we are running. lem 2010-06-13
# 2011-11-30 lem - added determination of physical host by MAC address of NIC
# 2012-09-11 lem - added override with "whathost=hostname" boot code.
getmac() {
ifconfig -a eth0 |grep -i hwaddr |while read REC ; do echo ${REC} |cut -d" " -f5 ; done
}
MACDB=/opt/whathost/macdb.txt
DISKDB=/opt/whathost/diskdb.txt
WHATHOST=""
. /etc/init.d/tc-functions
WHATHOST=`getbootparam whathost`
[ -n "${WHATHOST}" ] && echo ${WHATHOST}
if [ -z "${WHATHOST}" ] ; then {
# ID machine by eth0 MAC
if MAC=`getmac` ; then {
if REC=`grep ${MAC} ${MACDB}` ; then {
WHATHOST=`echo ${REC} |cut -d" " -f1`
} fi
[ -n "${WHATHOST}" ] && echo ${WHATHOST}
} fi
} fi
if [ -z "${WHATHOST}" ] ; then {
# ID machine by HD filesystems' UUIDs
blkid |grep -v loop |while read DISK ; do {
if [ -z "${WHATHOST}" ] ; then {
# get the UUID of the device...
VALQ="NONE"
PIECE=1
while [ "${VALQ}" != "UUID" ] ; do {
VALQVAL=`echo ${DISK} |cut -d" " -f${PIECE}`
VALQ=`echo ${VALQVAL} |cut -d"=" -f1`
VAL=`echo ${VALQVAL} |cut -d"=" -f2`
PIECE=`expr ${PIECE} + 1`
} done
# and look it up in the disks database
if REC=`grep ${VAL} ${DISKDB}` ; then {
WHATHOST=`echo ${REC} |cut -d" " -f1`
} fi
[ -n "${WHATHOST}" ] && echo ${WHATHOST}
} fi
} done
} fi
# database of mac addresses vs. host names for use by whathost.
D4600 00:0C:F1:D6:73:44
tigress 00:E0:4C:91:19:0C
cgs1501 00:19:89:68:4e:e0
neptune 00:13:20:47:E6:02
D4600 /dev/sda1: LABEL="D4600" UUID="7faa7183-0cd1-4677-b790-8d4a814a95a9" TYPE="ext2"
leepc /dev/sda1: UUID="B0B880D3B8809A0C" TYPE="ntfs"
leepc /dev/sda5: LABEL="SDA5" UUID="3C71-9C09" TYPE="vfat"
leepc /dev/sda6: UUID="c963ba63-ded9-432f-9d38-5c30e684d63c" TYPE="ext2"
neptune /dev/sda1: SEC_TYPE="msdos" LABEL="DellUtility" UUID="07D5-061B" TYPE="vfat"
neptune /dev/sda2: UUID="E6D42FD4D42FA5B1" TYPE="ntfs"
neptune /dev/sda5: UUID="DAE8BAF2E8BACC4F" TYPE="ntfs"