You are not logged in.

#1 2018-11-27 18:27:17

rlees85
Member
From: Daventry, UK
Registered: 2015-04-29
Posts: 98
Website

Custom systemd initcpio unit

Not sure if this is the right sub-forum but here goes....

Has anyone here got any experience with making a custom systemd initcpio hook?

What I'm trying to do I think is simple enough, I am using the "systemd" startup hook instead of the "udev" one, but I have a custom script that I would like to run in the initramfs stage. As I am using systemd I need to include a systemd service/unit too. The only problem is, that even after getting the unit file into the ramdisk image, the unit never starts.

What I have so far:

/etc/initcpio/install/growfs

#!/bin/bash

build() {
    add_binary date
    add_binary findfs
    add_binary growpart
    add_binary sfdisk
    add_systemd_unit initrd-growfs.service
}

help() {
    cat <<HELPEOF
This hook expands the root filesystem to the size of the partition
which is mostly useful for cloud images to expand to the block device
they've been given.
HELPEOF
}

# vim: set ft=sh ts=4 sw=4 et:

/usr/lib/systemd/system/initrd-growfs.service

[Unit]
Description=GrowFS Grow Root Partition Service
DefaultDependencies=no
Conflicts=shutdown.target emergency.service
Before=initrd-root-fs.target
ConditionPathExists=/etc/initrd-release

[Service]
Type=oneshot
ExecStart=/usr/local/bin/growfs
RemainAfterExit=true

Running mkinitcpio looks good:

[archlinux@archlinux ~]$ sudo mkinitcpio -p linux
==> Building image from preset: /etc/mkinitcpio.d/linux.preset: 'default'
  -> -k /boot/vmlinuz-linux -c /etc/mkinitcpio.conf -g /boot/initramfs-linux.img
==> Starting build: 4.19.4-arch1-1-ARCH
  -> Running build hook: [base]
  -> Running build hook: [systemd]
  -> Running build hook: [block]
==> WARNING: Possibly missing firmware for module: aic94xx
==> WARNING: Possibly missing firmware for module: wd719x
  -> Running build hook: [mdadm_udev]
  -> Running build hook: [modconf]
  -> Running build hook: [filesystems]
  -> Running build hook: [keyboard]
  -> Running build hook: [sd-vconsole]
  -> Running build hook: [fsck]
  -> Running build hook: [growfs]
==> Generating module dependencies
==> Creating gzip-compressed initcpio image: /boot/initramfs-linux.img
==> Image generation successful

If I manually extract the ramdisk image I can see my unit, binaries called within the unit, binaries manually added in the hook install are all present in expected locations.

But when I restart the machine the unit simply does not run! No error in journalctl, no error in systemctl status, no sign of growfs in any logs. It simply does not call the unit!

I am sure I am missing something stupid. Any ideas?

Offline

Board footer

Powered by FluxBB