Skip to content

Commit 6323791

Browse files
Merge pull request #63 from random-archer/dev-refactor-install
refactor install
2 parents b072dc3 + 9b5a085 commit 6323791

File tree

13 files changed

+216
-141
lines changed

13 files changed

+216
-141
lines changed

README.md

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
[![Master Status](https://dev.azure.com/random-archer/mkinitcpio-systemd-tool/_apis/build/status/random-archer.mkinitcpio-systemd-tool?branchName=master)](https://dev.azure.com/random-archer/mkinitcpio-systemd-tool/_build/latest?definitionId=1&branchName=master)
66

7-
### Summary
7+
### Summary
88

99
<details>
1010
<summary>
@@ -19,14 +19,14 @@ Provisioning tool for systemd in initramfs (systemd-tool):
1919
Core features provided by the hook:
2020
* unified systemd + mkinitcpio configuration
2121
* automatic provisioning of binary and config resources
22-
* on-demand invocation of mkinitcpio scripts and in-line functions
22+
* on-demand invocation of mkinitcpio scripts and in-line functions
2323

2424
Features provided by the included service units:
2525
* initrd debugging
2626
* early network setup
2727
* interactive user shell
2828
* remote ssh access in initrd
29-
* cryptsetup + custom password agent
29+
* cryptsetup + custom password agent
3030

3131
</details>
3232

@@ -72,7 +72,7 @@ systemctl reboot
7272
### Install Details
7373

7474
`pacman` install actions:
75-
* take a look in [arch repo](https://git.archlinux.org/svntogit/community.git/tree/trunk/PKGBUILD?h=packages/mkinitcpio-systemd-tool)
75+
* take a look in [arch repo](https://git.archlinux.org/svntogit/community.git/tree/trunk/PKGBUILD?h=packages/mkinitcpio-systemd-tool)
7676
and [make file](https://github.com/random-archer/mkinitcpio-systemd-tool/blob/master/Makefile)
7777
* provision user config and vendor systemd units into:
7878
* `/etc/mkinitcpio-systemd-tool` (with backup)
@@ -82,7 +82,7 @@ systemctl reboot
8282
* look for enabled units in the `/etc/systemd/system`
8383
* include in initrd units containing marker `/etc/initrd-release`
8484
* activate transitively in initrd any discovered systemd service units
85-
* auto provision into initramfs resources declared inside initrd service units
85+
* auto provision into initramfs resources declared inside initrd service units
8686

8787
### Provisioning Questions and Answers
8888

@@ -98,17 +98,17 @@ how can I customize installed service units?
9898

9999
how can I review generated `/boot/initramfs-linux.img`?
100100
* to review `initramfs.img` after `mkinitcpio` but before `reboot`, use:
101-
* visually, with [midnight commander](https://www.archlinux.org/packages/community/x86_64/mc/)
102-
or scripted, with [mkinitcpio lsinitcpio](https://wiki.archlinux.org/index.php/Mkinitcpio#Extracting_the_image)
101+
* visually, with [midnight commander](https://www.archlinux.org/packages/community/x86_64/mc/)
102+
or scripted, with [mkinitcpio lsinitcpio](https://wiki.archlinux.org/index.php/Mkinitcpio#Extracting_the_image)
103103

104104
how systemd unit transitive dependency provisioning works?
105105
* see `mkinitcpio-install.sh/add_systemd_unit_X()`
106-
* units found in `[Unit]/Requires|OnFailure` are recursively installed
106+
* units found in `[Unit]/Requires|OnFailure` are recursively installed
107107

108108
what is the purpose of `[X-SystemdTool]` section in service unit files?
109109
* see https://github.com/systemd/systemd/issues/3340
110110
* this section provides configuration interface for `mkinitcpio` provisioning actions
111-
* directives: `InitrdPath` `InitrdLink` `InitrdBinary` `InitrdBuild` `InitrdCall` `InitrdUnit`
111+
* directives: `InitrdPath` `InitrdLink` `InitrdBinary` `InitrdBuild` `InitrdCall` `InitrdUnit`
112112

113113
how can I auto-provision my custom service unit binaries into initramfs?
114114
* use `InitrdBinary=/path/target-exec` to provision service binary
@@ -121,10 +121,10 @@ how can I relocate folder during provisioning?
121121
* not implemented, source and target folder must use the same location
122122

123123
how can I relocate file and/or change file mode during provisioning?
124-
* use `InitrdPath=/target-file source=/source-file mode=NNN`
124+
* use `InitrdPath=/target-file source=/source-file mode=NNN`
125125

126126
how can I filter directory content during provisioning?
127-
* use `InitrdPath=/target-folder glob=*.example`
127+
* use `InitrdPath=/target-folder glob=*.example`
128128

129129
how can I provision optional folder or file?
130130
* use `InitrdPath=/target-file source=/source-file optional=yes`
@@ -134,40 +134,40 @@ is there a way to create empty folder or file?
134134
* for empty file, use `InitrdPath=/path/target-file create=yes` note NO trailing slash
135135

136136
how can I provision a symbolic link?
137-
* use `InitrdLink=/path-to-link/link-name /path-to-target/target-name`
138-
* note that `/path-to-target/target-name` must be provisioned separately
137+
* use `InitrdLink=/path-to-link/link-name target=/path-to-target/target-name`
138+
* note that link target `/path-to-target/target-name` must be provisioned separately
139139

140140
can I invoke a provisioning script related to my service during mkinitcpio build time?
141-
* use `InitrdBuild=/path-to/script.sh command=function_name`
141+
* use `InitrdBuild=/path-to/script.sh command=function_name`
142142

143143
can I call a little provisioning script snippet during mkinitcpio build time?
144144
* check for available `mkinitcpio` functions in `/usr/lib/initcpio/functions.sh`
145-
* use `InitrdCall=inline-bash-code-here` to call these functions
145+
* use `InitrdCall=inline-bash-code-here` to call these functions
146146

147147
how can I provide custom interactive user shell for ssh client
148-
* change sample shell file located in `/usr/lib/mkinitcpio-systemd-tool/initrd-shell.sh`
148+
* change sample shell file located in `/usr/lib/mkinitcpio-systemd-tool/initrd-shell.sh`
149149

150150
which ssh user keys are used by initramfs sshd server(s)?
151151
* they come from host `/root/.ssh/authorized_keys`
152152

153153
### Shell Script Questions and Answers
154154

155155
there is a `initrd-shell.sh` script provided, what does it do?
156-
* it is used as both interactive login shell and as a systemd service
156+
* it is used as both interactive login shell and as a systemd service
157157
* when crypto disks are present, it acts as password agent
158158
* when in ssh console, it offers simple interactive menu
159-
* when in systemd service mode, it acts as service
159+
* when in systemd service mode, it acts as service
160160

161161
how can I review `initrd-shell.sh` actions during last boot?
162162
* use `journalctl -b -t shell`
163163

164164
what does `CTRL-C` do to `initrd-shell.sh` in different modes?
165165
* `initrd-shell.sh` provides appropriate reaction to interrupt, depending on the context
166166
* while in `ssh` terminal password agent prompt, it will start a menu form `initrd-shell.sh`
167-
* while in `/dev/tty` local debug console, it will exit from `initrd-shell.sh`
167+
* while in `/dev/tty` local debug console, it will exit from `initrd-shell.sh`
168168
* while in `/dev/console` password agent prompt, it will restart the `initrd-shell.sh` service
169169

170170
is there a silent or no-echo mode during password entry in `initrd-shell.sh`?
171171
* there are two ways to enter silent mode (see `systemd-ask-password.c`):
172172
* either by pressing `BACKSPACE` as first key or by pressing `TAB` at any time
173-
* then the prompt will show extra text: `(no echo)`
173+
* then the prompt will show extra text: `(no echo)`

src/initrd-cryptsetup.path

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
# this is a twin unit for initrd-cryptsetup.service
1111
# enable only initrd-cryptsetup.path, initrd-cryptsetup.service is activated on demand
1212

13+
# note:
14+
# remove `sd-encrypt` from HOOKS=()
15+
1316
# note:
1417
# mutually exclusive with initrd-plymouth.path
1518

@@ -38,4 +41,7 @@ DirectoryNotEmpty=/run/systemd/ask-password
3841
WantedBy=sysinit.target
3942

4043
[X-SystemdTool]
41-
# not used
44+
45+
# provision disk tables in initramfs
46+
InitrdPath=/etc/crypttab source=/etc/mkinitcpio-systemd-tool/config/crypttab replace=yes
47+
InitrdPath=/etc/fstab source=/etc/mkinitcpio-systemd-tool/config/fstab replace=yes

src/initrd-cryptsetup.service

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,10 @@ TTYPath=/dev/console
4747
[X-SystemdTool]
4848

4949
# disable default password agents
50-
InitrdPath=/usr/lib/systemd/system/systemd-ask-password-console.path replace=yes create=yes
51-
InitrdPath=/usr/lib/systemd/system/systemd-ask-password-wall.path replace=yes create=yes
52-
53-
# provision disk tables in initramfs
54-
InitrdPath=/etc/crypttab source=/etc/mkinitcpio-systemd-tool/config/crypttab replace=yes
55-
InitrdPath=/etc/fstab source=/etc/mkinitcpio-systemd-tool/config/fstab replace=yes
50+
InitrdPath=/usr/lib/systemd/system/systemd-ask-password-console.path replace=yes create=yes
51+
InitrdPath=/usr/lib/systemd/system/systemd-ask-password-console.service replace=yes create=yes
52+
InitrdPath=/usr/lib/systemd/system/systemd-ask-password-wall.path replace=yes create=yes
53+
InitrdPath=/usr/lib/systemd/system/systemd-ask-password-wall.servive replace=yes create=yes
5654

5755
# provide folder for sysroot.mount
5856
InitrdPath=/sysroot/ create=yes
@@ -61,8 +59,7 @@ InitrdPath=/sysroot/ create=yes
6159
InitrdPath=/run/cryptsetup/ create=yes
6260

6361
# include early swap support
64-
InitrdBinary=/usr/bin/swapon
65-
InitrdBinary=/usr/bin/swapoff
62+
InitrdBinary=/usr/bin/mkswap
6663

6764
# include cryptsetup binaries
6865
InitrdBinary=/usr/bin/dmsetup

src/initrd-debug-progs.service

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ InitrdBinary=/usr/bin/journalctl
3232
InitrdBinary=/usr/bin/less replace=yes
3333
#InitrdBinary=/usr/bin/systemd-analyze
3434

35+
# early swap support
36+
InitrdBinary=/usr/bin/swapon optional=yes
37+
InitrdBinary=/usr/bin/swapoff optional=yes
38+
3539
# midnight commander
3640
InitrdBinary=/usr/bin/mc
3741
InitrdBinary=/usr/bin/mcedit

src/initrd-network.service

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,23 +31,23 @@ WantedBy=sysinit.target
3131
# TODO use predictable network interface names
3232
#InitrdPath=/usr/lib/udev/rules.d/80-net-setup-link.rules
3333

34-
# include network activated in initramfs
34+
# include network activated in initramfs
3535
InitrdPath=/etc/systemd/network/initrd-network.network source=/etc/mkinitcpio-systemd-tool/network/initrd-network.network
3636

37-
# provision discovered network kernel modules
37+
# provision discovered network kernel modules
3838
InitrdCall=add_checked_modules /drivers/net/
3939

4040
# runtime location of resolv.conf provided by systemd-resolved.service
41-
InitrdLink=/etc/resolv.conf /run/systemd/resolve/resolv.conf
41+
InitrdLink=/etc/resolv.conf target=/run/systemd/resolve/resolv.conf
4242

43-
# ensure consistent host name
43+
# ensure consistent host name
4444
InitrdPath=/etc/hostname replace=yes optional=yes
4545

46-
# include default config file for systemd-resolved.service
46+
# include default config file for systemd-resolved.service
4747
InitrdPath=/usr/lib/systemd/resolv.conf
4848

4949
# dns resolution support
5050
InitrdBinary=/usr/lib/libnss_dns.so.2 optional=yes
5151

52-
# required for systemd-resolved
52+
# required for systemd-resolved
5353
InitrdPath=/var/tmp/ create=yes

src/initrd-shell.service

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ InitrdBinary=/usr/bin/systemd-cat
2727
InitrdBinary=/usr/bin/journalctl
2828

2929
# configure login script
30-
InitrdLink=/root/.profile /usr/lib/mkinitcpio-systemd-tool/initrd-shell.sh
30+
InitrdLink=/root/.profile target=/usr/lib/mkinitcpio-systemd-tool/initrd-shell.sh
3131

3232
# configure user settings
3333
InitrdPath=/etc/group replace=yes
@@ -40,9 +40,9 @@ InitrdBuild=/usr/lib/mkinitcpio-systemd-tool/initrd-build.sh command=do_secret_c
4040
InitrdPath=/root/.ssh/authorized_keys source=/root/.ssh/authorized_keys mode=600
4141

4242
# override system actions
43-
InitrdLink=/usr/bin/halt /usr/bin/systemctl
44-
InitrdLink=/usr/bin/reboot /usr/bin/systemctl
45-
InitrdLink=/usr/bin/shutdown /usr/bin/systemctl
43+
InitrdLink=/usr/bin/halt target=/usr/bin/systemctl
44+
InitrdLink=/usr/bin/reboot target=/usr/bin/systemctl
45+
InitrdLink=/usr/bin/shutdown target=/usr/bin/systemctl
4646

4747
# required by /etc/nsswitch.conf
4848
InitrdBinary=/usr/lib/libnss_compat.so optional=yes

src/initrd-shell.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
# * implements minimal interactive menu
1010
# * implements password query/reply agent, see reference.md
1111

12-
# https://github.com/koalaman/shellcheck
12+
# Using shell linter: https://github.com/koalaman/shellcheck
1313
# shellcheck shell=dash
1414
# shellcheck disable=SC1008 # This shebang was unrecognized
1515
# shellcheck disable=SC2169 # In dash, [[ ]] is not supported

0 commit comments

Comments
 (0)