Skip to content

Commit 5e04193

Browse files
release
1 parent c652843 commit 5e04193

12 files changed

+146
-58
lines changed

README.md

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -60,23 +60,25 @@ systemctl reboot
6060

6161
what is the mkinitcpio hook entry provided by this package?
6262
* hook name: `systemd-tool`
63-
* minimum required hooks are: `base systemd systemd-tool`
64-
* recommended hooks are: `base systemd autodetect modconf block filesystems keyboard systemd-tool`
63+
* required hooks are: `base systemd systemd-tool`
64+
* recommended hooks are: `base autodetect modconf block filesystems keyboard fsck systemd systemd-tool`
6565

66-
how can I enable my custom service unit in initrd?
67-
* add `[Unit]` entry `ConditionPathExists=/etc/initrd-release`
66+
how can I include/exclude my custom service unit in initrd?
67+
* include: change `[Unit]` entry to `ConditionPathExists=/etc/initrd-release`
68+
* exclude: change `[Unit]` entry to `ConditionPathExists=/etc/xxx/initrd-release`
6869

69-
how can I disable my custom service unit in initrd?
70-
* alter the tag marker string, i.e.: `ConditionPathExists=/etc/xxx/initrd-release`
70+
how can I enable/disable/mask/unmask my custom service unit in initrd?
71+
* enable: change `[X-SystemdTool]` entry `InitrdService=enable`
7172

7273
how systemd unit transitive dependency provisioning works?
7374
* see `mkinitcpio-install.sh/add_systemd_unit_X()`
74-
* services and targets found in `[Unit]/Requires|OnFailure` are recursively installed
75+
* units found in `[Unit]/Requires|OnFailure` are recursively installed
7576

7677
what is the purpose of `[X-SystemdTool]` section in service unit files?
7778
* see https://github.com/systemd/systemd/issues/3340
7879
* this section provides configuration interface for `mkinitcpio` provisioning actions
79-
* entries include: `InitrdBinary=`, `InitrdPath=`, `InitrdLink=`, `InitrdBuild=`, `InitrdCall=`
80+
* entries: `InitrdBuild`, `InitrdCall`, `InitrdService`
81+
* entries: `InitrdBinary`, `InitrdPath`, `InitrdLink`
8082

8183
how can I auto-provision my custom service unit binaries into initramfs?
8284
* use `InitrdBinary=/path/target-exec` to provision service binary
@@ -98,9 +100,8 @@ how can I provision optional folder or file?
98100
* use `InitrdPath=/target-file source=/source-file optional=yes`
99101

100102
is there a way to create empty folder or file?
101-
* for empty dir, use `InitrdPath=/path/target-folder/ create=yes` note trailing SLASH
103+
* for empty dir, use `InitrdPath=/path/target-dir/ create=yes` note trailing SLASH
102104
* for empty file, use `InitrdPath=/path/target-file create=yes` note NO trailing slash
103-
* in order to ignore existing host source, add `source=/some-invalid-path` argument
104105

105106
how can I provision a symbolic link?
106107
* use `InitrdLink=/path-to-link/link-name /path-to-target/target-name`
@@ -144,8 +145,8 @@ is there a silent or no-echo mode during password entry in `initrd-shell.sh`?
144145
### Package Build Questions and Answers
145146

