Deploying the board
Improve reliability with a read-only file system
Once you have finished developing your instrument, you may want to seal it up in a box and have Bela power it reliably for years to come, powering it on and off by plugging and unplugging the power cable, without having to worry about corrupting its storage. This guide allows you to achieve maximum reliability by setting the file system to read-only. We’ll also explain how to set the file system back to read/write so that you can write to it again.
Table of contents
- Introduction
- Introduction to
/etc/fstab
- Make the root file system read-only
- Making the root file system read-write again
- Limitations
Introduction
The operating system on your Bela boots from either the SD card or the eMMC (embedded memory card, not available on BelaMini). As part of its normal functioning, the operating system may write to the files ystem, for instance for logging purposes. As long as the operating system is gracefully shut down, no data corruption should happen. However, it is possible for the file system to become corrupted when the power cable is pulled. Sometimes these errors are recoverable and are automatically corrected on the next boot; some other times they make the board unbootable. In order to prevent this from ever happening, we can set the file system to read-only so that the operating system never writes to it and no corruption can happen.
Prerequisites
We’ll assume below that:
- you can access the board via
ssh
from a terminal (e.g.:ssh root@bela.local
) - you have enough familiarity with the terminal to browse and edit files
- that you have made a backup of your files from the eMMC or SD card
- if you are setting the fileystem to read-only, that you have already set your program to run on boot and built its latest version
- that your program doesn’t need to write to disk (e.g.: to write log or audio files or settings)
Introduction to /etc/fstab
The file /etc/fstab
is read by your operating system on boot in order to know which file systems should be mounted at which paths. It contains one line per each file system to be mounted automatically. The line starts with the path to the device containing the file system, followed by the mount point (the path at which the root of the file system’s contents will show up), followed by some options.
The device containing the root file system on Bela will be /dev/mmcblk0p2
if you booted from the SD card or /dev/mmcblk1p2
if you booted from the eMMC.
A stock /etc/fstab
on a Bela SD card will look like this:
/dev/mmcblk0p2 / ext4 defaults,noatime 0 1
/dev/mmcblk0p1 /mnt/boot vfat defaults,noatime 0 2
On a Bela eMMC it will look like this:
/dev/mmcblk1p2 / ext4 defaults,noatime 0 1
/dev/mmcblk1p1 /mnt/boot vfat defaults,noatime 0 2
Note the difference between mmcblk0
in the first case and mmcblk1
in the second.
Below we’ll edit this file to modify the default mounting options.
If by editing /etc/fstab you leave it in an invalid state, with syntax error or invalid text, the system may stop booting. Make sure you have your data backed up before you attempt the instructions below.
Make the root file system read-only
To make the root file system read-only, ssh
onto the board and open the file /etc/fstab
in your editor of choice. On the line starting with /dev/mmcblk0p2
or /dev/mmcblk1p2
, append ,ro
(meaning read-only) immediately after defaults,noatime
on each line. Make sure you do so without adding any additional spaces. Additionally, add the following line at the bottom of the file:
tmpfs /var/lib/dhcp tmpfs nosuid,nodev 0 0
The resulting /etc/fstab
should look like this if you booted from SD card:
/dev/mmcblk0p2 / ext4 defaults,noatime,ro 0 1
/dev/mmcblk0p1 /mnt/boot vfat defaults,noatime,ro 0 2
tmpfs /var/lib/dhcp tmpfs nosuid,nodev 0 0
or like this if you booted from eMMC:
/dev/mmcblk1p2 / ext4 defaults,noatime,ro 0 1
/dev/mmcblk1p1 /mnt/boot vfat defaults,noatime,ro 0 2
tmpfs /var/lib/dhcp tmpfs nosuid,nodev 0 0
Once you have checked that the file content is correct, save it and close the editor. To verify there is no invalid syntax, run mount -o remount /mnt/boot
and ensure it doesn’t print any errors. If it does, edit the file again and fix the error.
If your board reboots correctly, your file system will be read-only. If you open the IDE and try to edit or upload a file, create a file or a directory or a project, you will get an error. Success!
Making the root file system read-write again
Once your file system is set to read-only, you may want to set it to read/write again. For instance,eyou may want to update your project, add more audio files to it, or switch to a different program.
The first step is to remount the file system as read/write. To do so, ssh
to the Bela board and run the following command, or run it in the console at the bottom of the IDE:
mount -o remount,rw /
This will remount the file system as read/write as a one-off: it will be like this only until the next reboot.
If you want to make this change permanent and restore the file system to its default read/write state at every boot, you need to open /etc/fstab
in your editor of choice and restore it to its original state shown above.
Limitations
If your program needs to write to disk, the above approach will prevent it from doing so. In this case, we recommend creating another partition that can be mounted as read/write, while keeping the root file system safely read-only. This is beyond the scope of this tutorial, but there are many resources available online.