Run Klipper/OctoPrint In Void Linux
Published: 2021-11-24 01:42:52

---
title: Run Klipper/OctoPrint In Void Linux
published: true
description: How to install and run Klipper from a Laptop running a Debian Based Distribution
tags: 
//cover_image: https://imgur.com/a/RwlyTwb
---
This is a guide for installing Klipper and Octoprint on Void Linux
![octovoid_v1](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q19x0bgit0ccd8a8czv4.png)

It is broken into 3 sections,
1. Installing __Klipper__
2. Installing __Octoprint__
3. Installing __Webcam__

Each Section is broken into numbered steps. It is a lot but very dueable, it is mostly copy+paste. That said you should always try and understand what you paste into your console.

---

## Klipper

I am assuming you have a `printer.cfg` file in your home directory, your printer is connted via USB and you know kinda how to use a terminal.

I have made a new user `pi`, to keep things as close to the raspberry-pi setup as I can. I recommend you do this as well.

To make a new user
```
### Login as root
su
# create the new user
useradd -m -G dialout,tty -s /bin/bash pi
```
> __make sure the user pi is part of the dialout and tty groups__
Add this user to sudoers with `visudo` command, google if you need help with vi or install nano and run `EDITOR=nano visudo` from root.

You will need python2 for this to run and python3 to set it up. As of writing this python2 in Void Linux is called `python` in xbps and python3 is `python3`. I think they are working on making everything python3 and there is a python3 branch that I have tested and works without Python2 but I am not sure how complete that is. 

### Now that the user is set up and you are logged in as pi, do the following....


1. Install system dependencies

```bash
sudo xbps-install -S python python3 python3-pip python3-devel python3-setuptools git base-devel libffi-devel libyaml-devel avrdude avr-gcc avr-binutils avr-libc
```

2. Clone Klipper Repo from github

```bash
cd ~/
git clone https://github.com/Klipper3d/klipper.git klipper
cd klipper
```

3. Setup python-venv

```bash
python3 -m venv venv
source venv/bin/activate
```

4. Install Dependencies

```bash
./venv/bin/python -m pip install --upgrade pip
./venv/bin/pip install -r scripts/klippy-requirements.txt
```

5. Create runsv service(runit) direcotry and file

```bash
sudo mkdir /etc/sv/klipper
sudo touch /etc/sv/klipper/run
sudo chmod +x /etc/sv/klipper/run
```

6. Edit the file `/etc/sv/klipper/run`

```bash
#!/bin/bash
export USER=pi
export HOME=/home/pi
groups="$(id -Gn "$USER" | tr ' ' ':')"

exec chpst -u "$USER:$groups" "$HOME"/klipper/venv/bin/python "$HOME"/klipper/klippy/klippy.py "$HOME"/printer.cfg -l /tmp/klippy.log
```

7. Enable klipper

```bash
sudo ln -srv /etc/sv/klipper /var/service
```

8. It be a good idea to reboot too.

After this plug in your printer if is not already, make sure you have your printer.cfg in your home dir, `sudo sv restart klipper` and you should be connected. I have an ender 3 with LCD enabled so I could confirm at this point that the LCD menu works. On to OctoPrint.

---

## OctoPrint

All of the dependencies got installed in the Klipper install, so this is pretty simple.
1. make the directory
```bash
cd ~
mkdir OctoPrint && cd OctoPrint
```
2. Setup Python3 venv
```bash
python3 -m venv venv
source venv/bin/activate
```
3. Install Octoprint
```bash
./venv/bin/pip install pip --upgrade
./venv/bin/pip install octoprint
```

4. Create runsv service(runit) direcotry and file

```bash
sudo mkdir /etc/sv/octoprint
sudo touch /etc/sv/octoprint/run
sudo chmod +x /etc/sv/octoprint/run
```

5. Edit the file `/etc/sv/octoprint/run`

```bash
#!/bin/bash
export USER=pi
export HOME=/home/pi
groups="$(id -Gn "$USER" | tr ' ' ':')"

exec chpst -u "$USER:$groups" "$HOME"/OctoPrint/venv/bin/octoprint serve

```

6. Enable Octoprint
```
sudo ln -srv /etc/sv/octoprint /var/service
```

Another restart might be good.

Once you open Octoprint in the browser you should install the OctoKlipper plugin.

By default the octoprint instance runs on port `5000`. So something like `localhost:5000` should get you there, or the ip of the machine with void.


---


## Webcam

1. __Install some things__
```bash
sudo xbps-install subversion libjpeg-turbo-devel ffmpeg 
cmake
```

2. __Get the repo and build it__
```bash
git clone https://github.com/jacksonliam/mjpg-streamer.git
cd mjpg-streamer/mjpg-streamer-experimental
export LD_LIBRARY_PATH=.
make
```

3. __Test it__
```bash
./mjpg_streamer -i "./input_uvc.so" -o "./output_http.so -w ./www"
```
Press Control-C to exit
You may have to add a device. in my case my laptop has a built in camera but I want to use the USB one, so I use(example)
```bash
./mjpg_streamer -i "./input_uvc.so -d /dev/video2" -o "./output_http.so -w ./www"
```
    The `-d /dev/video2` part is different.
    You can this will give you a video feed on port `8080`.


4. __Setup Octoprint__  
In octoprint goto settings and webcam & timelapse section. In the "Stream URL" section put the http://ip:port/?action=stream, example `http://192.168.0.24:8080/?action=stream`. 
If you want Timelapse enter the same http://ip:port part but with `/?action=snapshot` at the end, example `http://192.168.0.24:8080/?action=snapshot`
You should know have a video feed.

5. __Setting it up to autostart. first make the files__
```bash
sudo mkdir /etc/sv/octocam
sudo touch /etc/sv/octocam/run
sudo chmod +x /etc/sv/octocam/run
```
6. __Create a executable file that has the start command__  
I had trouble getting this to work any other way I tried, you need to make a file, `/home/pi/bin/octocam_run`, like so
```
mkdir ~/bin
touch ~/bin/octocam_run
chmod +x ~/bin/octocam_run
```
__Next, put the following into the `/home/pi/bin/octocam_run` file__
```
#!/bin/bash

MJPGSTREAMER_HOME=/home/pi/mjpg-streamer/mjpg-streamer-experimental
camera_options="-r 640x480 -f 10"

pushd $MJPGSTREAMER_HOME
LD_LIBRARY_PATH=. ./mjpg_streamer -o "output_http.so -w ./www" -i "input_uvc.so $camera_options -d /dev/video2"
popd

```

7. **Add content to the `/etc/sv/octocam/run` file**
```bash
#!/bin/bash
export USER=pi
export HOME=/home/pi
groups="$(id -Gn "$USER" | tr ' ' ':')"

exec chpst -u "$USER:$groups" /home/pi/bin/octocam_run

```
8. **last add it to your services**
```bash
sudo ln -sv /etc/sv/octocam /var/service
```

If you have not, maybe do a reboot.

Please let me know if I have messed anything up if there is a better way to do this. And any errors your eyes sea please.

__Sources__

    - Klipper Install
        - https://www.klipper3d.org/Installation.html
    - Void Docs
        -https://docs.voidlinux.org/config/services/index.html
        - https://docs.voidlinux.org/config/services/user-services.html
    - OcotPrint Help
        - https://community.octoprint.org/t/setting-up-octoprint-on-a-raspberry-pi-running-raspbian-or-raspberry-pi-os/2337
    - And the install scripts from klipper, a few man pages here and there.