Raspberry Pi OS Rootfs ROMing – How to Add Packages While Making it a RAM Disk

I’m exploring the process of enabling RAM Disk and implementing a read-only root filesystem on a Raspberry Pi while incorporating Soracom connectivity.

Testing Environment:

  • Raspberry Pi 3 Model B+
  • Raspberry Pi OS (Lite; 32bit; 2020-12-02)
  • Soracom SIM SKU#4573326590334

Activate Soracom SIM:

Before proceeding with the RAM Disk and read-only root filesystem setup, activate your Soracom SIM using the following steps:

  • Insert the Soracom SIM SKU#4573326590334 into your Raspberry Pi.
  • Connect your Raspberry Pi to the internet.
  • Register an account on the Soracom platform (https://console.soracom.io/).
  • Once registered, log in to the Soracom console and navigate to the SIM Management section.
  • Locate the Soracom SIM SKU#4573326590334 and click on the SIM’s ID.
  • Follow the instructions provided to activate the SIM and complete the necessary configurations.

Enable RAM Disk:

To enable RAM Disk, follow these steps:

  • Open a terminal and run the following commands:
ruby

$ sudo raspi-config nonint enable_overlayfs $ sudo systemctl reboot 
  • After the reboot, the Raspberry Pi will boot from the RAM disk using overlayfs.

Disable RAM Disk:

If you want to disable RAM Disk and boot from the microSD card, follow these steps:

  • Open a terminal and run the following commands:
ruby

$ sudo raspi-config nonint disable_overlayfs $ sudo systemctl reboot 
  • After the reboot, the Raspberry Pi will boot from the microSD card.

Checking Current Configuration:

To check the current RAM Disk configuration, run the following command:

shell

$ sudo raspi-config nonint get_overlay_now && echo "enabled" || echo "disabled"

This command will display whether the RAM Disk is enabled or disabled.

Summary:

The process of converting the Raspberry Pi OS root filesystem to a read-only configuration was performed based on the instructions provided in the memo titled “RaspberryPi: Read-only Root-FS (using overlayfs).” The steps outlined in the memo were further investigated and packaged for personal use.

The conversion process utilizes overlayfs, as explained in the memo titled “RaspberryPi: Read-only Root-FS (using overlayfs).”

Post-Execution:

After executing the commands, you can use the following commands to verify the filesystem configuration:

bash

$ df -h /dev/mmcblk0p2 30G 1.1G 28G 4% /mnt/root-ro tmpfs 464M 712K 463M 1% /mnt/root-rw overlay 464M 712K 463M 1% / $ mount /dev/mmcblk0p2 on /mnt/root-ro type ext4 (ro) tmpfs on /mnt/root-rw type tmpfs (rw) overlay on / type overlay (rw)

Configuring Your Own Package and Settings on Raspberry Pi:

After following the instructions for converting to a read-only root filesystem using overlays, you have two options to install packages and software:

Option A: Mount the SD card as read/write (RW) and boot normally.

Option B: Remount the SD card as RW and then use chroot.

Option A: Mounting the SD Card as RW and Booting:

  • Open the /boot/config.txt file and comment out the line that says initramfs initrd.gz. Save the changes.
  • Reboot the Raspberry Pi. It will now boot normally from the SD card.
  • You can use apt or edit the necessary files, as the Raspberry Pi OS is now booted normally from the SD card.
  • Reboot again if required and revert to read-only (RO) mode.

Option B: Remounting the SD Card as RW and Using chroot:

    1. Mount /mnt/root-ro as read/write (RW) and then use chroot to execute the following commands:
shell

$ sudo -s # mount -o remount,rw /mnt/root-ro # chroot /mnt/root-ro # mount -t proc proc /proc
  1. Configure the necessary settings and install packages. Ensure that the required communication services such as D-Bus are available for successful execution.

  2. Clean up if necessary and reboot the Raspberry Pi.

Permanent Data Storage on Your Raspberry Pi:

To store permanent data such as logs, you can implement a local persistent storage solution at the bottom of the initramfs.

Conclusion:

Congratulations on implementing the RAM Disk and read-only root filesystem on your Raspberry Pi while incorporating Soracom connectivity. By following these technical steps, you can optimize the performance and security of your Raspberry Pi IoT projects.

4 Likes