# Building own image, apt-get

**URL:** <https://forums.balena.io/t/building-own-image-apt-get/357599>\
**Category:** General\
**Created:** [May 10, 2022, 6:33am UTC](https://forums.balena.io/t/building-own-image-apt-get/357599 "2022-05-10T06:33:37Z")\
**Posts on this page:** 14\
**Page:** 2

<div class="post-metadata">

**Author:** ![M4xell](https://avatars.discourse-cdn.com/v4/letter/m/a8b319/32.png) [@M4xell](https://forums.balena.io/u/M4xell)\
**Post date:** [May 23, 2022, 6:55am UTC](https://forums.balena.io/t/building-own-image-apt-get/357599/30 "2022-05-23T06:55:49Z")

</div>

I tested this and if i put “IMAGE\_INSTALL:append = " i2cdetect” after “# Barys: Additional variables” then there is nothing happend after compilation and this file just back to original, if I put before then i received error

```auto
NOTE: Resolving any missing task queue dependencies
ERROR: Nothing RPROVIDES 'i2cdetect' (but /home/balena/poky/balena-raspberrypi/build/../layers/meta-balena/meta-balena-common/recipes-core/images/balena-image.bb RDEPENDS on or otherwise requires it)
NOTE: Runtime target 'i2cdetect' is unbuildable, removing...
Missing or unbuildable dependency chain was: ['i2cdetect']
ERROR: Required build target 'balena-image' has no buildable providers.
Missing or unbuildable dependency chain was: ['balena-image', 'i2cdetect']

```

---

<div class="post-metadata">

**Author:** ![M4xell](https://avatars.discourse-cdn.com/v4/letter/m/a8b319/32.png) [@M4xell](https://forums.balena.io/u/M4xell)\
**Post date:** [May 23, 2022, 7:10am UTC](https://forums.balena.io/t/building-own-image-apt-get/357599/31 "2022-05-23T07:10:32Z")

</div>

> $ balena run -it --privileged alpine   
> /bin/sh -c “apk add --update i2c-tools && i2cdetect -y 0”

maybe is working for simple command (i’m not sure that i2cdetect run from your method show my correct value) but if i want to decode my overlay by dtc command it looks that I can’t see filesystem … Please check below

> balena run -it --privileged alpine /bin/sh -c “apk add --update dtc && dtc -I dtb -O dts -o /mnt/boot/overlays/test.dts /mnt/boot/overlays/test.dtbo”  
> FATAL ERROR: Couldn’t open “/mnt/boot/overlays/test.dtbo”: No such file or directory

---

<div class="post-metadata">

**Author:** ![TJvV](https://avatars.discourse-cdn.com/v4/letter/t/858c86/32.png) [@TJvV](https://forums.balena.io/u/TJvV)\
**Post date:** [May 23, 2022, 7:17am UTC](https://forums.balena.io/t/building-own-image-apt-get/357599/32 "2022-05-23T07:17:58Z")

</div>

Hi,

This may not be exactly what you’re looking for, but you can [enable i2cdetect in busybox](https://www.digikey.nl/en/maker/projects/intro-to-embedded-linux-part-5-how-to-enable-i2c-in-the-yocto-project/6843bbf9a83c4c96888fccada1e7aedf).  
Re-configure busybox using `bitback busybox -c menuconfig`.  
You can probably save the new configuration as a patch file to make it automatic.

Edit: for testing, you can do this with `barys` using `./balena-yocto-scripts/build/barys --bitbake-target busybox --bitbake-args -cmenuconfig`

---

<div class="post-metadata">

**Author:** ![TJvV](https://avatars.discourse-cdn.com/v4/letter/t/858c86/32.png) [@TJvV](https://forums.balena.io/u/TJvV)\
**Post date:** [May 23, 2022, 7:40am UTC](https://forums.balena.io/t/building-own-image-apt-get/357599/33 "2022-05-23T07:40:40Z")

</div>

Your problem here is that you don’t have a (bind mount) directory `/mnt/boot/overlays`; as bind mounts are normally disabled in Balena, I doubt this is gonna work.  
You could make a directory in your container, but it won’t be shared with the Host OS.

---

<div class="post-metadata">

**Author:** ![M4xell](https://avatars.discourse-cdn.com/v4/letter/m/a8b319/32.png) [@M4xell](https://forums.balena.io/u/M4xell)\
**Post date:** [May 23, 2022, 9:00am UTC](https://forums.balena.io/t/building-own-image-apt-get/357599/34 "2022-05-23T09:00:04Z")

</div>

It looks that you are right, do you know where is dtc (device tree compiler)? I tried to find but I can’t.

---

<div class="post-metadata">

**Author:** ![TJvV](https://avatars.discourse-cdn.com/v4/letter/t/858c86/32.png) [@TJvV](https://forums.balena.io/u/TJvV)\
**Post date:** [May 23, 2022, 9:53am UTC](https://forums.balena.io/t/building-own-image-apt-get/357599/35 "2022-05-23T09:53:57Z")

</div>

I think it’s important to keep an eye on what we’re doing, where and why.

First, let’s deconstruct what you just tried to do.

You ran a docker image `alpine`;  
In this image, you installed `dtc` by running `apk add --update dtc `;  
Then you ran the freshly installed `dtc` by running `dtc -I dtb -O dts -o /mnt/boot/overlays/test.dts /mnt/boot/overlays/test.dtbo”`  
This command should convert an existing device tree binary to a source file.  
This command failed, because `/mnt/boot/overlays` does not exist in your image.

Now the why:  
Presumably you want to use your current device tree in its source form for a patch or to check if things ended up the way as expected?

What now?  
If you have compiled the OS yourself, you should be able to access the compiled device tree before even running it on your target. You can find it in `build/tmp/deploy/images/<device>`.  
You can actually install `dtc` on your own machine (Debian/Ubuntu package is called `device-tree-compiler`), or run `dtc` with `docker` to do the same thing you tried with the `balena` command. See [the docker docs](https://docs.docker.com/storage/bind-mounts/#choose-the--v-or---mount-flag) how to use bind mounts.

If you are running a pre-built image on the target, you might be able to grab the current device tree from `/proc/device-tree` using `dtc -I fs /proc/device-tree`, and then store the output to `/data`.

If you haven’t read it yet, [the raspberry pi docs](https://www.raspberrypi.com/documentation/computers/configuration.html#device-trees-overlays-and-parameters) has a fair bit on device trees.

---

<div class="post-metadata">

**Author:** ![M4xell](https://avatars.discourse-cdn.com/v4/letter/m/a8b319/32.png) [@M4xell](https://forums.balena.io/u/M4xell)\
**Post date:** [May 23, 2022, 11:35am UTC](https://forums.balena.io/t/building-own-image-apt-get/357599/36 "2022-05-23T11:35:07Z")

</div>

I know what i want to do, just try to check why my i2c is not working properly when i add my own overlays;) up to now is very hard to do this, because every “normal” procedure from my point of view is blocked by balena (i2cdetect, dtc) so i need to make this topic to teach a little this ecosystem.

Now I know how to add i2cdetect by change config but still don’t know what I need to do when I need to add some packages (doesn’t matter which one). This is a base of this topic so let’s focus on it. Now I’m think what i need to do to add dtc to my own image.

> What now?  
> If you have compiled the OS yourself, you should be able to access the compiled device tree before even running it on your target. You can find it in build/tmp/deploy/images/.  
> You can actually install dtc on your own machine (Debian/Ubuntu package is called device-tree-compiler), or run dtc with docker to do the same thing you tried with the balena command. See the docker docs how to use bind mounts.

Of course, I can run this in other system or in the docker but why? I want to add this to my own image because for me is a basic function. This is why I want to build my own image and not using default.

> If you are running a pre-built image on the target, you might be able to grab the current device tree from /proc/device-tree using dtc -I fs /proc/device-tree, and then store the output to /data.

Yes i know 😉 but only if i have this package, few message above I’m asking if the DTC in docker is same like in the hostOS, but it looks that nobody answer me

---

<div class="post-metadata">

**Author:** ![TJvV](https://avatars.discourse-cdn.com/v4/letter/t/858c86/32.png) [@TJvV](https://forums.balena.io/u/TJvV)\
**Post date:** [May 23, 2022, 2:27pm UTC](https://forums.balena.io/t/building-own-image-apt-get/357599/37 "2022-05-23T14:27:06Z")

</div>

My bad, I think I just misunderstood.

As far as I know, there are no specific versions of `dtc`, they all do the same thing.  
That’s why I mentioned you could just run your native `dtc` to get the job done.

I think that `IMAGE_INSTALL_append` might be the way to go for [packages/recipes](https://layers.openembedded.org/layerindex/branch/master/recipes/?q=dtc).  
I’m not sure if there’s a big difference between adding the external `i2c-tools` recipe and using the "configure `busybox`" version.

You said that it did “nothing” for you; did you check the `build/conf/local.conf` to see if it actually picked up your changes?  
If I recall correctly, `barys` likes to overwrite it with the version in `meta-balena-<device>`.  
You could add your change to `layers/meta-balena-<device>/conf/samples/local.conf.sample` and then build it to see if it works.

You should be able to find it after building, using something like `find build/tmp/sysroots-components/ -name dtc\*`

---

<div class="post-metadata">

**Author:** ![M4xell](https://avatars.discourse-cdn.com/v4/letter/m/a8b319/32.png) [@M4xell](https://forums.balena.io/u/M4xell)\
**Post date:** [May 24, 2022, 7:59am UTC](https://forums.balena.io/t/building-own-image-apt-get/357599/38 "2022-05-24T07:59:14Z")

</div>

Thanks, i will check.

Other topic, I know that yocto have a possibility to run compiled system in emulator, can i do the same for my own balena image? I’m so tired to flash next disk to check one change in DT overlay …

---

<div class="post-metadata">

**Author:** ![alexgg](https://avatars.discourse-cdn.com/v4/letter/a/7ab992/32.png) [@alexgg](https://forums.balena.io/u/alexgg)\
**Post date:** [May 27, 2022, 10:46am UTC](https://forums.balena.io/t/building-own-image-apt-get/357599/39 "2022-05-27T10:46:00Z")

</div>

Hi, coming back to one of your comments, `i2cdetect` is not a Yocto package, it’s provided by the `i2c-tools` package. So the correct way of adding it to the image is:

```auto
IMAGE_INSTALL:append = " i2c-tools"

```

You can use the `devtool` tool to query the Yocto metadata for the package a specific utility is included in, like:

```auto
MACHINE=raspberrypi4-64 devtool search i2cdetect
NOTE: Starting bitbake server...
NOTE: Reconnecting to bitbake server...
NOTE: Retrying server connection (#1)...
Loading cache: 100% |########################################################################################################################################################################################################| Time: 0:00:00
Loaded 3867 entries from dependency cache.
i2c-tools Set of i2c tools for linux

```

---

<div class="post-metadata">

**Author:** ![garkbeda43](https://avatars.discourse-cdn.com/v4/letter/g/8c91f0/32.png) [@garkbeda43](https://forums.balena.io/u/garkbeda43)\
**Post date:** [June 10, 2022, 1:42pm UTC](https://forums.balena.io/t/building-own-image-apt-get/357599/41 "2022-06-10T13:42:03Z")

</div>

I have same error any type of solution…

---

<div class="post-metadata">

**Author:** ![garkbeda43](https://avatars.discourse-cdn.com/v4/letter/g/8c91f0/32.png) [@garkbeda43](https://forums.balena.io/u/garkbeda43)\
**Post date:** [June 20, 2022, 8:18am UTC](https://forums.balena.io/t/building-own-image-apt-get/357599/42 "2022-06-20T08:18:15Z")

</div>

I know what i want to do, just try to check why my i2c is not working properly when i add my own overlays;) up to now is very hard to do this, because every “normal” procedure from my point of view is blocked by balena (i2cdetect, dtc) so i need to make this topic to teach a little this ecosystem.[.](https://19216811.bid/)  
[.](https://panoramacharter.ltd/)

---

<div class="post-metadata">

**Author:** ![M4xell](https://avatars.discourse-cdn.com/v4/letter/m/a8b319/32.png) [@M4xell](https://forums.balena.io/u/M4xell)\
**Post date:** [June 22, 2022, 7:04am UTC](https://forums.balena.io/t/building-own-image-apt-get/357599/43 "2022-06-22T07:04:27Z")

</div>

`./balena-yocto-scripts/build/barys --bitbake-target busybox --bitbake-args -cmenuconfig -m raspberrypicm4-ioboard`  
Just run and find i2cdetect package in the list

😉 This is a solution to add i2cdetect

---

<div class="post-metadata">

**Author:** ![klutchell](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/klutchell/32/861_2.png) [@klutchell](https://forums.balena.io/u/klutchell)\
**Post date:** [July 4, 2022, 6:49pm UTC](https://forums.balena.io/t/building-own-image-apt-get/357599/44 "2022-07-04T18:49:02Z")

</div>

Hey @garkbeda43, it might be worthwhile to follow the Yocto getting started guides to familiarize yourself with the Yocto build ecosystem that balena is based on. This could be the learning experience you are looking for!  
[https://docs.yoctoproject.org/brief-yoctoprojectqs/index.html](https://docs.yoctoproject.org/brief-yoctoprojectqs/index.html)

Once you’ve gone through those guides you may find it easier to apply customizations to balenaOS images. Let us know how it goes!

[Previous page](https://forums.balena.io/t/building-own-image-apt-get/357599.md?page=1)
