I am interested in changing the default hostnames on our Verdin modules.
I am aware of being able to change the hostname through the terminal or by modifying the conf file, but this is a bit clunky when we are doing hundreds of devices per year.
Is it possible to do that at scale in some manner?
Hi, I’m the Toradex AI Assistant. I’m in early beta, and I would appreciate your feedback.
The Toradex Support team will follow up with you shortly!
Did you like my answer?
Hello,
Changing the hostname for a large number of Verdin modules efficiently can indeed be streamlined using TorizonCore Builder. TorizonCore Builder is a powerful tool that allows you to customize TorizonCore images, including setting a custom hostname, before deploying them to your devices.
To change the hostname at scale using TorizonCore Builder, you can follow these general steps:
Prepare Your Environment: Ensure you have TorizonCore Builder installed and configured on your system. If you haven’t already, set up TorizonCore Builder by following the official Toradex documentation.
Customize the Device Tree or Overlay: Although changing the hostname is not directly a device tree modification, it’s essential to understand that any hardware-specific configurations should be handled before software customizations like hostname changes.
Customize the Image with TorizonCore Builder: Use the customize command in TorizonCore Builder to modify the system settings, including the hostname. You can create a customization script or use command-line parameters to specify the new hostname.
Apply Customizations: Apply your customizations to a base TorizonCore image. This process will generate a new TorizonCore image with your specified hostname.
Deploy the Customized Image: Once you have the customized image, you can deploy it to your Verdin modules using your preferred method, such as over-the-air updates or direct flashing.
For a large number of devices, consider automating the deployment process to streamline the updates further. This could involve scripting the download and flashing process or using a continuous integration/continuous deployment (CI/CD) pipeline to manage your fleet of devices.
Remember, while the above steps provide a high-level overview, the exact commands and procedures will depend on your specific requirements and the current version of TorizonCore Builder you are using. Always refer to the latest TorizonCore Builder documentation for the most accurate and detailed instructions.
Best regards,
Toradex AI Assistant
Please, also check if these links can help you solve your problem:
That said, /etc/hostname is a bit of a special case since it can’t be customized by TorizonCore Builder. What could be done instead is creating a script that runs on boot that will customize the hostname on your device. You can then use TorizonCore Builder to capture this script and service and create a custom image that can then be deployed to multiple devices.
A script that runs on boot is what I was thinking, but I just wanted to make sure there wasn’t a more defined approach for this already.
In regards to creating that script on boot, what is the best approach to handling that? Would it be to have a service that starts on boot and runs the script?
don’t forget to enable the service : systemctl enable change_hostname.service
and for the bash : change_hostname.sh > wherever you want (but still in “/etc” for the 2nd option)
#!/bin/bash/
#I want a hostname which start with "card-" and finish with the 3 last case of MAC addr : card-aabbcc
chmod ugo+w /etc/hostname #change the right
echo "card-$(ip a | grep 00:14: | cut -c25-32 | tr -d :)" > /etc/hostname #write the hostname
chmod ugo-w /etc/hostname #reset the right
As @Waise has shared and as shown the in the thread I linked you previously. The general idea would be to make a systemd service that calls a script on boot. You can then capture these changes and deploy them in production via TorizonCore Builder as shown in the links.
That’s how we can set the hostname containing the module serial number despite the serial number being unique across our hardware. So this solution isn’t anything out of the ordinary.
Is there a way to modify that existing hostname file? I just want to change the verdin-am62 to something else an maintain the serial number as the unique identifier.
The file is part of the read only file system, so I don’t think there is without building from Yocto.
Is there a way to modify that existing hostname file?
I mean you can modify /etc/hostname on a single device via the command-line. But as I said previously in this thread, that file is a bit of a special case and can’t be customized with TorizonCore Builder. This means you can’t capture the change to this file and deploy it in a scalable way in production. Meaning it would not be very practical outside of development.
I just want to change the verdin-am62 to something else an maintain the serial number as the unique identifier.
Did you look at the previous link I shared with you? As I said previously, we use a script in our base OS to set the hostname to <module-name>-<serial-number>. Can you not just use this script as a reference and create another script that then sets the hostname to whatever you want like <my-hostname>-<serial-number>?
The file is part of the read only file system, so I don’t think there is without building from Yocto.
Are we talking about the same thing? The file /etc/hostname is definitely writable. It requires sudo/root permissions to write but it can be written. If it was read-only then how would we be able to change the hostname with a script on first boot?
I mean you can modify /etc/hostname on a single device via the command-line. But as I said previously in this thread, that file is a bit of a special case and can’t be customized with TorizonCore Builder. This means you can’t capture the change to this file and deploy it in a scalable way in production. Meaning it would not be very practical outside of development.
I searched the file system for the service that you send me the link to, that is in a read only section of the file system, unless I’m misunderstanding something. It cannot be modified with sudo. I am referring to sethostname.
Did you look at the previous link I shared with you? As I said previously, we use a script in our base OS to set the hostname to <module-name>-<serial-number> . Can you not just use this script as a reference and create another script that then sets the hostname to whatever you want like <my-hostname>-<serial-number> ?
Yes, I did look at that, but modifying the existing hostname service that was provided with the OS would have been an easier route if it was possible. It doesn’t appear to be possible without going back to Yocto, so I am pursing making my own. Not a problem.
Are we talking about the same thing? The file /etc/hostname is definitely writable. It requires sudo/root permissions to write but it can be written. If it was read-only then how would we be able to change the hostname with a script on first boot?
See first response, we are not talking about the same thing. I should have been more clear when I said “The file”.
It’s highly recommended to create your own service and script for this rather than try to modify what is already there. This is what most of our other customers do. It’s also easier from a maintenance point of view since you’ll have full control over the script and service files. Rather than relying on something we did, which could change at any time in the future.