Ubuntu18.04的init程序合并到了systemd中,本篇文章记录一下systemd的下载和编译。
1. 下载systemd源码
(1) 查看systemd版本号,用来确定需要下载的分支
shell
sun@sun-pc:~$ systemd --version
systemd 237
+PAM +AUDIT +SELINUX +IMA +APPARMOR +SMACK +SYSVINIT +UTMP +LIBCRYPTSETUP +GCRYPT +GNUTLS +ACL +XZ +LZ4 +SECCOMP +BLKID +ELFUTILS +KMOD -IDN2 +IDN -PCRE2 default-hierarchy=hybrid
(2) 上面看到systemd的版本是237,对应git仓库的v237 tag
shell
sun@sun-pc:~/3rdcode$ git clone https://github.com/systemd/systemd.git --branch=v237
下载完成后,systemd目录内容如下:
shell
sun@sun-pc:~/3rdcode/systemd$ ls
catalog configure ENVIRONMENT.md hwdb Makefile meson_options.txt modprobe.d po README.md shell-completion sysusers.d TODO travis-ci xorg
coccinelle DISTRO_PORTING factory LICENSE.GPL2 man mkosi.build network presets rules src test tools UIDS-GIDS.md
CODING_STYLE docs HACKING LICENSE.LGPL2.1 meson.build mkosi.default NEWS README scripts sysctl.d tmpfiles.d TRANSIENT-SETTINGS.md units
2. 配置编译环境
systemd代码下载完成后,进入systemd目录,执行下面命令
shell
sun@sun-pc:~/3rdcode/systemd$ ./configure
+ exec meson build
The Meson build system
Version: 0.45.1
Source dir: /home/sun/3rdcode/systemd
Build dir: /home/sun/3rdcode/systemd/build
Build type: native build
...
配置完后,可以看到systemd目录多了一个build目录
shell
sun@sun-pc:~/3rdcode/systemd$ ls
build CODING_STYLE docs HACKING LICENSE.LGPL2.1 meson.build mkosi.default NEWS README scripts sysctl.d tmpfiles.d TRANSIENT-SETTINGS.md units
catalog configure ENVIRONMENT.md hwdb Makefile meson_options.txt modprobe.d po README.md shell-completion sysusers.d TODO travis-ci xorg
coccinelle DISTRO_PORTING factory LICENSE.GPL2 man mkosi.build network presets rules src test tools UIDS-GIDS.md
3. 编译systemd源码
shell
sun@sun-pc:~/3rdcode/systemd$ make