Skip to content

Instantly share code, notes, and snippets.

@basilfx
Last active May 21, 2023 06:01
Show Gist options
  • Save basilfx/a099d4f64407c42e716d to your computer and use it in GitHub Desktop.
Save basilfx/a099d4f64407c42e716d to your computer and use it in GitHub Desktop.
OctoPi to Read-only

OctoPi to Read-only

These steps will provide a read-only OctoPi installation while still having a read/write home directory. In other words, as long as you don't have to update system files, this installation will be fully functional.

  • Install OctoPi on a 8GB (or more) SD card and boot it at least once.
  • Mount it with a Linux machine (e.g. Ubuntu).
  • Use sudo gparted and configure the remaining space as EXT4.
  • There are now three partitions. Mount the last two.
  • Move /home/pi to the new and empty partition.
  • Edit /etc/fstab:
    • Add ro to the options of /dev/mmcblk0p2
    • Append /dev/mmcblk0p3 /home ext4 defaults,noatime 0 2
  • Unmount the SD card and boot OctoPi.
  • Temporary mount the filesystem read-write using sudo mount -o rw,remount /.
  • Replace syslog with an in-memory alternative:
    • Run sudo apt-get install busybox-syslogd
    • Run sudo dpkg --purge rsyslog
    • You can read the syslog using logread
  • Edit /etc/default/tmpfs:
    • Uncomment and change RAMTMP to yes
    • Uncomment TMPFS_SIZE
  • Run sudo systemctl enable tmp.mount.
  • Symlink /etc/resolv.conf to a read-write location, so your DNS servers get updated by resolvconf service:
    • Run sudo rm /etc/resolv.conf
    • Run sudo ln -s /var/run/resolv.conf /etc/resolv.conf
    • Edit /etc/resolvconf.conf and change resolv_conf to /var/run/resolv.conf
  • Edit /etc/default/webcamd:
    • Change LOG to /tmp/webcamd.log
  • Reboot!

To mount the filesystem for read/write, simply use sudo mount -o rw,remount /. This will be reverted on next boot.

Note that the /home/pi folder is still read/write. If the power fails, any files (logs, plugins, timelapses) written to that partiton may be lost, but the system is still capable of booting (and recovering).

@newzealandpaul
Copy link

Just a note to everyone trying this, the current latest version of octopi (2015-05-05-octopi-wheezy-0.12.0.img) does not have the systemctl command. I have not used that command but it worked for me anyway.

Also if you are doing this on the pi itself, you can create the new partition by using the following commands:

$ sudo parted -s /dev/mmcblk0 -- mkpart primary ext4 3400MB -1
$ sudo mkfs.ext4 /dev/mmcblk0p3

This creates and formats a new ext4 partition that will consume all the remaining free space.

@CraigRK
Copy link

CraigRK commented Jan 14, 2016

Not being too hot on Linux, could a similar approach be to move /home/pi to an external drive or share?

I have a Linux based NAS, and I like the idea of putting the various logs, time lapse and upload folders on the NAS, so the RasPi is effectively just the processor. Then while I could/would run separate RasPis for multiple printers, I would be able to access the logs and upload files on both and on my PC without ruining SD cards. (Lower writes/corruption)

@basilfx
Copy link
Author

basilfx commented Jan 28, 2016

Yes, that should be possible, in theory. But I don't know if any services depend on /home/pi while booting, and if that directory is mounted on time. NFS should be a decent way to mount it externally, in this case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment