8.89.1. Installation of Udev
Udev is part of the systemd-257.3 package. Use the
systemd-257.3.tar.xz file as the source tarball.
Create the PKGBUILD for the Udev package with the following
commands:
mkdir /sources/udev
cd /sources/udev
cat > PKGBUILD << "REALEOF"
# Maintainer: Linux From Scratch <lfs-dev@lists.linuxfromscratch.org>
pkgname="udev"
_pkgbase="systemd"
pkgver="257.3"
pkgrel="1"
pkgdesc="The Udev package contains programs for dynamic creation of device nodes."
arch=('x86'
'x86_64')
url="https://www.freedesktop.org/wiki/Software/systemd/"
license=('BSD2C'
'BSD3C'
'CCU-1'
'GLPv2'
'LGPLv2.1'
'MIT'
'PD'
'OFL')
install='udev.install'
groups=('core')
depends=('acl'
'glibc'
'libcap'
'openssl'
'util-linux')
makedepends=('bash'
'binutils'
'coreutils'
'diffutils'
'gawk'
'gcc'
'gperf'
'grep'
'jinja2'
'libxcrypt'
'meson'
'pkgconf'
'sed'
'zstd')
source=('https://github.com/systemd/systemd/archive/v257.3/systemd-257.3.tar.gz'
'https://anduin.linuxfromscratch.org/LFS/systemd-man-pages-257.3.tar.xz'
'https://anduin.linuxfromscratch.org/LFS/udev-lfs-20230818.tar.xz')
md5sums=('8e4fc90c7aead651fa5c50bd1b34abc2'
'9b77c3b066723d490cb10aed4fb05696'
'acd4360d8a5c3ef320b9db88d275dae6')
noextract=('systemd-man-pages-257.3.tar.xz'
'udev-lfs-20230818.tar.xz')
prepare(){
cd "${_pkgbase}-${pkgver}"
# Remove two unneeded groups, render and sgx, from the default udev rules
sed -e 's/GROUP="render"/GROUP="video"/' \
-e 's/GROUP="sgx", //' \
-i rules.d/50-udev-default.rules.in
# Remove one udev rule requiring a full Systemd installation
sed -i '/systemd-sysctl/s/^/#/' rules.d/99-systemd.rules.in
# Adjust the hardcoded paths to network configuration files for the
# standalone udev installation
sed -e '/NETWORK_DIRS/s/systemd/udev/' \
-i src/libsystemd/sd-network/network-util.h
# Build udev in its own directory
mkdir -p build
}
build(){
cd "${_pkgbase}-${pkgver}/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
# Get the list of the shipped udev helpers and save it into a variable
_udev_helpers=$(grep "'name' :" ../src/udev/meson.build | \
awk '{print $3}' | tr -d ",'" | grep -v 'udevadm')
# Build the package
ninja udevadm systemd-hwdb \
$(ninja -n | grep -Eo '(src/(lib)?udev|rules.d|hwdb.d)/[^ ]*') \
$(realpath libudev.so --relative-to .) \
${_udev_helpers}
}
package(){
cd "${_pkgbase}-${pkgver}/build"
# Get the list of the shipped udev helpers and save it into a variable
_udev_helpers=$(grep "'name' :" ../src/udev/meson.build | \
awk '{print $3}' | tr -d ",'" | grep -v 'udevadm')
# Install only what is needed from the systemd package for udev
install -vDm755 -d "${pkgdir}"{/usr/lib,/etc}/udev/{hwdb.d,rules.d,network}
install -vDm755 -d "${pkgdir}"/usr/{lib,share}/pkgconfig
install -vDm755 udevadm "${pkgdir}/usr/bin/"
install -vDm755 systemd-hwdb "${pkgdir}/usr/bin/udev-hwdb"
install -vdm755 "${pkgdir}"/usr/sbin
ln -svfn ../bin/udevadm "${pkgdir}/usr/sbin/udevd"
cp -av libudev.so{,*[0-9]} "${pkgdir}/usr/lib/"
install -vDm644 ../src/libudev/libudev.h "${pkgdir}/usr/include/"
install -vDm644 src/libudev/*.pc "${pkgdir}/usr/lib/pkgconfig/"
install -vDm644 src/udev/*.pc "${pkgdir}/usr/share/pkgconfig/"
install -vDm644 ../src/udev/udev.conf "${pkgdir}/etc/udev/"
install -vDm644 rules.d/* ../rules.d/README "${pkgdir}/usr/lib/udev/rules.d/"
install -vDm644 $(find ../rules.d/*.rules \
-not -name '*power-switch*') "${pkgdir}/usr/lib/udev/rules.d/"
install -vDm644 hwdb.d/* ../hwdb.d/{*.hwdb,README} "${pkgdir}/usr/lib/udev/hwdb.d/"
install -vDm755 ${_udev_helpers} "${pkgdir}/usr/lib/udev"
install -vDm644 ../network/99-default.link "${pkgdir}/usr/lib/udev/network"
# Install the LFS custom rules and support files
tar -xvf "${srcdir}/udev-lfs-20230818.tar.xz"
make -f udev-lfs-20230818/Makefile.lfs DESTDIR="${pkgdir}" install
# Install the man pages
tar -xf "${srcdir}/systemd-man-pages-257.3.tar.xz \
--no-same-owner --strip-components=1 \
-C "${pkgdir}/usr/share/man" --wildcards '*/udev*' '*/libudev*' \
'*/systemd.link.5' \
'*/systemd-'{hwdb,udevd.service}.8
sed 's|systemd/network|udev/network|' \
"${pkgdir}/usr/share/man/man5/systemd.link.5" \
> "${pkgdir}/usr/share/man/man5/udev.link.5"
sed 's/systemd\(\\\?-\)/udev\1/' \
"${pkgdir}/usr/share/man/man8/systemd-hwdb.8" \
> "${pkgdir}/usr/share/man/man8/udev-hwdb.8"
sed 's|lib.*udevd|sbin/udevd|' \
"${pkgdir}/usr/share/man/man8/systemd-udevd.service.8" \
> "${pkgdir}/usr/share/man/man8/udevd.8"
rm "${pkgdir}"/usr/share/man/man*/systemd*
}
REALEOF
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.
Create the udev.install file to run
the udev-hwdb update
on installation or upgrade:
cat > udev.install << "REALEOF"
# udev.install
post_install(){
/usr/bin/udev-hwdb update
}
post_upgrade(){
/usr/bin/udev-hwdb update
}
REALEOF
Prepare the build directory for the pacman user and build the
package:
chown -R root:pacman .
chmod 2775 .
chmod 664 PKGBUILD
su pacman -c 'makepkg -L --nodeps'
Add the newly created package to the central package repository:
cp udev-257.3-1-$(uname -m).pkg.tar.xz \
/srv/pacman/repos/LFS/
repo-add /srv/pacman/repos/LFS/LFS.db.tar.xz \
/srv/pacman/repos/LFS/udev-257.3-1-$(uname -m).pkg.tar.xz
Update the local cache and install the Udev package:
pacman -Syu
pacman -S udev --overwrite \* -dd --noconfirm
Finally, copy the source files into the source repository and clean
up the build directory:
mkdir /srv/pacman/source/LFS/udev
cp PKGBUILD /srv/pacman/source/LFS/udev
cd /sources
rm -rf udev
8.89.2. 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. The installation created the
initial database, but shoud it need to be updated for any other
change, use the followoing command:
udev-hwdb update
This command needs to be run each time the hardware information is
updated.