Setting hostname from Yocto build

I have a Colibri vf50 module running linux V2.5 on a custom board with two LAN ports.

Is it possible to set the target machines hostname from Yocto build?

Hi

Have a look in the Yocto documentation.

Max

I have tried placing: hostname=“myhostname” in a base-files_%.bbappend file. I have also tried setting: hostname_pn-base-files = “myhostname” in the local.conf file. However, the hostname file in the resultant distribution is still “colibri-vf”. Not sure what I am doing wrong?

Do you use a DHCP server which assigns the hostname to your device? In that case, connman will overwrite the preconfigured hostname…

Otherwise, check using the --environment or -e parameter whether you append or local conf really got applied:

bitbake base-files -e | grep hostname

If I do not have a meta layer, I can do it directly in conf/local.conf:

hostname_pn-base-files = "your_hostname_here"


Cleiton Bueno

Blog | Linkedin | B2Open

Wow, nice to know that. Noted here.

Apologies if I am doing something wrong - I am a bit new to OE/Yocto. But I cannot seem to get this to work. I have added the line:
hostname_pn-base-files = “MY001”
to the file: /opt/TORADEX_COLIBRI_VF_V2.5/build/conf/local.conf
However, when I check the contents of the /etc/hostname file in the resultant image file:
/opt/TORADEX_COLIBRI_VF_V2.5/build/out-glibc/deploy/images/colibri-vf/Colibri_VF_LinuxConsoleImageV2.5_20161130.tar.bz2
it always has colibri_vf?

Hi

I tried it out and got the same issue, in the final image I still have the machine name in /etc/hostname.

Angstrom overrides the creation of the file and sets the hostname unconditionally to machine.
You could edit in layers/meta-angstrom the bbappend as follows:

--- a/recipes-core/base-files/base-files_3.0.14.bbappend
+++ b/recipes-core/base-files/base-files_3.0.14.bbappend
@@ -16,7 +16,9 @@ dirs755 += "${localstatedir}/cache \
 BASEFILESISSUEINSTALL = "do_install_angstromissue"
 
 do_install_angstromissue () {
-    echo ${MACHINE} > ${D}${sysconfdir}/hostname
+    if [ "${hostname}" ]; then
+        echo ${hostname} > ${D}${sysconfdir}/hostname
+    fi
 
     install -m 644 ${WORKDIR}/issue*  ${D}${sysconfdir}
         if [ -n "${DISTRO_NAME}" ]; then

With that changes you should get the expected behaviour, e.g. setting hostname_pn-base-files = “MY001” in local.conf propagates into the rootfs.

Max

Very strange! Enter here the command output suggested by @stefan.tx

Have a look at Max’ answer above. It is an issue in the base file bbappend of meta-angstrom.