This is a convenient wrapper script to run bash with a swapfile and temporary folder with more capacity. The need for this script comes from The 100 printers where Banana Pi M2 Zero needs to install numpy and other Python packages which have a memory hungry build process.
The script does the following thigs:
- Sets up a swapfile and enables it
- Creates a temporary directory and assigns it appropriately
- Cleans up after itself when the shell exits
To use the script, first download the script on the target machine using your preferred tools. Run the script and then run the commands which take significant amounts of ram.
for example:
printer@printer:~$ ./swappy-shell.sh
Swapfile has been created and activated!
[..]
(swappy-shell)printer@printer:~$ ~/klippy-env/bin/pip3 install numpy
[..long output here..]
(swappy-shell)printer@printer:~$ exit
## Cleaning up swapfile
While I don't recommend running arbitrary scripts from the internet without auditing them first. You can run the following one liner to start a swappy shell. If you trust me to do the right thing that is...
Run the following:
bash <(curl -s https://gist.githubusercontent.com/ressu/0611ba0c505af6b1d0a3704f38c5f260/raw/swappy-shell.sh)
The swapfile will be available for all processes on the system and not just the
shell. The temporary directory that is set up by this script on the other hand
is only set up in the interactive shell. Since the /tmp
diretory in Armbian is
created on a memory backed device, it's common to get disk full errors for
temporary files. This is why the script creates both swap and temporary
directory on the sdcard.
It's not recommended to use the environment for regular work as both the temporary files and the swap put extra strain on the sdcard shortening the lifespan. (It's fine to do this short term though)
You have the shell running, now what?
To install latest numpy for Klipper on Armbian, the ninja build system needs to be installed before. The following gets you up and running
sudo apt install libatlas-base-dev ninja-build
~/klippy-env/bin/pip3 install numpy
NOTE: SciPy is only needed in special cases, so in a normal installation there is no need to install it.
SciPy is like the more demanding big brother for numpy. while numpy gets going with ease, SciPy needs a bit more.
sudo apt install libatlas-base-dev libopenblas-dev gfortran ninja-build
pip3 install scipy ## Adjust this to match what ever location you need for the installation