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

**URL:** <https://forums.balena.io/t/is-data-partition-read-only-copy-on-write-to-ram-when-container-is-running/62568>\
**Category:** balenaOS\
**Created:** [February 10, 2020, 10:01pm UTC](https://forums.balena.io/t/is-data-partition-read-only-copy-on-write-to-ram-when-container-is-running/62568 "2020-02-10T22:01:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ciantic](https://avatars.discourse-cdn.com/v4/letter/c/8797f3/32.png) [@Ciantic](https://forums.balena.io/u/Ciantic)\
**Post date:** [February 10, 2020, 10:01pm UTC](https://forums.balena.io/t/is-data-partition-read-only-copy-on-write-to-ram-when-container-is-running/62568/1 "2020-02-10T22:01:29Z")

</div>

Is the “Data Partition” ([seen in this diagram](https://www.balena.io/docs/reference/OS/overview/2.x/#stateless-and-read-only-rootfs)) 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.

---

<div class="post-metadata">

**Author:** ![Ciantic](https://avatars.discourse-cdn.com/v4/letter/c/8797f3/32.png) [@Ciantic](https://forums.balena.io/u/Ciantic)\
**Post date:** [February 10, 2020, 10:16pm UTC](https://forums.balena.io/t/is-data-partition-read-only-copy-on-write-to-ram-when-container-is-running/62568/2 "2020-02-10T22:16:44Z")

</div>

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 \
    ' > test.sh

CMD ["/bin/bash", "test.sh"]

```

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`

Thanks.

---

<div class="post-metadata">

**Author:** ![tmigone](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/tmigone/32/2814_2.png) [@tmigone](https://forums.balena.io/u/tmigone)\
**Post date:** [February 11, 2020, 6:12pm UTC](https://forums.balena.io/t/is-data-partition-read-only-copy-on-write-to-ram-when-container-is-running/62568/4 "2020-02-11T18:12:44Z")

</div>

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:

```auto
version: 2.1

services:
  test:
    build: .
    tmpfs:
      - /test

```

And the `Dockerfile`:

```auto
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' > test.sh

RUN chmod +x test.sh

CMD ["/bin/bash", "test.sh"]

```

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.
