# Incude script in initial image

**URL:** <https://forums.balena.io/t/incude-script-in-initial-image/34640>\
**Category:** openBalena\
**Created:** [September 30, 2019, 10:27am UTC](https://forums.balena.io/t/incude-script-in-initial-image/34640 "2019-09-30T10:27:03Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![mexekanez](https://avatars.discourse-cdn.com/v4/letter/m/73ab20/32.png) [@mexekanez](https://forums.balena.io/u/mexekanez)\
**Post date:** [September 30, 2019, 10:27am UTC](https://forums.balena.io/t/incude-script-in-initial-image/34640/1 "2019-09-30T10:27:03Z")

</div>

We need to be able to build an image which could be flashed on the USB. This image would contain a file called " **auto\_run.py**" or " **auto\_run.sh**".

The idea is: as soon as the USB is connected to the machine (Edge device), the script should run automatically. This script would perform an operation like making an API call, storing some logs, repairing an API and etc

---

<div class="post-metadata">

**Author:** ![dansku](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/dansku/32/1183_2.png) [@dansku](https://forums.balena.io/u/dansku)\
**Post date:** [September 30, 2019, 11:32am UTC](https://forums.balena.io/t/incude-script-in-initial-image/34640/2 "2019-09-30T11:32:23Z")

</div>

Hey @mexekanez,  
you must first provision your device with balenaOS, then the auto\_run script should run inside a container.

You can also check the SDK, which you can use to control the API from the device. [https://github.com/balena-io/balena-sdk](https://github.com/balena-io/balena-sdk)

Let me know if you have ay questions.

Cheers

---

<div class="post-metadata">

**Author:** ![mexekanez](https://avatars.discourse-cdn.com/v4/letter/m/73ab20/32.png) [@mexekanez](https://forums.balena.io/u/mexekanez)\
**Post date:** [September 30, 2019, 1:05pm UTC](https://forums.balena.io/t/incude-script-in-initial-image/34640/6 "2019-09-30T13:05:26Z")

</div>

@dansku Hi!  
No I don’t want to wait while device will pull updates. I want that script is in image before sd burn. and will run after usb connected

---

<div class="post-metadata">

**Author:** ![dansku](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/dansku/32/1183_2.png) [@dansku](https://forums.balena.io/u/dansku)\
**Post date:** [September 30, 2019, 2:01pm UTC](https://forums.balena.io/t/incude-script-in-initial-image/34640/9 "2019-09-30T14:01:16Z")

</div>

Hey @mexekanez, one thing that you can test is the balena-preload project =\> [https://github.com/balena-io/balena-preload](https://github.com/balena-io/balena-preload)

Take a look at the repository and see if that would help with your requirements.

Cheers

---

<div class="post-metadata">

**Author:** ![mexekanez](https://avatars.discourse-cdn.com/v4/letter/m/73ab20/32.png) [@mexekanez](https://forums.balena.io/u/mexekanez)\
**Post date:** [September 30, 2019, 2:11pm UTC](https://forums.balena.io/t/incude-script-in-initial-image/34640/11 "2019-09-30T14:11:57Z")

</div>

yes I understood that I can use only preload OR build yocto image.

with preload I have an issue (using openBalena):

```
 balena preload balena.img --app 12 --commit 9bde88b0e12e4b34228ace17a71d45ab
Building Docker preloader image. [========================] 100%

/ Creating preloader container
- Starting preloader container
\ Fetching application 12
| Reading image information
/ Resizing partitions and waiting for dockerd to start
| Cleaning up temporary files
(HTTP code 500) server error - Get https://registry.DOMAIN.xyz/v2/: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers) 

Additional information may be available by setting a DEBUG=1 environment
variable: "set DEBUG=1" on a Windows command prompt, or "export DEBUG=1"
on Linux or macOS.

If you need help, don't hesitate in contacting our support forums at
https://forums.balena.io

For bug reports or feature requests, have a look at the GitHub issues or
create a new one at: https://github.com/balena-io/balena-cli/issues/
```

---

<div class="post-metadata">

**Author:** ![jviotti](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/jviotti/32/220_2.png) [@jviotti](https://forums.balena.io/u/jviotti)\
**Post date:** [September 30, 2019, 2:16pm UTC](https://forums.balena.io/t/incude-script-in-initial-image/34640/12 "2019-09-30T14:16:24Z")

</div>

Hey there! Is the error message actually printing “[https://registry.DOMAIN.xyz/v2/](https://registry.DOMAIN.xyz/v2/)”? If not, what is the actual domain?

---

<div class="post-metadata">

**Author:** ![mexekanez](https://avatars.discourse-cdn.com/v4/letter/m/73ab20/32.png) [@mexekanez](https://forums.balena.io/u/mexekanez)\
**Post date:** [September 30, 2019, 2:28pm UTC](https://forums.balena.io/t/incude-script-in-initial-image/34640/14 "2019-09-30T14:28:06Z")

</div>

hi!  
actual domain:  
[https://registry.visoagent.xyz/v2/](https://registry.visoagent.xyz/v2/)  
as I said I using openBalena

---

<div class="post-metadata">

**Author:** ![richbayliss](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/richbayliss/32/1054_2.png) [@richbayliss](https://forums.balena.io/u/richbayliss)\
**Post date:** [September 30, 2019, 3:10pm UTC](https://forums.balena.io/t/incude-script-in-initial-image/34640/16 "2019-09-30T15:10:59Z")

</div>

@mexekanez I tried to look at the domain you listed, and I only so the registry exposed on HTTP and not HTTPS. This would explain the issue, since the preload script it trying to use HTTPS and it reporting a timeout before receiving headers; which would happen if the TLS layer couldn’t be established correctly.

For openBalena I think you should have HTTPS going to your registry container, so I am not sure what setup you have but it looks like something isn’t configured correctly. By default openBalena will expose port 443 to the `haproxy` container, which reverse proxies the request to the `registry` container. I would start by looking there to see if you have something misconfigured 👍

---

<div class="post-metadata">

**Author:** ![mexekanez](https://avatars.discourse-cdn.com/v4/letter/m/73ab20/32.png) [@mexekanez](https://forums.balena.io/u/mexekanez)\
**Post date:** [October 1, 2019, 8:10am UTC](https://forums.balena.io/t/incude-script-in-initial-image/34640/18 "2019-10-01T08:10:33Z")

</div>

hi @richbayliss  
not sure what you mean  
bot domain working well http and https  
[http://registry.visoagent.xyz/v2/](http://registry.visoagent.xyz/v2/)  
[https://registry.visoagent.xyz/v2/](https://registry.visoagent.xyz/v2/)

---

<div class="post-metadata">

**Author:** ![mexekanez](https://avatars.discourse-cdn.com/v4/letter/m/73ab20/32.png) [@mexekanez](https://forums.balena.io/u/mexekanez)\
**Post date:** [October 1, 2019, 8:25am UTC](https://forums.balena.io/t/incude-script-in-initial-image/34640/19 "2019-10-01T08:25:44Z")

</div>

actually I have the same issue with balena-preload

```
mexekanez@mexekanezlaptop:~$ balena-preload --app 12 --commit 123455667 --api-token 24234234 --img balena.img
Building Docker preloader image. [========================] 100%

/ Creating preloader container
- Starting preloader container
\ Fetching application 12
/ Reading image information
/ Resizing partitions and waiting for dockerd to start
/ Cleaning up temporary files

{ Error: (HTTP code 500) server error - Get https://registry.visoagent.xyz/v2/: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers) 
    at /usr/local/lib/node_modules/balena-preload/node_modules/docker-modem/lib/modem.js:257:17
    at IncomingMessage.<anonymous> (/usr/local/lib/node_modules/balena-preload/node_modules/docker-modem/lib/modem.js:284:9)
    at emitNone (events.js:111:20)
    at IncomingMessage.emit (events.js:208:7)
    at endReadableNT (_stream_readable.js:1064:12)
    at _combinedTickCallback (internal/process/next_tick.js:138:11)
    at process._tickCallback (internal/process/next_tick.js:180:9) reason: 'server error', statusCode: 500, json: null }

Looks like this might be an issue with balena-preload. Please report it at https://github.com/balena-io/balena-preload/issues
```

---

<div class="post-metadata">

**Author:** ![mexekanez](https://avatars.discourse-cdn.com/v4/letter/m/73ab20/32.png) [@mexekanez](https://forums.balena.io/u/mexekanez)\
**Post date:** [October 1, 2019, 9:11am UTC](https://forums.balena.io/t/incude-script-in-initial-image/34640/21 "2019-10-01T09:11:57Z")

</div>

> / Creating preloader container
> 
> - Starting preloader container  
> \ Fetching application 12  
> | Reading image information  
> / Resizing partitions and waiting for dockerd to start  
> / Cleaning up temporary files
> 
> { Error: (HTTP code 500) server error - Get [https://registry.visoagent.xyz/v2/v2/44acbabc9d364cf2263b1840f099ca43/manifests/sha256:81247b1f61a6bce4a3b2dca3a2fa6ac4fd78144d5421787fb32216bbfab52bc2:](https://registry.visoagent.xyz/v2/v2/44acbabc9d364cf2263b1840f099ca43/manifests/sha256:81247b1f61a6bce4a3b2dca3a2fa6ac4fd78144d5421787fb32216bbfab52bc2:) dial tcp: lookup registry.visoagent.xyz on 192.168.0.1:53: read udp 192.168.0.103:35298-\>192.168.0.1:53: i/o timeout  
> at /usr/local/lib/node\_modules/balena-preload/node\_modules/docker-modem/lib/modem.js:257:17  
> at IncomingMessage. (/usr/local/lib/node\_modules/balena-preload/node\_modules/docker-modem/lib/modem.js:284:9)  
> at emitNone (events.js:111:20)  
> at IncomingMessage.emit (events.js:208:7)  
> at endReadableNT (\_stream\_readable.js:1064:12)  
> at \_combinedTickCallback (internal/process/next\_tick.js:138:11)  
> at process.\_tickCallback (internal/process/next\_tick.js:180:9) reason: ‘server error’, statusCode: 500, json: null }
> 
> Looks like this might be an issue with balena-preload. Please report it at [Issues · balena-io-modules/balena-preload · GitHub](https://github.com/balena-io/balena-preload/issues)  
> mexekanez@mexekanezlaptop:~$ sudo ufw status  
> [sudo] password for mexekanez:  
> Status: inactive

My laptop IP: 192.168.0.103

running preload command on it

where is an issue?

I have all ports opened on openBalenaOS

---

<div class="post-metadata">

**Author:** ![mexekanez](https://avatars.discourse-cdn.com/v4/letter/m/73ab20/32.png) [@mexekanez](https://forums.balena.io/u/mexekanez)\
**Post date:** [October 1, 2019, 11:51am UTC](https://forums.balena.io/t/incude-script-in-initial-image/34640/23 "2019-10-01T11:51:18Z")

</div>

@here any thoughts?

---

<div class="post-metadata">

**Author:** ![afitzek](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/afitzek/32/359_2.png) [@afitzek](https://forums.balena.io/u/afitzek)\
**Post date:** [October 1, 2019, 12:16pm UTC](https://forums.balena.io/t/incude-script-in-initial-image/34640/24 "2019-10-01T12:16:36Z")

</div>

Hi,  
Could you try to run `balena-preload` from your laptop with `NODE_EXTRA_CA_CERTS=~/open-balena/config/certs/root/ca.crt`. Maybe the problem is that balena-preload cannot verify the self signed CA certificate.

---

<div class="post-metadata">

**Author:** ![mexekanez](https://avatars.discourse-cdn.com/v4/letter/m/73ab20/32.png) [@mexekanez](https://forums.balena.io/u/mexekanez)\
**Post date:** [October 1, 2019, 4:47pm UTC](https://forums.balena.io/t/incude-script-in-initial-image/34640/27 "2019-10-01T16:47:22Z")

</div>

nope, doesn’t works @afitzek

---

<div class="post-metadata">

**Author:** ![mexekanez](https://avatars.discourse-cdn.com/v4/letter/m/73ab20/32.png) [@mexekanez](https://forums.balena.io/u/mexekanez)\
**Post date:** [October 1, 2019, 5:09pm UTC](https://forums.balena.io/t/incude-script-in-initial-image/34640/28 "2019-10-01T17:09:12Z")

</div>

where I can check logs in OpenBalena?

---

<div class="post-metadata">

**Author:** ![robertgzr](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/robertgzr/32/1387_2.png) [@robertgzr](https://forums.balena.io/u/robertgzr)\
**Post date:** [October 1, 2019, 5:19pm UTC](https://forums.balena.io/t/incude-script-in-initial-image/34640/29 "2019-10-01T17:19:32Z")

</div>

How are you running it? Did you follow the instructions here: [https://www.balena.io/open/docs/getting-started/](https://www.balena.io/open/docs/getting-started/)?

---

<div class="post-metadata">

**Author:** ![mexekanez](https://avatars.discourse-cdn.com/v4/letter/m/73ab20/32.png) [@mexekanez](https://forums.balena.io/u/mexekanez)\
**Post date:** [October 1, 2019, 5:21pm UTC](https://forums.balena.io/t/incude-script-in-initial-image/34640/30 "2019-10-01T17:21:57Z")

</div>

yes.

also I have the same issue with balena cloud:

```
mexekanez@mexekanezlaptop:~$ DEBUG=1 balena-preload --commit 189631023ad438125eab7e6f6f25ab41096fad9e --app 1504381 --img ./balena.img --api-token 123456
Building Docker preloader image. [===] 12%
Step 1/7 : FROM docker:17.10.0-ce-dind
Building Docker preloader image. [======] 25%
Step 2/7 : RUN apk update && apk add --no-cache python3 parted btrfs-progs docker util-linux sfdisk file coreutils sgdisk
 ---> Using cache
Building Docker preloader image. [=========] 37%
Step 3/7 : COPY ./requirements.txt /tmp/
 ---> Using cache
Building Docker preloader image. [============] 50%
Step 4/7 : RUN pip3 install -r /tmp/requirements.txt
 ---> Using cache
Building Docker preloader image. [===============] 62%
Step 5/7 : COPY ./src /usr/src/app
 ---> Using cache
Building Docker preloader image. [==================] 75%
Step 6/7 : WORKDIR /usr/src/app
 ---> Using cache
Building Docker preloader image. [=====================] 87%
Step 7/7 : CMD ["python3", "/usr/src/app/preload.py"]
 ---> Using cache
 ---> 3200b63da1b5
Successfully built 3200b63da1b5
Building Docker preloader image. [========================] 100%

/ Creating preloader container
- Starting preloader container
\ Fetching application 1504381
| Reading image informationWaiting for Docker to start...
/ Reading image informationDocker started
\ Reading image information
Leaving splash image alone
| Resizing partitions and waiting for dockerd to startWaiting for Docker to start...
\ Resizing partitions and waiting for dockerd to startDocker started

/ Cleaning up temporary files

{ Error: (HTTP code 500) server error - Get https://registry2.balena-cloud.com/v2/: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers) 
    at /usr/local/lib/node_modules/balena-preload/node_modules/docker-modem/lib/modem.js:257:17
    at IncomingMessage.<anonymous> (/usr/local/lib/node_modules/balena-preload/node_modules/docker-modem/lib/modem.js:284:9)
    at emitNone (events.js:111:20)
    at IncomingMessage.emit (events.js:208:7)
    at endReadableNT (_stream_readable.js:1064:12)
    at _combinedTickCallback (internal/process/next_tick.js:138:11)
    at process._tickCallback (internal/process/next_tick.js:180:9) reason: 'server error', statusCode: 500, json: null }

Looks like this might be an issue with balena-preload. Please report it at https://github.com/balena-io/balena-preload/issues

```

really confused…

mexekanez@mexekanezlaptop:~$ balena -v

```
(node:10669) Error Plugin: balena-cli: files attribute must be specified in /usr/local/lib/node_modules/balena-cli/package.json

module: @oclif/config@1.13.0

plugin: balena-cli

root: /usr/local/lib/node_modules/balena-cli

See more details with DEBUG=*

11.13.0

```

Docker version 19.03.2, build 6a30dfc

what else I can check to get point where it doesn’t works?

---

<div class="post-metadata">

**Author:** ![chrisys](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/chrisys/32/1731_2.png) [@chrisys](https://forums.balena.io/u/chrisys)\
**Post date:** [October 1, 2019, 11:02pm UTC](https://forums.balena.io/t/incude-script-in-initial-image/34640/36 "2019-10-01T23:02:00Z")

</div>

@mexekanez it’s strange that you would have the same/similar error for both different methods.

Looking at the first log you posted I note the section `dial tcp: lookup registry.visoagent.xyz on 192.168.0.1:53: read udp 192.168.0.103:35298->192.168.0.1:53: i/o timeout`. This looks like it’s trying to contact a DNS server on your local network, and failing. It would make sense that both methods fail in the same fashion if the container is unable to resolve DNS for either of them. It’s hard to speculate any further without knowing your network setup but perhaps this is something to look into?

---

<div class="post-metadata">

**Author:** ![mexekanez](https://avatars.discourse-cdn.com/v4/letter/m/73ab20/32.png) [@mexekanez](https://forums.balena.io/u/mexekanez)\
**Post date:** [October 2, 2019, 7:38am UTC](https://forums.balena.io/t/incude-script-in-initial-image/34640/38 "2019-10-02T07:38:27Z")

</div>

I checked /etc/resolv.conf  
and put

> nameserver 8.8.8.8  
> nameserver 8.8.4.4  
> nameserver 127.0.0.53

---

<div class="post-metadata">

**Author:** ![roman-mazur](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/roman-mazur/32/2194_2.png) [@roman-mazur](https://forums.balena.io/u/roman-mazur)\
**Post date:** [October 2, 2019, 9:16am UTC](https://forums.balena.io/t/incude-script-in-initial-image/34640/39 "2019-10-02T09:16:48Z")

</div>

@mexekanez So did the change help with the issue?

[Next page](https://forums.balena.io/t/incude-script-in-initial-image/34640.md?page=2)
