Upgrading systemd on Amazon Linux 2
While this will not be everyone’s cup of tea and the majority should have no need for this tutorial, what is the Internet if not a collection of “useful” bits of information for those one-off moments that we all occasionally run into.
I recently ran into a situation, unrelated to this tutorial, where I was using Amazon Linux 2 and I needed to upgrade the version of systemd
to the latest, or something close to it at least. In this case, the yum
command is not helpful and the task needs to performed manually.
Getting started
The first step is to get the lay of the land and determine what your starting point is. In this example, I’m using a default installation of Amazon Linux 2 on AWS. All of the versions indicated here are at the time of writing and may not correspond to what you find in the wild.
An important thing to note is that systemd
is not in the standard path and cannot simply be downloaded as a binary and dropped into place.
$ which systemd
/usr/bin/which: no systemd in (/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/ec2-user/.local/bin:/home/ec2-user/bin)
There is an easy way to confirm the location, and version, of your systemd
installation.
$ ps 1
PID TTY STAT TIME COMMAND
1 ? Ss 0:02 /usr/lib/systemd/systemd --switched-root --system --deserialize 21
$ sudo /usr/lib/systemd/systemd --version
systemd 219
+PAM +AUDIT +SELINUX +IMA -APPARMOR +SMACK +SYSVINIT +UTMP +LIBCRYPTSETUP +GCRYPT +GNUTLS +ACL +XZ +LZ4 -SECCOMP +BLKID +ELFUTILS +KMOD +IDN
The first command identifies the command, and its path, /usr/lib/systemd/systemd
, and the second checks the version using sudo
which in this case us 219.
Prepare the environment
The next step is to prepare the local server to be able to compile systemd
from source.
$ sudo yum groupinstall "Development Tools"
$ sudo yum install libcap-devel gperf glib2-devel libmount-devel
$ pip3 install --user meson
$ sudo pip3 install ninja
$ sudo pip3 install jinja2
Using sudo
for pip3
will generate a warning that it is not recommended usage but it works for the purposes of this tutorial. Secure management of pip3
packages is beyond the scope of this walkthrough.
Download the source code
Based on the current version, the command to download:
$ wget https://github.com/systemd/systemd/archive/refs/tags/v252.tar.gz
$ tar -xf v252.tar.gz
$ cd systemd-252
Build process
This next section is straightforward and nearly the final step of the process.
$ ./configure
$ make
$ sudo /usr/local/bin/ninja -C build install
Confirm success!
The final step is to confirm that everything works as expected:
$ sudo reboot
$ ps 1
PID TTY STAT TIME COMMAND
1 ? Ss 0:02 /usr/lib/systemd/systemd --switched-root --system --deserialize 21
$ /usr/lib/systemd/systemd --version
systemd 252 (252)
-PAM -AUDIT -SELINUX -APPARMOR +IMA +SMACK -SECCOMP -GCRYPT -GNUTLS -OPENSSL -ACL +BLKID -CURL -ELFUTILS -FIDO2 -IDN2 -IDN -IPTC -KMOD -LIBCRYPTSETUP -LIBFDISK -PCRE2 -PWQUALITY -P11KIT -QRENCODE -TPM2 -BZIP2 -LZ4 -XZ +ZLIB -ZSTD -BPF_FRAMEWORK -XKBCOMMON +UTMP +SYSVINIT default-hierarchy=unified
As you can see, we now have version 252
installed on our system instead of the original default version.
Conclusion
This is not something we may need to do on a regular basis, it’s still important to have this list of commands available to us, just in case. The process is straightforward with only a few prerequisite commands and successful confirmation is simple.