Skip to content

udev: run both as onboot and as service; drop hardcoded modprobe #270

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion images/hook-udev/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ RUN DEBIAN_FRONTEND=noninteractive apt update && \
apt-get autoremove --yes && \
rm -rf /var/lib/apt /var/lib/dpkg /var/lib/cache /var/lib/log /var/cache/* /usr/lib/apt/* /usr/share/*

CMD ["/etc/init.d/udev", "start"]
ADD ./one-shot.sh /one-shot.sh
CMD ["/lib/systemd/systemd-udevd", "--debug"]
32 changes: 32 additions & 0 deletions images/hook-udev/one-shot.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/bash

# Here we start the systemd-udev daemon, sleep a bit, run udevadm settle, and then stop the daemon, all using bash.
# This is a one-shot script that is run by LinuxKit when the system boots up.

echo "$(date) Starting systemd-udev in the background..."
/lib/systemd/systemd-udevd "${@}" &
declare udev_pid=$!
echo "$(date) systemd-udev started with PID: ${udev_pid}"

echo "$(date) Sleeping for 2 seconds so systemd-udev does its job..."
sleep 2

echo "$(date) Running udevadm trigger..."
udevadm trigger --action=add

echo "$(date) Running udevadm settle..."
udevadm settle

echo "$(date) Status of /dev/disk/by-id:"
ls -la /dev/disk/by-id/* || true

echo "$(date) Stopping systemd-udev with PID: ${udev_pid}"
kill -SIGTERM "${udev_pid}"

echo "$(date) Waiting for systemd-udev to stop..."
wait

echo "$(date) systemd-udev stopped with PID: ${udev_pid}"
echo "$(date) One-shot script completed."

exit 0
27 changes: 13 additions & 14 deletions linuxkit-templates/hook.template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,13 @@ onboot:
- name: sysfs
image: linuxkit/sysfs:v1.0.0

- name: modprobe
image: linuxkit/modprobe:v1.0.0
command: [ "modprobe", "cdc_ncm" ] # for usb ethernet dongles

- name: udev
- name: udev-once
image: "${HOOK_CONTAINER_UDEV_IMAGE}"
capabilities:
- all
binds:
- /dev:/dev
- /sys:/sys
- /lib/modules:/lib/modules
command: [ "/usr/bin/bash", "/one-shot.sh" ]
capabilities: [ all ]
binds: [ /dev:/dev, /sys:/sys, /lib/modules:/lib/modules ]
rootfsPropagation: shared
devices:
- path: all
type: b
devices: [ { path: all, type: b }, { path: all, type: c } ]

- name: dhcpcd-once
image: linuxkit/dhcpcd:v1.0.0
Expand All @@ -77,6 +68,14 @@ services:
- name: ntpd
image: linuxkit/openntpd:v1.0.0

- name: udev # as a service; so system reacts to changes in devices
image: "${HOOK_CONTAINER_UDEV_IMAGE}"
command: [ "/lib/systemd/systemd-udevd", "--debug" ]
capabilities: [ all ]
binds: [ /dev:/dev, /sys:/sys, /lib/modules:/lib/modules ]
rootfsPropagation: shared
devices: [ { path: all, type: b }, { path: all, type: c } ]

- name: getty
image: linuxkit/getty:v1.0.0
capabilities:
Expand Down
Loading