OpenWrt Forum Archive

Topic: systemd on OpenWrt

The content of this topic has been archived on 14 Apr 2016. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

So, the OpenWrt build system is amazing and awesome and incredible. Systemd on an embedded machine has interested me for quite some time, and to date I've been using OpenEmbedded / Yocto. However that ecosystem makes me want to stab my eyes out with rusty fish hooks... so I came back to OpenWrt's buildroot and attempted to add systemd.

This became a much simpler task with recent versions of systemd since they dropped the cyclic dependency on libdbus.

What works:
* Booting (yay!)
* Default targets
* The journal
* systemctl
* Probably a bunch of other stuff

What does not work:
* Module loading (need depmod and libkmod)
* Overlayfs, firstboot magic, preinit magic, most of the OpenWrt special sauce related to system boot.
* Hotplug scripts (working on a udev rule for this...)
* Probably a bunch of other stuff

I have tested most of the systemd modules (hostnamed, timedated, machined, networkd) but not all. Some are most likely missing dependencies.

Extra (you need to add/select these yourself) Dependencies:
* Kernel config: CONFIG_DEVTMPFS CONFIG_DEVTMPFS_MOUNT CONFIG_FHANDLE. I submitted a patch to OpenWrt which adds these symbols to config/Config-kernel.in so the systemd package can automagically select them. CONFIG_CGROUPS, another dependency, works like this so it's taken care of already.
* agetty (util-linux), glib2 (for gudev). Just install the packages/ feed and the systemd package will pull these in.
* eglibc - I have patches included for uClibc support but I have not tested it. If you're interested in checking it out, please do.

I would very much like to make gudev/glib2 selectable. GUdev is the most pointless library in the world since libudev is so easy to use already. This is a WIP.

Conflicts:
* procd as init (for obvious reasons)
* base-files (use base-files-systemd)


How to get it:
Add this to your feeds.conf

 src-git systemd git://github.com/aport/openwrt-systemd.git 

Then:

 ./scripts/feeds update systemd
./scripts/feeds install systemd
./scripts/feeds install base-files-systemd 

The package is under Base system. Select base-files-systemd and it will select systemd. I high recommend also selecting systemd-udev.

Comments? Suggestions? Hate mail? Please let me know!

Have fun!

(Last edited by aport on 18 Mar 2014, 20:56)

Hello there!

I too would like to get my hands dirty and try to see if i can port systemd to a "fork seeking mainline" to try and test out the benefits. Did you managed to iron out the details or are there problems still? I'm interested in porting systemd to Openwrt as well!

Thank You,
lifehacksback

it need libkmod to compile, how to enable it then?

lifehacksback wrote:

Hello there!

I too would like to get my hands dirty and try to see if i can port systemd to a "fork seeking mainline" to try and test out the benefits. Did you managed to iron out the details or are there problems still? I'm interested in porting systemd to Openwrt as well!

Thank You,
lifehacksback

Hey,

Sorry about the delay; I haven't kept up with this at all. I didn't generate any feedback or interest so I kind of forgot about it.

Maybe this weekend I'll fire it up and see if I can get it running on the latest trunk.

maplewang wrote:

it need libkmod to compile, how to enable it then?

I don't think a package exists yet.

aport wrote:

Hey,

Sorry about the delay; I haven't kept up with this at all. I didn't generate any feedback or interest so I kind of forgot about it.

Maybe this weekend I'll fire it up and see if I can get it running on the latest trunk.

Many Thanks! I look forward seeing your progress. I'm willing to test and build images if you need me to big_smile

I got a build to compile! However when i loaded it on my router it gave me an error while loading /dev hmm I'm running a new build and i left out systemd-udevd and see if something changed. Also how do I add this CONFIG_DEVTMPFS CONFIG_DEVTMPFS_MOUNT CONFIG_FHANDLE?

update:
I'm really dumb I just had to manually add these to the .config. tongue

------------------------------------------------------------------------\

Compiled but it did does not mount /dev

(Last edited by lifehacksback on 20 Jan 2015, 17:52)

same problem here. after adding systemd feeds, disabling base-system (incl. procd) and enabling base-system-systemd i'm getting

Failed to mount /dev: No such device
Failed to mount /dev/shm: No such file or directory
Failed to mount /dev: No such device

on first boot of device. any hints? smile

aschuetze wrote:

same problem here. after adding systemd feeds, disabling base-system (incl. procd) and enabling base-system-systemd i'm getting

Failed to mount /dev: No such device
Failed to mount /dev/shm: No such file or directory
Failed to mount /dev: No such device

on first boot of device. any hints? smile

I got it to work up to the service Journald and agetty hmm unfortunately until we find a way to fix this then we wont be able to access the console. If you would like to make systemd a reality under openwrt we should fork this work and continue the improvements! anyways for the answer to this problem --> I thought the CONFIG_* I placed under the .config was wrong, i was right. Type in openwrt root this $ make kernel_menuconfig. Then navigate to general options and enable fhandler. back up then go to drivers then general drivers and enable tmpfs and devtmpfs. That's it! then system will load in an average of 7 something seconds!!! However like I stated before the machine_id is not generating an output which inhibits journald functions. Furthermore agetty service fails which prevents the "enter to activate the console". So we have a "functional" boot with no way of debugging. If you could help us improve this error it would be a great help! I will add my router is fairly beefy (Linksys Openwrt wrt1900ac)


EDIT:

you may need to enable systemd-udevd under systemd (which is inside the Base Configuration NOT UNDER BASE-SYSTEM-SYSTEMD)

(Last edited by lifehacksback on 26 Jan 2015, 00:54)

I wonder how long it will take if everything is actually working smile

Tried updating to systemd 218 I get missing dependencies on glib2

libtool: link: arm-openwrt-linux-gnueabi-gcc -Wall -Wstrict-prototypes -Werror=declaration-after-statement -Werror=missing-prototypes -Werror=implicit-function-declaration -Werror=pointer-arith -Werror=init-self -Werror=format=2 -Werror=missing-include-dirs -Os -pipe -march=armv7-a -mtune=cortex-a9 -mfpu=vfpv3-d16 -fno-caller-saves -fhonour-copts -Wno-error=unused-but-set-variable -mfloat-abi=soft -I/home/thagabe/openwrt/staging_dir/target-arm_cortex-a9+vfpv3_eglibc-2.19_eabi/usr/lib/libiconv-stub/include -I/home/thagabe/openwrt/staging_dir/target-arm_cortex-a9+vfpv3_eglibc-2.19_eabi/usr/lib/libintl-stub/include -o .libs/glib-compile-resources gvdb-builder.o glib-compile-resources.o  -L/home/thagabe/openwrt/staging_dir/target-arm_cortex-a9+vfpv3_eglibc-2.19_eabi/usr/lib -L/home/thagabe/openwrt/staging_dir/target-arm_cortex-a9+vfpv3_eglibc-2.19_eabi/lib -L/home/thagabe/openwrt/staging_dir/toolchain-arm_cortex-a9+vfpv3_gcc-4.8-linaro_eglibc-2.19_eabi/usr/lib -L/home/thagabe/openwrt/staging_dir/toolchain-arm_cortex-a9+vfpv3_gcc-4.8-linaro_eglibc-2.19_eabi/lib -L/home/thagabe/openwrt/staging_dir/target-arm_cortex-a9+vfpv3_eglibc-2.19_eabi/usr/lib/libiconv-stub/lib -L/home/thagabe/openwrt/staging_dir/target-arm_cortex-a9+vfpv3_eglibc-2.19_eabi/usr/lib/libintl-stub/lib ./.libs/libgio-2.0.so ../gobject/.libs/libgobject-2.0.so ../glib/.libs/libglib-2.0.so
/home/thagabe/openwrt/staging_dir/toolchain-arm_cortex-a9+vfpv3_gcc-4.8-linaro_eglibc-2.19_eabi/lib/gcc/arm-openwrt-linux-gnueabi/4.8.3/../../../../arm-openwrt-linux-gnueabi/bin/ld: warning: libgmodule-2.0.so.0, needed by ./.libs/libgio-2.0.so, not found (try using -rpath or -rpath-link)
./.libs/libgio-2.0.so: undefined reference to `g_module_error'
./.libs/libgio-2.0.so: undefined reference to `g_module_close'
./.libs/libgio-2.0.so: undefined reference to `g_module_open'
./.libs/libgio-2.0.so: undefined reference to `g_module_supported'
./.libs/libgio-2.0.so: undefined reference to `g_module_symbol'
collect2: error: ld returned 1 exit status
Makefile:2029: recipe for target 'glib-compile-resources' failed
make[8]: *** [glib-compile-resources] Error 1
make[8]: Leaving directory '/home/thagabe/openwrt/build_dir/target-arm_cortex-a9+vfpv3_eglibc-2.19_eabi/glib-2.43.3/gio'
Makefile:3943: recipe for target 'all-recursive' failed
make[7]: *** [all-recursive] Error 1
make[7]: Leaving directory '/home/thagabe/openwrt/build_dir/target-arm_cortex-a9+vfpv3_eglibc-2.19_eabi/glib-2.43.3/gio'
Makefile:1765: recipe for target 'all' failed
make[6]: *** [all] Error 2
make[6]: Leaving directory '/home/thagabe/openwrt/build_dir/target-arm_cortex-a9+vfpv3_eglibc-2.19_eabi/glib-2.43.3/gio'
Makefile:1205: recipe for target 'all-recursive' failed
make[5]: *** [all-recursive] Error 1
make[5]: Leaving directory '/home/thagabe/openwrt/build_dir/target-arm_cortex-a9+vfpv3_eglibc-2.19_eabi/glib-2.43.3'
Makefile:846: recipe for target 'all' failed
make[4]: *** [all] Error 2
make[4]: Leaving directory '/home/thagabe/openwrt/build_dir/target-arm_cortex-a9+vfpv3_eglibc-2.19_eabi/glib-2.43.3'
Makefile:102: recipe for target '/home/thagabe/openwrt/build_dir/target-arm_cortex-a9+vfpv3_eglibc-2.19_eabi/glib-2.43.3/.built' failed
make[3]: *** [/home/thagabe/openwrt/build_dir/target-arm_cortex-a9+vfpv3_eglibc-2.19_eabi/glib-2.43.3/.built] Error 2
make[3]: Leaving directory '/home/thagabe/openwrt/feeds/packages/libs/glib2'
package/Makefile:174: recipe for target 'package/feeds/packages/glib2/compile' failed
make[2]: *** [package/feeds/packages/glib2/compile] Error 2
make[2]: Leaving directory '/home/thagabe/openwrt'
package/Makefile:171: recipe for target '/home/thagabe/openwrt/staging_dir/target-arm_cortex-a9+vfpv3_eglibc-2.19_eabi/stamp/.package_compile' failed
make[1]: *** [/home/thagabe/openwrt/staging_dir/target-arm_cortex-a9+vfpv3_eglibc-2.19_eabi/stamp/.package_compile] Error 2
make[1]: Leaving directory '/home/thagabe/openwrt'
/home/thagabe/openwrt/include/toplevel.mk:173: recipe for target 'world' failed
make: *** [world] Error 2

I have the same issue as lifehacksback
I changed trunk/feeds/packages/lib/glib2/Makefile
line 11 from 'PKG_VERSION:=2.43.3' to 'PKG_VERSION:=2.43.2' and removed checksum(line 17). After this changes sources became  compilable.

@lcfvrn

Thanks! It seemed like it was going to finish compiling, however I got some error because I tried updating systemd to 218. Well i went through the files and updated all 211 to 218.
Also do you get agetty to work?

Got agetty to compile with systemd. Seems like systemd puts deamons in the /sbin/ folder. However most openwrt utilities (util-linux) installs them to /usr/sbin. Manually setting agetty to /sbin yields a working console base for systemd on openwrt. Now im stuck on the  "<hostmachine> login: " as systemdlogin does not compile correctly. There are 3 places where I could focus, 1) systemd-login to continue to a boot (btw 7 seconds!) 2) fix up agetty mainly error handlers, or 3) fix machine-id (it does not create a machine id at boot) which prevents journald from starting and thus journal is not useful.

@lifehacksback did you got any further progress since your last post ? any place where one could follow (perhaps help) your work ?
thnxs!

The discussion might have continued from here.