Building balenaOS from source and connecting to balenaCloud

Hi,
I’m trying to learn about the internals of balenaOS by building it from the source.
My goal is eventually porting balenaOS to a new board: STM32MP157C-DK2.
I successfully built a balenaOS resin-image for MACHINE=raspberrypi3 and got resin-image-raspberrypi3-20190816161432.rootfs.resinos-img.

The only customization I made is switching to overlay2 from aufs for storage driver, because there is a problem building aufs docker images on my host machine (Arch Linux) even if I used resin/yocto-build-env docker for building.

However, after flashing using dd command, although I see systemd messages on the touchscreen on boot, there is nothing happened.

Obviously, I didn’t configure balenaCloud before flashing. This discussion seems to tell how to preload the image. So I preloaded the image using the following command:

balena preload resin-image-raspberrypi3-20190816161432.rootfs.resinos-img --app 1391883 --commit "current"

(btw I already have added two devices in appid 1391883)

But I still cannot get the device connected to the appid 1391883 on balenaCloud. The preloaded app seems to work, though it is partially broken because it doesn’t seems to have environment variables and device variables that are supposed to be pulled from balenaCloud such as device name.

How can I connect this to the cloud? Is there anything I need to do on the cloud app, or on the device?

Hey @kbumsik ,

It’s great you’ve managed to make a custom balenaOS build.
In order to make the device connected to our cloud, it needs its credentials in config.json file stored in the root of the image.
It contains stuff like device ID (in our system), application ID, and API key used for authorization.

You can go “Add new device” window on the dashboard, expand “Advanced” section at the bottom, check “Download configuration file only” box, and press download. Then add this file to your image used to boot the device, flash it, and hopefully see it connected.

BTW, it should work without preloading too, since it will download the app from the backend.

Let us know if it works.

1 Like

Hi @roman-mazur,
It finally works, thank you for help! Now I can proceed to the porting job.
So will balena config generate do the same thing?

Yes, you can generate config.json with balena config generate too. See docs: https://www.balena.io/docs/reference/cli/#config-generate

1 Like