# Klipper-mcu Service Fails to Start

**URL:** <https://klipper.discourse.group/t/klipper-mcu-service-fails-to-start/12219>\
**Category:** Knowledge Base\
**Created:** [December 11, 2023, 7:16pm UTC](https://klipper.discourse.group/t/klipper-mcu-service-fails-to-start/12219 "2023-12-11T19:16:28Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sineos](https://yyz2.discourse-cdn.com/free1/user_avatar/klipper.discourse.group/sineos/32/18_2.png) [@Sineos](https://klipper.discourse.group/u/Sineos)\
**Post date:** [December 11, 2023, 7:16pm UTC](https://klipper.discourse.group/t/klipper-mcu-service-fails-to-start/12219/1 "2023-12-11T19:16:28Z")

</div>

### Background

The [klipper-mcu](https://www.klipper3d.org/RPi_microcontroller.html) process fails to start on certain Linux distributions, even when the relevant documentation is carefully followed.

This issue primarily affects Armbian Linux distributions or those based on Armbian.

### Diagnosing the issue

The easiest way to recognize this problem is in the `klippy.log` where an error message like

```auto
mcu 'rpi': Unable to open port: [Errno 2] No such file or directory: '/tmp/klipper_host_mcu'

```

will appear.

Further issuing the command:

```auto
systemctl status klipper-mcu

```

yields following result:

```auto
klipper@bigtreetech-cb1:~# systemctl status klipper-mcu
● klipper-mcu.service - Starts the MCU Linux firmware for klipper on startup
     Loaded: loaded (/etc/systemd/system/klipper-mcu.service; enabled; preset: enabled)
     Active: activating (auto-restart) (Result: exit-code) since Mon 2023-12-11 19:39:56 CET; 4s ago
       Docs: https://www.klipper3d.org/RPi_microcontroller.html
    Process: 2408 ExecStart=/usr/local/bin/klipper_mcu -r -I ${KLIPPER_HOST_MCU_SERIAL} (code=exited, status=255/EXCEPTION)
   Main PID: 2408 (code=exited, status=255/EXCEPTION)
        CPU: 6ms

```

and finally, the commands:

```auto
sudo service klipper-mcu restart
# Wait around 30 seconds before issueing the following command:
sudo journalctl -u klipper-mcu

```

Produces following output:

```auto
Dec 11 19:17:48 cb1 systemd[1]: Started klipper-mcu.service - Starts the MCU Linux firmware for klipper on startup.
Dec 11 19:24:47 cb1 systemd[1]: Stopping klipper-mcu.service - Starts the MCU Linux firmware for klipper on startup...
Dec 11 19:24:48 cb1 systemd[1]: klipper-mcu.service: Deactivated successfully.
Dec 11 19:24:48 cb1 systemd[1]: Stopped klipper-mcu.service - Starts the MCU Linux firmware for klipper on startup.
Dec 11 19:24:48 cb1 systemd[1]: Started klipper-mcu.service - Starts the MCU Linux firmware for klipper on startup.
Dec 11 19:24:48 cb1 klipper_mcu[1934]: Got error -1 in sched_setscheduler: (1)Operation not permitted
Dec 11 19:24:48 cb1 systemd[1]: klipper-mcu.service: Main process exited, code=exited, status=255/EXCEPTION
Dec 11 19:24:48 cb1 systemd[1]: klipper-mcu.service: Failed with result 'exit-code'.
Dec 11 19:24:53 cb1 systemd[1]: klipper-mcu.service: Scheduled restart job, restart counter is at 1.
Dec 11 19:24:53 cb1 systemd[1]: Stopped klipper-mcu.service - Starts the MCU Linux firmware for klipper on startup.
Dec 11 19:24:53 cb1 systemd[1]: Started klipper-mcu.service - Starts the MCU Linux firmware for klipper on startup.
Dec 11 19:24:53 cb1 klipper_mcu[1937]: Got error -1 in sched_setscheduler: (1)Operation not permitted

```

The key error message here is:

```auto
Dec 11 19:24:53 cb1 klipper_mcu[1937]: Got error -1 in sched_setscheduler: (1)Operation not permitted

```

### Reason for the error

To achieve highly precise timing, the `klipper_mcu` is operated in real-time mode. However, the kernel of these distributions requires _Real-Time Group Scheduling_, which is incompatible with `systemd` and causes relevant calls to fail.

### Temporary Fix

To test the solution, a temporary fix can be deployed by issuing the command:

```auto
sudo sysctl -w kernel.sched_rt_runtime_us=-1
sudo service klipper-mcu restart

```

If now the service starts successfully, which can be again verified with `systemctl status klipper-mcu`, the fix can be made permanent.

### Permanent Fix

Adjusting kernel parameters should only be done after confirming that this approach effectively solves the problem. Run the following command to make the changes permanent:

```auto
echo "kernel.sched_rt_runtime_us = -1" | sudo tee /etc/sysctl.d/10-disable-rt-group-limit.conf
# Now reboot the system to verify 
sudo reboot now

```

Credits go to @Piezo for this fix.
