• Stars
    star
    327
  • Rank 128,686 (Top 3 %)
  • Language
    Shell
  • License
    GNU General Publi...
  • Created almost 4 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Tools for bootstrapping custom kernels on the UniFi Dream Machine

udm-kernel-tools Release

Tools for bootstrapping custom Linux kernels on the Ubiquiti UniFi Dream Machine (Pro).

Introduction

The Ubiquiti UniFi Dream Machine (UDM) and UDM Pro are a class of all-in-one network appliances built by Ubiquiti. These devices are powered by UbiOS, which uses Linux kernel under the hood.

However, the stock kernel on these devices lacks some important functionality needed for common use-cases (such as WireGuard as VPN or multicast routing support for IPTV). In many cases, this functionality can be enabled with a custom Linux kernel.

This repository provides tools to bootstrap a custom Linux kernel on the UDM/P. To prevent bricking your device, this tool does not overwrite the firmware of the device. Instead, it boots directly into the custom kernel from the stock kernel using kexec (see How it works).

Use-cases

There are currently several use-cases for using a custom kernel on the UniFi Dream Machine (Pro). These use-cases include:

  1. In-kernel WireGuard support
    Although you can already run a WireGuard server on your UDM/P using wireguard-go (see udm-utilities), its performance will be reduced due to it running in user-space. A custom kernel enables your WireGuard VPN server to utilize the kernel implementation and run at full speed.
  2. Multicast routing support
    The stock kernel of the UDM/P does not support multicast routing which is needed for running igmpproxy. In turn, igmpproxy is needed to route multicast traffic between WAN and LAN, which is necessary for IPTV. See the following guide for more information.
  3. Early boot modifications
    Since changes to root filesystem on the UDM/P are non-persistent. It is not possible with the stock kernel to perform modification to the early boot process (since the on-boot-script only runs after UniFi OS is started). This project enables you to modify the root filesystem before UbiOS is started. See Overriding files on root pre-boot for more information.

Getting Started

Disclaimer

Although these tools do not modify any firmware on your device, using them might lead to system instability or data loss. Make sure you know what you are doing and ensure you have a backup! I take no responsibility for any damage that might occur as result of using this project.

Entering UniFi OS

To start, SSH into your UniFi Dream Machine (Pro) and enter the UniFi OS shell as follows:

unifi-os shell

Installing udm-kernel-tools

Select from the Releases page the package version you want to install and download the selected Debian package, for instance:

wget https://github.com/fabianishere/udm-kernel-tools/releases/download/v1.1.7/udm-kernel-tools_1.1.7_arm64.deb
apt install ./udm-kernel-tools_1.1.7_arm64.deb

Installing a custom kernel

To obtain and install a custom Linux kernel for the UniFi Dream Machine (Pro), visit the udm-kernel repository. This repository contains instructions for installing the pre-built kernels as well as instructions for building custom kernels yourself.

Booting into a custom kernel

First, list the kernels you have installed on your system as follows:

udm-bootctl list

Booting into a custom kernel is then done as follows:

udm-bootctl boot KERNEL_VERSION

Alternatively, you may specify the path to the kernel image. Note that after executing this command, the SSH connection might become unresponsive or might even be killed with an error message. This is expected behavior and after a minute, you should be able to log back into your device via SSH.

Once the system is back online, verify that you are running the correct kernel:

uname -a

Auto-booting into the custom kernel

Since the custom kernel does not persist across reboots due to the use of kexec, you need to perform the boot procedure after every reboot. We provide a udm-autoboot.service to automate this process.

First, select the default kernel you want to boot into:

udm-bootctl set-default KERNEL_VERSION

Then, enable the udm-autoboot.service to run during system startup:

systemctl enable udm-autoboot.service

Disabling auto-boot
To disable this functionality again, run the following command:

systemctl disable udm-autoboot.service

Overriding files on root pre-boot

Some users may wish to modify files on the root filesystem before UniFi OS boots (e.g., to hook into the early boot process). In order to facilitate this, udm-kernel-tools allows users to override files from the root filesystem using an overlay located at /mnt/data/udm-kernel-tools/root,

The overlay filesystem will be mounted only after running mkdir -p /overlay/root_ro/mnt/data/udm-kernel-tools/root from within the UniFi OS shell or when running mkdir -p /data/udm-kernel-tools/root from outside UniFi OS.

Note that changes to this directory only appear on the root filesystem after reboot.

Restoring the stock kernel

If you are running a custom kernel and wish to return the stock kernel, simply reboot the device (from UbiOS):

reboot

Removing udm-kernel-tools

To remove udm-kernel-tools and the custom kernels you have installed, run the following command in UniFi OS:

apt remove 'udm-kernel*'

This will remove the artifacts on your device related to this project.

Compatibility

Since the project requires firmware-specific binaries (e.g., kernel modules), you possibly need to upgrade the tools after you have upgraded to a new firmware version. Currently, the releases of this project support the following firmware versions:

  • 1.8.6
  • 1.9.3
  • 1.10.0
  • 1.10.4
  • 1.11.0
  • 1.11.4
  • 1.12.22
  • 1.12.30
  • 1.12.33

To build the project for custom firmware versions, please refer to the Maintenance Guide.

Troubleshooting

