I am trying to deploy I simple text file on a Nerves BBB device application partition. For this I created custom config/fwup.conf
where I add an custom file-resource just below the rootfs.img
like this:
file-resource test.txt {
host-path = "${NERVES_APP}/config/test.txt"
}
The text file is also under config/test.txt
In the task upgrade.b …
on-resource test.txt { fat_write(${ROOTFS_B_PART_OFFSET}, "test.txt") }
When I start ./upload.sh
I get fwup
message:
./upload.sh
Path: ./_build/bbb_dev/nerves/images/hello_nerves.fw
Product: hello_nerves 0.1.0
UUID: 4cc602a0-71dc-5398-5a5c-bf4727494331
Platform: bbb
Uploading to nerves.local...
Running fwup...
fwup: Upgrading partition B
fwup: Can't open file on FAT partition(test.txt): FATFS: There is no valid FAT volume
Is there a way deploy a file or file bundle resource on the application partition?
1 Like
Hi Koleto,
There are several ways of putting files on Nerves devices. Here are the compile-time ways:
- Add the file to your application’s or library’s
priv
directory. Then use :code.priv_dir/1
or Application.app_dir/2
to get a path to it. The file will be read-only on the device.
- Configure a
rootfs_overlay
. This lets you put a file in any directory on the root filesystem. It will still be read-only.
- Edit the
fwup.conf
to add a file to the boot partition. Unless you need to modify the bootloader or update kernel device tree overlays, I’d stay away from this. The boot filesystem is small and since your device depends on it to boot up, it’s generally a good idea to leave it be.
I highly recommend sticking with option 1 if you can.
If you need a file to be writable, the recipe is to add code to your app that initializes files or directories under /root
. For example, if you have a sqlite database that’s been pre-seeded, you’d add the database file to a priv
directory. Then at run time, you’d check if /root/mydb.sqlite3
exists. If not, you’d copy over the pre-seeded one from your priv
directory.
When the device is running, you can run sftp
to get and put files on the device.
If none of these options works for you, let me know more about the constraints on the files that you have.
3 Likes
Thank you very much! It was very useful information. I tried rootfs_overlay to put just a text file in /tmp and /opt but somehow I was not able to find the file after flashing the firmware. The firs method is the one I still have to try. I am evaluating Nerves for building a logging system on top of CouchDB. The idea is to have continues replication with another CouchDB server, and still make logging on a write partition. I build similar system working already for 3 years 24/7 but still experiencing some minor problems that I hope to overcome with Nerves. Unfortunately I didn’t found any information on including CouchDB to Nerves, so I build CouchDB release to try to mount as a file bundle on Nerves BBB without modifying the image itself. This is the reason why I tried first to use fwup.
The rootfs_overlay
can put a file most places, but anything in /tmp
won’t be visible since a tmpfs
filesystem is mounted there. The other special locations are /proc
, /sys
, and /dev
. /opt
should have worked. Of course, using priv
directories is still better since it’s namespaced and keeps with Erlang/OTP conventions.
Since it sounds like you’re just making one device, running sftp
to copy your current database on /root
would be easiest, right? Or could the database magically replicate there if you start CouchDB with an empty database there.
Frank
1 Like
sftp is working very well I don’t know why I didn’t try this by myself it is probably because I try to use scp but this didn’t work. For my first test evaluation sftp is working perfect…
Thank you Frank!
1 Like