Skip to content

Instantly share code, notes, and snippets.

@ZwCreatePhoton
Created August 31, 2021 03:57
Show Gist options
  • Save ZwCreatePhoton/be78495e2a6903c22e4c3be4766c0f7b to your computer and use it in GitHub Desktop.
Save ZwCreatePhoton/be78495e2a6903c22e4c3be4766c0f7b to your computer and use it in GitHub Desktop.
OctoPrint on piCore

Intro

This is how to install OctoPrint on piCore (Tiny Core Linux) running on a Raspberry Pi 1 Model B. This model has very little ram so running recent versions of OctoPrint on OctoPi or OctoPrint+Raspbery OS Lite will not do. There was not already instruction on the internet on this. The overall installation was not trivial. Processes kept getting killed during the pip install for a few OctoPrint dependencies due to lack of free memory during compilation. Piwheels was needed to avoid the intensive task of compilation on the pi.

(Prereq) Install piCore on the Pi

  1. Download piCore
  2. Flash piCore image to an SD card using dd or Etcher
  3. Load piCore on the Pi
  4. Increase the size of partition 2 (See the piCore readme)
  5. (Optional) Take an image backup of the SD card to have a clean piCore image

(Optional) Overclock the Pi

sudo cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq
sudo mount /mnt/mmcblk0p1
vi /mnt/mmcblk0p1/config.txt
# Uncomment and set arm_freq to a value between 700 and 1000. Max overclock frequency without overvolting varies per system. My system used 950.
sudo umount /mnt/mmcblk0p1
sudo reboot
sudo cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq
# scaling_max_freq rounds up to the nearest 100 MHZ

Install OctoPrint

sudo vi /opt/tcemirror
# Change the url to this:
# http://distro.ibiblio.org/tinycorelinux
filetool.sh -b
tce-load -wi python3.9
# Ram on Raspberry Pi 1 / zero is very limited, so the linux tmp directory, the pip cache directory, and the OctoPrint virtual environment need to be on persistent storage.
# Other Pis with more ram can avoid the persistent storage and use the /opt directory instead
cd /mnt/mmcblk0p2/tce
# cd /opt
mkdir octoprint
cd octoprint
mkdir tmp
export TMPDIR="$(pwd)/tmp"
mkdir cache
python3 -m venv venv
./venv/bin/python -m pip install --cache-dir "$(pwd)/cache" --upgrade pip
./venv/bin/python -m pip install --cache-dir "$(pwd)/cache" wheel
./venv/bin/python -m pip install --cache-dir "$(pwd)/cache" --index-url=https://piwheels.org/simple octoprint
rm -r -f tmp/*
rm -r -f cache/*
# The octoprint user directory can be stored on the persistent disk too if lots of models will be stored on the server.
echo /home/tc/.octoprint >> /opt/.filetool.lst
filetool.sh -b
./venv/bin/octoprint serve
# Wait for OctoPrint to finish initializing (~5 for pi 1/0) then exit OctoPrint.
# ^C
filetool.sh -b
sudo reboot
cd /mnt/mmcblk0p2/tce
./octoprint/venv/bin/octoprint serve

End

The final size of the OctoPrint virtual environment for this setup was 101.1 MB. If this were made 10-30 MB smaller some how, it can be moved off the persistent disk and onto ram. Does a lite version OctoPrint exist? ✯ ✯ ✯

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