Skip to content

Commit

Permalink
release
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrei-Pozolotin committed Jun 11, 2016
1 parent c652843 commit 5e04193
Show file tree
Hide file tree
Showing 12 changed files with 146 additions and 58 deletions.
25 changes: 13 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,23 +60,25 @@ systemctl reboot

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

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

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

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

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

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

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

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

how can I install latest release or development version of this?
* create a marker file `.PKGDEV` to build from latest master branch,
* create a marker file `.PKGREL` to build from latest release tag,
* create a marker file `.PKGDEV` to build from latest branch=master ,
* create a marker file `.PKGREL` to build from latest release tag=vNNN,
* for example:
```
mkdir -p /tmp/aur
Expand Down
8 changes: 3 additions & 5 deletions crypttab
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@
# how crypttab is used by systemd
# https://www.freedesktop.org/software/systemd/man/systemd-cryptsetup-generator.html

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

# <name> <device> <password> <options>
swap UUID=${UUID_SWAP} none luks
root UUID=${UUID_ROOT} none luks
swap UUID=${UUID_SWAP} none luks
root UUID=${UUID_ROOT} none luks
19 changes: 19 additions & 0 deletions fstab
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# This file is part of https://github.com/random-archer/mkinitcpio-systemd-tool

# TODO
# currently systemd requires use of "root=" kenel argument for /sysroot mount
# https://github.com/systemd/systemd/blob/master/src/fstab-generator/fstab-generator.c

# fstab: mappings for direct partitions

# fstab format:
# https://wiki.archlinux.org/index.php/Fstab

# how fstab is used by systemd
# https://www.freedesktop.org/software/systemd/man/systemd-fstab-generator.html

# provide here root partition description (instead of kernel command line)

# <file system> <dir> <type> <option <dump> <pass>
# /dev/mapper/swap none swap defaults 0 0
# /dev/mapper/root /sysroot ext4 defaults,ro 0 1
11 changes: 9 additions & 2 deletions initrd-cryptsetup.service
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
[Unit]
Description=Initrd Cryptsetup Service
Documentation=https://github.com/random-archer/mkinitcpio-systemd-tool/blob/master/README.md
ConditionPathExists=/etc/crypttab
ConditionPathExists=/etc/fstab
ConditionPathExists=/etc/initrd-release
DefaultDependencies=no
After=initrd-shell.service
Expand All @@ -31,8 +33,12 @@ WantedBy=sysinit.target

[X-SystemdTool]

# provision crypttab in initramfs
InitrdPath=/etc/crypttab source=/etc/mkinitcpio.d/crypttab optional=yes
# enable service
InitrdService=enable

# provision disk tables in initramfs
InitrdPath=/etc/crypttab source=/etc/mkinitcpio.d/crypttab replace=yes
InitrdPath=/etc/fstab source=/etc/mkinitcpio.d/fstab replace=yes

# include cryptsetup binaries
InitrdBinary=/usr/bin/dmsetup
Expand All @@ -50,6 +56,7 @@ InitrdPath=/usr/lib/systemd/system/cryptsetup.target
InitrdPath=/usr/lib/systemd/system/cryptsetup-pre.target
InitrdBinary=/usr/lib/systemd/systemd-cryptsetup
InitrdBinary=/usr/lib/systemd/system-generators/systemd-cryptsetup-generator
InitrdBinary=/usr/lib/systemd/system-generators/systemd-fstab-generator

# include systemd password agent support
InitrdBinary=/usr/bin/systemd-ask-password
Expand Down
6 changes: 4 additions & 2 deletions initrd-debug-progs.service
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,16 @@ WantedBy=initrd-debug-shell.service

[X-SystemdTool]

# enable service
InitrdService=enable

# debug tools
InitrdBinary=/usr/bin/strace optional=yes

# systemd tools
InitrdBinary=/usr/bin/systemd-analyze
InitrdBinary=/usr/bin/journalctl
# proper pager for journalctl
InitrdBinary=/usr/bin/less replace=yes
#InitrdBinary=/usr/bin/systemd-analyze

# midnight commander
InitrdBinary=/usr/bin/mc
Expand Down
8 changes: 7 additions & 1 deletion initrd-debug-shell.service
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ Documentation=https://github.com/random-archer/mkinitcpio-systemd-tool/blob/mast
ConditionPathExists=/etc/initrd-release
ConditionPathExists=/dev/tty8
DefaultDependencies=no
IgnoreOnIsolate=yes

[Service]
Environment=TERM=linux
ExecStart=/bin/sh
Restart=always
RestartSec=1s
RestartSec=3s
StandardInput=tty
TTYPath=/dev/tty8
TTYReset=yes
Expand All @@ -24,3 +25,8 @@ IgnoreSIGPIPE=no

[Install]
WantedBy=sysinit.target

[X-SystemdTool]

# enable service
InitrdService=enable
17 changes: 10 additions & 7 deletions initrd-dropbear.service
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,26 @@ ExecReload=/bin/kill -HUP ${MAINPID}
# dropbear reports 1 when exiting on SIGTERM
SuccessExitStatus= 0 1
Restart=always
RestartSec=1s
RestartSec=3s

[Install]
WantedBy=sysinit.target

[X-SystemdTool]

# enable service
InitrdService=enable

# ensure dropbear server host keys
InitrdBuild=/etc/systemd/system/initrd-build.sh command=do_ssh_host_keys

# include generated dropbear configuration
InitrdPath=/etc/dropbear

# provide expected dropbear layout
InitrdPath=/var/run/ create=yes source=/invalid-source
InitrdPath=/var/run/utmp create=yes source=/invalid-source
InitrdPath=/var/log/ create=yes source=/invalid-source
InitrdPath=/var/log/btmp create=yes source=/invalid-source
InitrdPath=/var/log/wtmp create=yes source=/invalid-source
InitrdPath=/var/log/lastlog create=yes source=/invalid-source
InitrdPath=/var/run/ create=yes
InitrdPath=/var/run/utmp create=yes
InitrdPath=/var/log/ create=yes
InitrdPath=/var/log/btmp create=yes
InitrdPath=/var/log/wtmp create=yes
InitrdPath=/var/log/lastlog create=yes
16 changes: 11 additions & 5 deletions initrd-emergency.service
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
[Unit]
Description=Initrd Emergency Service
Documentation=https://github.com/random-archer/mkinitcpio-systemd-tool/blob/master/README.md
ConditionPathExists=/etc/initrd-release
ConditionPathExists=/etc/xxx/initrd-release
DefaultDependencies=no
Conflicts=shutdown.target
Conflicts=rescue.service
Expand All @@ -20,13 +20,19 @@ Wants=initrd-debug-shell.service
[Service]
ExecStartPre=/bin/echo "Initrd Emergency Service"
ExecStartPre=/bin/sh -c 'for step in 1 2 3; do echo -n "$step "; sleep 1; done; echo ".";'
ExecStart=/usr/bin/systemctl --job-mode=fail --no-block default
ExecStartPre=/usr/bin/systemctl daemon-reload
ExecStartPre=/usr/bin/systemctl --job-mode=fail --no-block default
ExecStart=/bin/true
Type=idle
StandardInput=null
StandardOutput=tty
StandardError=tty
StandardOutput=journal+console
StandardError=journal+console
TTYPath=/dev/console

[X-SystemdTool]

# disable service
InitrdService=disable

# override /usr/lib/systemd/system/emergency.service
InitrdPath=/etc/systemd/system/emergency.service source=/etc/systemd/system/initrd-emergency.service
#InitrdPath=/etc/systemd/system/emergency.service source=/etc/systemd/system/initrd-emergency.service
3 changes: 3 additions & 0 deletions initrd-network.service
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ WantedBy=sysinit.target

[X-SystemdTool]

# enable service
InitrdService=enable

# TODO use predictable network interface names
#InitrdPath=/usr/lib/udev/rules.d/80-net-setup-link.rules

Expand Down
8 changes: 8 additions & 0 deletions initrd-shell.service
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ WantedBy=sysinit.target

[X-SystemdTool]

# enable service
InitrdService=enable

# provision initrd shell
InitrdPath=/etc/systemd/system/initrd-shell.sh mode=700
InitrdBinary=/usr/bin/sulogin
Expand All @@ -38,3 +41,8 @@ InitrdBuild=/etc/systemd/system/initrd-build.sh command=do_secret_clean

# include ssh credentials
InitrdPath=/root/.ssh/authorized_keys source=/root/.ssh/authorized_keys mode=600

# override system actions
InitrdLink=/usr/bin/halt /usr/bin/systemctl
InitrdLink=/usr/bin/reboot /usr/bin/systemctl
InitrdLink=/usr/bin/shutdown /usr/bin/systemctl
76 changes: 52 additions & 24 deletions mkinitcpio-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ build() {
local dir="/etc/systemd/system"
add_dir $dir

local unit_list=$(2>/dev/null grep -l -F "$tag" "$dir"/*.service)
# locate units marked for inclusion into initramfs
local unit_list=$(2>/dev/null grep -l -F "$tag" "$dir"/*)
[[ $unit_list ]] || error "Missing any units in $dir with entry $tag"

local unit
for unit in $unit_list ; do
add_systemd_unit_X "$unit"
run_command systemctl --root "$BUILDROOT" enable "$unit"
done

}
Expand Down Expand Up @@ -96,53 +96,61 @@ add_systemd_unit_X() {
InitrdBinary)
# provision binaries
# format:
# InitrdBinary=/path/exec [replace=yes] [optional=yes]
local target= args= replace= optional=
# InitrdBinary=/path/exec [source=/host/exec] [replace=yes] [optional=yes]
local source= target= args= replace= optional=
target=${values[0]} ; args=${values[@]:1:9}
[[ $args ]] && local ${args[*]}
[[ $source ]] || source="$target"
if [[ -f $BUILDROOT$target ]] ; then
if [[ $replace == "yes" ]] ; then
quiet "replace present binary $target"
add_binary "$target"
add_binary "$source" "$target"
else
quiet "reuse present binary $target"
fi
elif [[ -f $target ]] ; then
elif [[ -f $source ]] ; then
quiet "provision new binary $target"
add_binary "$target"
add_binary "$source" "$target"
elif [[ $optional = "yes" ]] ; then
quiet "skip optional binary $target"
else
error "missing host binary $target"
error "invalid source binary $source"
fi
;;
InitrdPath)
# provision folder/file
# provision dir/file
# format:
# InitrdPath=/path/folder [glob=*.sh]
# InitrdPath=/path/file [source=/lib/file] [mode=755]
local source= target= mode= glob= args= optional= create=
# InitrdPath=/path/dir [glob=*.sh]
# InitrdPath=/path/file [source=/lib/file]
# arguments: [mode=755] [create=yes] [replace=yes] [optional=yes]
local source= target= args= mode= glob= optional= create= replace=
target=${values[0]} ; args=${values[@]:1:9}
[[ $args ]] && local ${args[*]}
[[ $source ]] || source="$target"
if [[ $replace == "yes" ]] ; then
quiet "replace path $target"
rm -f -r "$BUILDROOT$target"
fi
if [[ -e $BUILDROOT$target ]] ; then
quiet "reuse present path $target"
quiet "reuse path $target"
elif [[ $create == "yes" ]] ; then
if [[ ${target: -1} == "/" ]] ; then
quiet "create empty dir $target $mode"
add_dir "$target" "$mode"
else
quiet "create empty file $target $mode"
source=$(mktemp)
add_file "$source" "$target" "$mode"
rm -f "$source"
fi
elif [[ -d $source ]] ; then
quiet "provision new dir $source $glob"
add_full_dir "$source" "$glob"
elif [[ -f $source ]] ; then
quiet "provision new file $source -> $target $mode"
add_file "$source" "$target" "$mode"
elif [[ $create == "yes" ]] ; then
if [[ ${target: -1} == "/" ]] ; then
quiet "create empty dir $target"
add_dir "$target"
else
quiet "create empty file $target $mode"
add_file "$(mktemp)" "$target" "$mode"
fi
elif [[ $optional = "yes" ]] ; then
quiet "skip optional path $source -> $target"
quiet "skip optional path $target"
else
error "invalid source path $source"
fi
Expand Down Expand Up @@ -194,12 +202,32 @@ add_systemd_unit_X() {
$code
fi
;;
esac
InitrdService)
# invoke service configuration action
# format:
# InitrdService=enable|disable|mask|unmask
local action= name=
action=${values[0]}
name="$(basename $unit)"
case "$action" in
enable|disable|mask|unmask)
quiet "apply [$action] for unit [$name]"
run_command systemctl --root "$BUILDROOT" "$action" "$name"
;;
*)
error "invalid InitrdService action: $action"
;;
esac
;;
Initrd*)
error "invalid [X-SystemdTool] directive: $key"
;;
esac

done <"$unit"

# preserve reverse soft dependency
for dep in {/usr,}/lib/systemd/system/*.wants/${unit##*/}; do
for dep in {/etc,/usr/lib}/systemd/system/*.wants/${unit##*/}; do
if [[ -L $dep ]]; then
add_symlink "$dep"
fi
Expand Down
Loading

0 comments on commit 5e04193

Please sign in to comment.