146147
how can I install latest release or development version of this?
147-
* create a marker file `.PKGDEV` to build from latest master branch,
148-
* create a marker file `.PKGREL` to build from latest release tag,
148+
* create a marker file `.PKGDEV` to build from latest branch=master ,
149+
* create a marker file `.PKGREL` to build from latest release tag=vNNN,
149150
* for example:
150151
```
151152
mkdir -p /tmp/aur

crypttab

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@
88
# how crypttab is used by systemd
99
# https://www.freedesktop.org/software/systemd/man/systemd-cryptsetup-generator.html
1010

11-
# to setup crypto disks in initramfs over ssh
12-
# manually provide here partition UUID with help of `lsblk`
13-
# then active initrd-cryptsetup.service
11+
# provide here mapper partition UUID (instead of kernel command line)
1412

1513
# <name> <device> <password> <options>
16-
swap UUID=${UUID_SWAP} none luks
17-
root UUID=${UUID_ROOT} none luks
14+
swap UUID=${UUID_SWAP} none luks
15+
root UUID=${UUID_ROOT} none luks

fstab

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# This file is part of https://github.com/random-archer/mkinitcpio-systemd-tool
2+
3+
# TODO
4+
# currently systemd requires use of "root=" kenel argument for /sysroot mount
5+
# https://github.com/systemd/systemd/blob/master/src/fstab-generator/fstab-generator.c
6+
7+
# fstab: mappings for direct partitions
8+
9+
# fstab format:
10+
# https://wiki.archlinux.org/index.php/Fstab
11+
12+
# how fstab is used by systemd
13+
# https://www.freedesktop.org/software/systemd/man/systemd-fstab-generator.html
14+
15+
# provide here root partition description (instead of kernel command line)
16+
17+
# <file system> <dir> <type> <option <dump> <pass>
18+
# /dev/mapper/swap none swap defaults 0 0
19+
# /dev/mapper/root /sysroot ext4 defaults,ro 0 1

initrd-cryptsetup.service

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
[Unit]
1010
Description=Initrd Cryptsetup Service
1111
Documentation=https://github.com/random-archer/mkinitcpio-systemd-tool/blob/master/README.md
12+
ConditionPathExists=/etc/crypttab
13+
ConditionPathExists=/etc/fstab
1214
ConditionPathExists=/etc/initrd-release
1315
DefaultDependencies=no
1416
After=initrd-shell.service
@@ -31,8 +33,12 @@ WantedBy=sysinit.target
3133

3234
[X-SystemdTool]
3335

34-
# provision crypttab in initramfs
35-
InitrdPath=/etc/crypttab source=/etc/mkinitcpio.d/crypttab optional=yes
36+
# enable service
37+
InitrdService=enable
38+
39+
# provision disk tables in initramfs
40+
InitrdPath=/etc/crypttab source=/etc/mkinitcpio.d/crypttab replace=yes
41+
InitrdPath=/etc/fstab source=/etc/mkinitcpio.d/fstab replace=yes
3642

3743
# include cryptsetup binaries
3844
InitrdBinary=/usr/bin/dmsetup
@@ -50,6 +56,7 @@ InitrdPath=/usr/lib/systemd/system/cryptsetup.target
5056
InitrdPath=/usr/lib/systemd/system/cryptsetup-pre.target
5157
InitrdBinary=/usr/lib/systemd/systemd-cryptsetup
5258
InitrdBinary=/usr/lib/systemd/system-generators/systemd-cryptsetup-generator
59+
InitrdBinary=/usr/lib/systemd/system-generators/systemd-fstab-generator
5360

5461
# include systemd password agent support
5562
InitrdBinary=/usr/bin/systemd-ask-password

initrd-debug-progs.service

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,16 @@ WantedBy=initrd-debug-shell.service
2020

2121
[X-SystemdTool]
2222

23+
# enable service
24+
InitrdService=enable
25+
2326
# debug tools
2427
InitrdBinary=/usr/bin/strace optional=yes
2528

2629
# systemd tools
27-
InitrdBinary=/usr/bin/systemd-analyze
2830
InitrdBinary=/usr/bin/journalctl
29-
# proper pager for journalctl
3031
InitrdBinary=/usr/bin/less replace=yes
32+
#InitrdBinary=/usr/bin/systemd-analyze
3133

3234
# midnight commander
3335
InitrdBinary=/usr/bin/mc

initrd-debug-shell.service

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@ Documentation=https://github.com/random-archer/mkinitcpio-systemd-tool/blob/mast
88
ConditionPathExists=/etc/initrd-release
99
ConditionPathExists=/dev/tty8
1010
DefaultDependencies=no
11+
IgnoreOnIsolate=yes
1112

1213
[Service]
1314
Environment=TERM=linux
1415
ExecStart=/bin/sh
1516
Restart=always
16-
RestartSec=1s
17+
RestartSec=3s
1718
StandardInput=tty
1819
TTYPath=/dev/tty8
1920
TTYReset=yes
@@ -24,3 +25,8 @@ IgnoreSIGPIPE=no
2425

2526
[Install]
2627
WantedBy=sysinit.target
28+
29+
[X-SystemdTool]
30+
31+
# enable service
32+
InitrdService=enable

initrd-dropbear.service

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,26 @@ ExecReload=/bin/kill -HUP ${MAINPID}
2727
# dropbear reports 1 when exiting on SIGTERM
2828
SuccessExitStatus= 0 1
2929
Restart=always
30-
RestartSec=1s
30+
RestartSec=3s
3131

3232
[Install]
3333
WantedBy=sysinit.target
3434

3535
[X-SystemdTool]
3636

37+
# enable service
38+
InitrdService=enable
39+
3740
# ensure dropbear server host keys
3841
InitrdBuild=/etc/systemd/system/initrd-build.sh command=do_ssh_host_keys
3942

4043
# include generated dropbear configuration
4144
InitrdPath=/etc/dropbear
4245

4346
# provide expected dropbear layout
44-
InitrdPath=/var/run/ create=yes source=/invalid-source
45-
InitrdPath=/var/run/utmp create=yes source=/invalid-source
46-
InitrdPath=/var/log/ create=yes source=/invalid-source
47-
InitrdPath=/var/log/btmp create=yes source=/invalid-source
48-
InitrdPath=/var/log/wtmp create=yes source=/invalid-source
49-
InitrdPath=/var/log/lastlog create=yes source=/invalid-source
47+
InitrdPath=/var/run/ create=yes
48+
InitrdPath=/var/run/utmp create=yes
49+
InitrdPath=/var/log/ create=yes
50+
InitrdPath=/var/log/btmp create=yes
51+
InitrdPath=/var/log/wtmp create=yes
52+
InitrdPath=/var/log/lastlog create=yes

initrd-emergency.service

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
[Unit]
1111
Description=Initrd Emergency Service
1212
Documentation=https://github.com/random-archer/mkinitcpio-systemd-tool/blob/master/README.md
13-
ConditionPathExists=/etc/initrd-release
13+
ConditionPathExists=/etc/xxx/initrd-release
1414
DefaultDependencies=no
1515
Conflicts=shutdown.target
1616
Conflicts=rescue.service
@@ -20,13 +20,19 @@ Wants=initrd-debug-shell.service
2020
[Service]
2121
ExecStartPre=/bin/echo "Initrd Emergency Service"
2222
ExecStartPre=/bin/sh -c 'for step in 1 2 3; do echo -n "$step "; sleep 1; done; echo ".";'
23-
ExecStart=/usr/bin/systemctl --job-mode=fail --no-block default
23+
ExecStartPre=/usr/bin/systemctl daemon-reload
24+
ExecStartPre=/usr/bin/systemctl --job-mode=fail --no-block default
25+
ExecStart=/bin/true
2426
Type=idle
2527
StandardInput=null
26-
StandardOutput=tty
27-
StandardError=tty
28+
StandardOutput=journal+console
29+
StandardError=journal+console
30+
TTYPath=/dev/console
2831

2932
[X-SystemdTool]
3033

34+
# disable service
35+
InitrdService=disable
36+
3137
# override /usr/lib/systemd/system/emergency.service
32-
InitrdPath=/etc/systemd/system/emergency.service source=/etc/systemd/system/initrd-emergency.service
38+
#InitrdPath=/etc/systemd/system/emergency.service source=/etc/systemd/system/initrd-emergency.service

initrd-network.service

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ WantedBy=sysinit.target
2727

2828
[X-SystemdTool]
2929

30+
# enable service
31+
InitrdService=enable
32+
3033
# TODO use predictable network interface names
3134
#InitrdPath=/usr/lib/udev/rules.d/80-net-setup-link.rules
3235

initrd-shell.service

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ WantedBy=sysinit.target
1919

2020
[X-SystemdTool]
2121

22+
# enable service
23+
InitrdService=enable
24+
2225
# provision initrd shell
2326
InitrdPath=/etc/systemd/system/initrd-shell.sh mode=700
2427
InitrdBinary=/usr/bin/sulogin
@@ -38,3 +41,8 @@ InitrdBuild=/etc/systemd/system/initrd-build.sh command=do_secret_clean
3841

3942
# include ssh credentials
4043
InitrdPath=/root/.ssh/authorized_keys source=/root/.ssh/authorized_keys mode=600
44+
45+
# override system actions
46+
InitrdLink=/usr/bin/halt /usr/bin/systemctl
47+
InitrdLink=/usr/bin/reboot /usr/bin/systemctl
48+
InitrdLink=/usr/bin/shutdown /usr/bin/systemctl

0 commit comments

Comments
 (0)