Date: Tuesday, July 23, 2013 @ 01:52:11 Author: tomegun Revision: 191269
add systemd initcpio hook This hook allows you to boot with systemd in the initcpio instead of the current 'base'. Added: systemd/trunk/initcpio-install-systemd Modified: systemd/trunk/PKGBUILD --------------------------+ PKGBUILD | 3 initcpio-install-systemd | 147 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 150 insertions(+) Modified: PKGBUILD =================================================================== --- PKGBUILD 2013-07-22 18:59:43 UTC (rev 191268) +++ PKGBUILD 2013-07-22 23:52:11 UTC (rev 191269) @@ -16,12 +16,14 @@ 0001-utmp-turn-systemd-update-utmp-shutdown.service-into-.patch 0001-journald-DO-recalculate-the-ACL-mask-but-only-if-it-.patch 'initcpio-hook-udev' + 'initcpio-install-systemd' 'initcpio-install-udev' 'initcpio-install-timestamp') md5sums=('a07619bb19f48164fbf0761d12fd39a8' '7f39f9fde1ff7b48293ed1e3d0a6c213' '66e3162856ded8eb7dc7383405c6e0d6' 'e99e9189aa2f6084ac28b8ddf605aeb8' + 'f5edda743fb0611f11f9b82ecddcf4b3' 'fb37e34ea006c79be1c54cbb0f803414' 'df69615503ad293c9ddf9d8b7755282d') @@ -110,6 +112,7 @@ s#GROUP="cdrom"#GROUP="optical"#g' "$pkgdir"/usr/lib/udev/rules.d/*.rules # add mkinitcpio hooks + install -Dm644 "$srcdir/initcpio-install-systemd" "$pkgdir/usr/lib/initcpio/install/systemd" install -Dm644 "$srcdir/initcpio-install-udev" "$pkgdir/usr/lib/initcpio/install/udev" install -Dm644 "$srcdir/initcpio-hook-udev" "$pkgdir/usr/lib/initcpio/hooks/udev" install -Dm644 "$srcdir/initcpio-install-timestamp" "$pkgdir/usr/lib/initcpio/install/timestamp" Added: initcpio-install-systemd =================================================================== --- initcpio-install-systemd (rev 0) +++ initcpio-install-systemd 2013-07-22 23:52:11 UTC (rev 191269) @@ -0,0 +1,147 @@ +#!/bin/bash + +add_udev_rules() { + # Add an udev rules file to the initcpio image. Dependencies on binaries + # will be discovered and added. + # $1: path to rules file (or name of rules file) + + local rules= rule= key= value= binary= + + rules=$(PATH=/usr/lib/udev/rules.d:/lib/udev/rules.d type -P "$1") + if [[ -z $rules ]]; then + # complain about not found rules + return 1 + fi + + add_file "${rules}" + + while IFS=, read -ra rule; do + for pair in "${rule[@]}"; do + IFS='=' read -r key value <<< "$pair" + + case $key in + RUN@({program}|)@(+|)|IMPORT{program}|ENV{REMOVE_CMD}) + binary=${value[0]#\"} + if [[ ${binary:0:1} != '/' ]]; then + binary=$(PATH=/usr/lib/udev:/lib/udev type -P "$binary") + fi + add_binary "$binary" + ;; + esac + done + done < "$rules" +} + +add_systemd_unit() { + # Add a systemd unit file to the initcpio image. Hard dependencies on binaries + # and other unit files will be discovered and added. + # $1: path to rules file (or name of rules file) + + local unit= rule= entry= key= value= binary= dep= + + unit=$(PATH=/usr/lib/systemd/system:/lib/systemd/system type -P "$1") + if [[ -z $unit ]]; then + # complain about not found unit file + return 1 + fi + + add_file "${unit}" + + while IFS='=' read -r key values; do + + read -ra values <<< "$values" + + case $key in + Requires|OnFailure) + # only add hard dependencies (not Wants) + map add_systemd_unit "${values[@]}" + ;; + Exec*) + # don't add binaries unless they are required + if [[ ${values[0]:0:1} != '-' ]]; then + add_binary "${values[0]}" + fi + ;; + esac + + done < "$unit" + + # preserve reverse soft dependency + for dep in {/usr/lib/systemd/system,/lib/systemd/system}/*.wants/${unit##*/}; do + if [[ -h "${dep}" ]]; then + add_symlink "${dep}" + fi + done + + # add hard dependencies + if [[ -d "${unit}.requires" ]]; then + for dep in "${unit}".requires/*; do + add_systemd_unit ${dep##*/} + done + fi +} + +build() { + local rules unit + + # from base + add_binary /bin/mount + add_binary /usr/bin/kmod /usr/bin/modprobe + + # systemd + add_binary /usr/lib/systemd/systemd /init + + # generate sysroot.mount and sysroot-usr.mount + add_file "/usr/lib/systemd/system-generators/systemd-fstab-generator" + + # udev rules and systemd units + for rules in \ + 50-udev-default.rules \ + 60-persistent-storage.rules \ + 64-btrfs.rules \ + 80-drivers.rules \ + 99-systemd.rules \ + ; do + add_udev_rules "$rules" + done + for unit in \ + systemd-udevd-control.socket \ + systemd-udevd-kernel.socket \ + sockets.target \ + systemd-journald.service \ + systemd-udevd.service \ + systemd-udev-trigger.service \ + initrd-cleanup.service \ + initrd-fs.target \ + initrd-parse-etc.service \ + initrd-root-fs.target \ + initrd-switch-root.service \ + initrd-switch-root.target \ + initrd-udevadm-cleanup-db.service \ + initrd.target \ + systemd-fsck@.service \ + ctrl-alt-del.target \ + ; do + add_systemd_unit "$unit" + done + + add_symlink "/usr/lib/systemd/system/default.target" "initrd.target" + + + # libdbus needs the passwd info of the root user + # TODO: make sure this is no longer necessary when systemctl moves to sd-bus + add_file "/etc/nsswitch.conf" + add_file "/etc/passwd" + add_file "/lib/libnss_files-2.17.so" + add_symlink "/lib/libnss_files.so.2" "libnss_files-2.17.so" + add_symlink "/lib/libnss_files.so" "libnss_files.so.2" +} + +help() { + cat <<HELPEOF +This will install a basic systemd setup on your initrd, it is meant to replace the 'base', 'usr', 'fsck' and 'timestamp' hooks. +Other hooks would need to be ported, and may not work as intended. +HELPEOF +} + +# vim: set ft=sh ts=4 sw=4 et: