8.77. Udev from Systemd-256.5

The Udev package contains programs for dynamic creation of device nodes.

Approximate build time: 0.2 SBU
Required disk space: 144 MB

8.77.1. Installation of Udev

Udev is part of the systemd-256.5 package. Use the systemd-256.5.tar.xz file as the source tarball.

Remove two unneeded groups, render and sgx, from the default udev rules:

sed -i -e 's/GROUP="render"/GROUP="video"/' \
       -e 's/GROUP="sgx", //' rules.d/50-udev-default.rules.in

Remove one udev rule requiring a full Systemd installation:

sed '/systemd-sysctl/s/^/#/' -i rules.d/99-systemd.rules.in

Adjust the hardcoded paths to network configuration files for the standalone udev installation:

sed '/NETWORK_DIRS/s/systemd/udev/' -i src/basic/path-lookup.h

Prepare Udev for compilation:

mkdir -p build
cd       build

meson setup ..                  \
      --prefix=/usr             \
      --buildtype=release       \
      -D mode=release           \
      -D dev-kvm-mode=0660      \
      -D link-udev-shared=false \
      -D logind=false           \
      -D vconsole=false

The meaning of the meson options:

--buildtype=release

This switch overrides the default buildtype (debug), which produces unoptimized binaries.

-D mode=release

Disable some features considered experimental by upstream.

-D dev-kvm-mode=0660

The default udev rule would allow all users to access /dev/kvm. The editors consider it dangerous. This option overrides it.

-D link-udev-shared=false

This option prevents udev from linking to the internal systemd shared library, libsystemd-shared. This library is designed to be shared by many Systemd components and it's too overkill for a udev-only installation.

-D logind=false -D vconsole=false

These options prevent the generation of several udev rule files belonging to the other Systemd components that we won't install.

Get the list of the shipped udev helpers and save it into an environment variable (exporting it is not strictly necessary, but it makes building as a regular user or using a package manager easier):

export udev_helpers=$(grep "'name' :" ../src/udev/meson.build | \
                      awk '{print $3}' | tr -d ",'" | grep -v 'udevadm')

Only build the components needed for udev:

ninja udevadm systemd-hwdb                                           \
      $(ninja -n | grep -Eo '(src/(lib)?udev|rules.d|hwdb.d)/[^ ]*') \
      $(realpath libudev.so --relative-to .)                         \
      $udev_helpers

Install the package:

install -vm755 -d {/usr/lib,/etc}/udev/{hwdb.d,rules.d,network}
install -vm755 -d /usr/{lib,share}/pkgconfig
install -vm755 udevadm                             /usr/bin/
install -vm755 systemd-hwdb                        /usr/bin/udev-hwdb
ln      -svfn  ../bin/udevadm                      /usr/sbin/udevd
cp      -av    libudev.so{,*[0-9]}                 /usr/lib/
install -vm644 ../src/libudev/libudev.h            /usr/include/
install -vm644 src/libudev/*.pc                    /usr/lib/pkgconfig/
install -vm644 src/udev/*.pc                       /usr/share/pkgconfig/
install -vm644 ../src/udev/udev.conf               /etc/udev/
install -vm644 rules.d/* ../rules.d/README         /usr/lib/udev/rules.d/
install -vm644 $(find ../rules.d/*.rules \
                      -not -name '*power-switch*') /usr/lib/udev/rules.d/
install -vm644 hwdb.d/*  ../hwdb.d/{*.hwdb,README} /usr/lib/udev/hwdb.d/
install -vm755 $udev_helpers                       /usr/lib/udev
install -vm644 ../network/99-default.link          /usr/lib/udev/network

Install some custom rules and support files useful in an LFS environment:

tar -xvf ../../udev-lfs-20230818.tar.xz
make -f udev-lfs-20230818/Makefile.lfs install

Install the man pages:

tar -xf ../../systemd-man-pages-256.5.tar.xz                            \
    --no-same-owner --strip-components=1                              \
    -C /usr/share/man --wildcards '*/udev*' '*/libudev*'              \
                                  '*/systemd.link.5'                  \
                                  '*/systemd-'{hwdb,udevd.service}.8

sed 's|systemd/network|udev/network|'                                 \
    /usr/share/man/man5/systemd.link.5                                \
  > /usr/share/man/man5/udev.link.5

sed 's/systemd\(\\\?-\)/udev\1/' /usr/share/man/man8/systemd-hwdb.8   \
                               > /usr/share/man/man8/udev-hwdb.8

sed 's|lib.*udevd|sbin/udevd|'                                        \
    /usr/share/man/man8/systemd-udevd.service.8                       \
  > /usr/share/man/man8/udevd.8

rm /usr/share/man/man*/systemd*

Finally, unset the udev_helpers variable:

unset udev_helpers

8.77.2. Installation of Udev - 32bit

Clean previous build (while still in the build directory):

rm -rf *

Prepare Udev for compilation:

PKG_CONFIG_PATH="/usr/lib32/pkgconfig" \
CC="gcc -m32 -march=i686"              \
CXX="g++ -m32 -march=i686"             \
LANG=en_US.UTF-8                       \
meson setup \
      --prefix=/usr                 \
      --buildtype=release           \
      -Dmode=release                \
      -Ddev-kvm-mode=0660           \
      -Dlink-udev-shared=false      \
      -Dlogind=false                \
      -Dvconsole=false              \
      ..

Compile the package:

ninja \
      $(grep -o -E "^build (src/libudev|src/udev)[^:]*" \
        build.ninja | awk '{ print $2 }')                              \
      $(realpath libudev.so --relative-to .)

Install the package:

mkdir -pv /usr/lib32/pkgconfig &&
cp -av libudev.so{,*[0-9]} /usr/lib32/ &&
sed -e "s;/usr/lib;&32;g" src/libudev/libudev.pc > /usr/lib32/pkgconfig/libudev.pc

8.77.3. Installation of Udev - x32bit

Clean previous build (while still in the build directory):

rm -rf *

Prepare Udev for compilation:

PKG_CONFIG_PATH="/usr/libx32/pkgconfig" \
CC="gcc -mx32"                          \
CXX="g++ -mx32"                         \
CFLAGS+=" -Wno-error=shift-overflow"    \
CXXFLAGS+=" -Wno-error=shift-overflow"  \
LANG=en_US.UTF-8                        \
meson setup \
      --prefix=/usr                 \
      --buildtype=release           \
      -Dmode=release                \
      -Ddev-kvm-mode=0660           \
      -Dlink-udev-shared=false      \
      -Dlogind=false                \
      -Dvconsole=false              \
      ..

Compile the package:

ninja \
      $(grep -o -E "^build (src/libudev|src/udev)[^:]*" \
        build.ninja | awk '{ print $2 }')                              \
      $(realpath libudev.so --relative-to .)

Install the package:

mkdir -pv /usr/libx32/pkgconfig &&
cp -av libudev.so{,*[0-9]} /usr/libx32/ &&
sed -e "s;/usr/lib;&x32;g" src/libudev/libudev.pc > /usr/libx32/pkgconfig/libudev.pc

8.77.4. Configuring Udev

Information about hardware devices is maintained in the /etc/udev/hwdb.d and /usr/lib/udev/hwdb.d directories. Udev needs that information to be compiled into a binary database /etc/udev/hwdb.bin. Create the initial database:

udev-hwdb update

This command needs to be run each time the hardware information is updated.

8.77.5. Contents of Udev

Installed programs: udevadm, udevd (symlink to udevadm), and udev-hwdb
Installed libraries: libudev.so
Installed directories: /etc/udev and /usr/lib/udev

Short Descriptions

udevadm

Generic udev administration tool: controls the udevd daemon, provides info from the Udev database, monitors uevents, waits for uevents to finish, tests Udev configuration, and triggers uevents for a given device

udevd

A daemon that listens for uevents on the netlink socket, creates devices and runs the configured external programs in response to these uevents

udev-hwdb

Updates or queries the hardware database.

libudev

A library interface to udev device information

/etc/udev

Contains Udev configuration files, device permissions, and rules for device naming