Below is a non-exhaustive list of issues that might occur while using these tools. Please check these instructions before reporting an issue on issue tracker.

Device reboots into stock kernel
When your device still reports after the boot procedure that it is running the stock kernel, check the logs for errors:

# Check ramoops
cat /sys/fs/pstore/*
# Check kernel log
dmesg

Device appears to be stuck
When you cannot connect to your device a few minutes after performing the boot procedure, the device might be stuck. Power cycle the device to restore the stock kernel.

SSH session exits with error after boot command
After executing the boot command, your SSH connection might become unresponsive or even exit with an error message. This is expected behavior, and you should be able to log back in to your device after a minute.

Contributing

Questions, suggestions and contributions are welcome and appreciated! You can contribute in various meaningful ways:

  • Report a bug through Github issues.
  • Propose and document use-cases for using this project.
  • Contribute improvements to the documentation.
  • Provide feedback about how we can improve the project.
  • Help answer questions on our Discussions page.

Advanced users may also be interested in the Maintenance Guide.

How it works

Bootstrapping a custom Linux kernel on the UDM/P is not trivial. By default, UniFi OS restricts user capabilities on Linux significantly, to such an extent that even changes to the root filesystem are not persistent without a workaround.

Although udm-unlock can be used to overwrite the kernel boot image or root filesystem, such an approach is fragile and might lead to a bricked device.

To prevent touching the UDM/P firmware for booting a custom Linu kernel, we can employ Linux' kexec functionality, which enables Linux to act as a second stage bootloader for a custom kernel.

Since kexec is not supported natively by the stock kernel running on the UDM/P, I have backported this functionality as a loadable kernel module. These tools use the kexec backport to load a custom kernel into memory and boot directly into the custom kernel. With this, we do not need to modify the device firmware and in case of issues, we can simply power-cycle the device.

While we can now boot into a custom Linux kernel, we will find that UbiOS requires several proprietary kernel modules to properly function. To address this issue, during the initramfs phase, we prepare a workaround that force-inserts the proprietary modules into the kernel, even when the versions do not match (see here for the implementation).

License

The code is released under the GPLv2 license. See COPYING.txt.

More Repositories

1

pam_reattach

Reattach to the user's GUI session on macOS during authentication (for Touch ID support in tmux)
C
683
star
2

brainfuck

Brainfuck interpreter written in C
C
535
star
3

udm-iptv

Helper tool for configuring routed IPTV on the UniFi Dream Machine (Pro)
Shell
423
star
4

pve-edge-kernel

Newer Linux kernels for Proxmox VE 7
Shell
370
star
5

udm-kernel

Custom Linux kernels for the UniFi Dream Machine
C
128
star
6

boot2flappy

Flappy Bird as bootable UEFI executable
Assembly
62
star
7

kotlin-plugin-generated

A Kotlin compiler plugin that annotates Kotlin-generated methods for improved coverage reports
Kotlin
35
star
8

brainfuck-java

Interpreter for the original Brainfuck language and its derivatives written in Java.
Java
31
star
9

booklab

Visually recognize the books on your shelf!
Kotlin
23
star
10

udm-unlock

Unlock write-protected disks on the UniFi Dream Machine Pro
C
20
star
11

kexec-mod

Kexec as loadable kernel module for Linux ARM64 kernels
C
16
star
12

jsamp

Library for the Grand Theft Auto San Andreas Multiplayer query mechanism written in Java.
Java
6
star
13

broccoli

A modern vision on the 90's game Log!cal
Java
5
star
14

formula-andy

Formula One Manager written in Java
Java
5
star
15

ktor-oauth2

OAuth2 authorization framework for Ktor
Kotlin
5
star
16

traceur

Raytracing engine written in C++
C++
5
star
17

shadevolution

Genetic Programming for Shader Simplification
Python
4
star
18

hugetable

Re-implementation of Google BigTable in Scala
Scala
4
star
19

logging.js

Lightweight logging library for Node.js based on the java.util.logging library.
JavaScript
4
star
20

nitrogen

Lightweight web framework written in PHP
PHP
4
star
21

sas

Simple streaming audio server in C
C
4
star
22

kaffee

Kaffee is a software project management tool similar to Maven and is written in Coffeescript.
CoffeeScript
4
star
23

edx

Solutions for online courses
F#
4
star
24

slf4n

Simple logging facade for NodeJS allowing the end user to choose the desired logging framework at deployment time.
JavaScript
3
star
25

iconsync

A tool to sync your icon theme on macOS
Swift
3
star
26

udm-shims

Shims for the proprietary kernel modules on the UniFi Dream Machine (Pro)
C
3
star
27

homebrew-personal

Personal Homebrew recipes that are not (yet) available in the official Homebrew repositories
Ruby
3
star
28

trufflephp

GraalVM implementation of the PHP language (WIP)
Kotlin
2
star
29

olympiad

Solutions for the problems of the Dutch Olympiad of Informatics.
Python
2
star
30

vdom.js

Rebuilding React from scratch
JavaScript
2
star
31

kmbridge

In-kernel IGMP Proxy for Linux (WIP)
C
1
star
32

glimpse

Small OpenGL wrapper for modern C++
C++
1
star
33

fastauction

Auctions with Budget Constraints
Kotlin
1
star