Is data partition read-only & copy-on-write to RAM when container is running?

Is the “Data Partition” (seen in this diagram) read-only and copy-on-write to RAM when the container is running?

I don’t want my containers (when started) to write anything to SD card. I’m using Raspberry pi 4 with 4GB of memory, there should be plenty of space for everything to be kept in memory.

Ideally only time the balenaOS should write to SD card is when I deploy a new image.

I have a Electron kiosk running in a single container, and I’m worried that the cache directories it creates are written to disk. I know how notorious the Chromium is with IO, it is by far the most IO heavy program with it’s cache, even in Windows 10.

I came up a simple Dockerfile example what I mean:

FROM balenalib/raspberrypi3-node

WORKDIR /app/kiosk

RUN printf '\
    #!/bin/bash \n\
    echo "am I written to SD card or to RAM?" > foofile \n\
    /bin/bash \
    ' >

CMD ["/bin/bash", ""]

Is the “foofile” written to RAM and not to the SD card when I run the container? Note The foofile is written at runtime by the container to the /app/kiosk/foofile


Hi, as you point out, balenaOS is stateless and designed to minimize writing data to disk.

That said, your application will make use of the disk unless you specifically tell it to write to memory. To do that, you need to have your app write to a tmpfs. You can use for example /tmp/resin or create your own tmpfs using docker-compose.yml.

I created a simple example to showcase this. For this particular case you could even remove the SD card once it’s booted and it will continue to work:

version: 2.1

    build: .
      - /test

And the Dockerfile:

FROM balenalib/%%BALENA_MACHINE_NAME%%-node
WORKDIR /usr/src
COPY . .

RUN printf '\
    #!/bin/bash \n\
    while : \n\
    do \n\
    date >> /test/test.log \n\
    sleep 1 \n\
    done \n' >

RUN chmod +x

CMD ["/bin/bash", ""]

So in your case, you would need to have Chromium save its cache files on a tmpfs.

Regarding this question:

Is the “foofile” written to RAM and not to the SD card when I run the container?

foofile in this case is part of the image as it is being created when you build it (either locally or by our builders). Afterwards, your device will download and save that image into the disk.

1 Like