I’m at the stage now where I want to create a custom image. I’m following the instructions (Image customization overview | Toradex Developer Center) It’s capturing everything but
- I have a bunch of folders and files in /home/torizon dir. I want this and all it’s contents in the custom image. How would I do that?
- Saving the host name. I want the custom hostname to be part of this image. How do I include it?
I’m assuming it has to do with the tcbuild.yaml.
Greetings @jeffbelz,
Let me ho through your questions here one by one:
I have a bunch of folders and files in /home/torizon dir. I want this and all it’s contents in the custom image. How would I do that?
The short answer here is, you don’t do that. The framework that we use to perform image customization is called OSTree. OSTree manages certain directories to track and apply changes. In the case of the home directory, it is not tracked at all. Now this is by design, as this way users can use this directory to hold persistent files that won’t be affected by changes from OSTree.
However, since it’s not being tracked by OSTree it then has the effect where changes/customization here are not detected. So really the only workaround here is to instead store your folders and files in a place that is actively tracked by OSTree like /etc
for example. In fact the when TorizonCore Builder captures changes/customization it specifically looks at the /etc
directory because of this behavior of OSTree.
Saving the host name. I want the custom hostname to be part of this image. How do I include it?
Hostname can be simply modified by changing the contents of the /etc/hostname
file I believe. Since this file is under /etc
it will be picked up when you capture changes via the usual process of capturing changes.
I hope I was able to help clarify.
Best Regards,
Jeremias
Looks like OSTree captures /usr/etc not /etc. hostname is only in /etc. When I look at the change1 directory after I run the command to capture the changes it shows /usr/etc and when comparing folders it matches the /usr/etc. Any thoughts?
Hi @jeffbelz ,
Sorry for the late response. Although inside change1
shows /usr/etc/
all changes will be applied in /etc/
when creating the custom image. It’s a bit confusing but that’s how OSTree works internally under TorizonCore Builder.
Unfortunately it seems that TorizonCore Builder ignores changes in /etc/hostname
(TorizonCore Builder Tool - Commands Manual | Toradex Developer Center), so there isn’t a straightforward way to apply a different hostname as part of the image.
A possible workaround would be to execute a script on startup that changes the hostname.
Let me know if you have any additional questions.
Best regards,
Lucas Akira
Complementing my previous post, I managed to create an image with a custom hostname by creating a systemd service in /etc/
that executes a script changing the hostname on system startup.
The changes
directory used to do this has the following content:
changes
└── usr
└── etc
├── custom_hostname.sh
├── systemd
│ └── system
│ ├── custom_hostname.service
│ └── multi-user.target.wants
│ └── custom_hostname.service -> /etc/systemd/system/custom_hostname.service
└── .tcattr
custom_hostname.sh
: The script executed by the service. Change the value of CUSTOM_HOSTNAME
to your custom hostname.
#!/bin/sh
CUSTOM_HOSTNAME=my-colibri-arm64
if [ $(hostname) != $CUSTOM_HOSTNAME ]
then
hostnamectl set-hostname $CUSTOM_HOSTNAME
fi
custom_hostname.service
: Describes the systemd service.
[Unit]
After=dbus.service
Description=custom hostname script
DefaultDependencies=no
[Service]
Type=oneshot
ExecStart=/etc/custom_hostname.sh
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
-
custom_hostname.service
in multi-user.target.wants
: Symbolic link to the previous file, allows the service to initialize on startup.
-
.tcattr
: Describes the permissions of the previous files.
# file: custom_hostname.sh
# owner: 0
# group: 0
user::rwx
group::r-x
other::r--
# file: systemd/system/custom_hostname.service
# owner: 0
# group: 0
user::rw-
group::r--
other::r--
# file: systemd/system/multi-user.target.wants/custom_hostname.service
# owner: 0
# group: 0
user::rwx
group::rwx
other::rwx
I’ve also attached the changes
directory below.
With this directory I’ve created a custom TorizonCore image for a Colibri iMX8X, and the system successfully started with the new hostname. This should work on any module that supports TorizonCore.
Let me know if this helps you in any way.
Best regards,
Lucas Akira
changes.tar.gz (655 Bytes)