Skip to content

Commit

Permalink
Add dracut-module example
Browse files Browse the repository at this point in the history
- [x] Add dracut-module example Containerfile and readme
- [x] Add dracut-module example to main readme
- [x] Add dracut-module github workflow file
- [x] Test build dracut-module example
  • Loading branch information
thwiest-celonis committed Sep 7, 2023
1 parent d6606e8 commit 95f79b0
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 1 deletion.
34 changes: 34 additions & 0 deletions .github/workflows/dracut-module.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: "Build image: dracut-module"

env:
IMAGE_NAME: "dracut-module"

on:
pull_request:
branches:
- main
paths:
- dracut-module/*
- .github/workflows/dracut-module.yml
push:
branches:
- main
paths:
- dracut-module/*
- .github/workflows/dracut-module.yml

jobs:
build-image:
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v3

- name: Build container image
uses: redhat-actions/buildah-build@v2
with:
context: ${{ env.IMAGE_NAME }}
containerfiles: ${{ env.IMAGE_NAME }}/Containerfile
image: ${{ env.IMAGE_NAME }}
layers: false
oci: true
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ functionality.
- [build-zfs-module](build-zfs-module/): Build the ZFS third party module as rpm and install it
- [butane](butane/): Demos using https://github.com/coreos/butane
- [convert-ubuntu-package](convert-ubuntu-package/): Convert an Ubuntu package to rpm using [alien](https://wiki.debian.org/Alien) and install it.
- [dracut-module](dracut-module): Install and run a dracut module
- [initramfs-module](initramfs-module/): Demos generating a initramfs with specific modules added and omitted.
- [inject-go-binary](inject-go-binary/): Demos adding building and injecting a Go binary + systemd unit
- [podman-next](podman-next): Use COPR to install the podman-next package
Expand Down
2 changes: 1 addition & 1 deletion convert-ubuntu-package/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Convert an Ubuntu Package and Install It

This example converts an Ubuntu package into an rpm using [alien](https://wiki.debian.org/Alien) an then installs it using `rpm-ostree`.
This example converts an Ubuntu package into an rpm using [alien](https://wiki.debian.org/Alien) and then installs it using `rpm-ostree`.

This is useful for packages that are present in Ubuntu, but not in Fedora. This example installs Ubuntu's latest packaged version of gocryptfs, which is [no longer maintained in Fedora](https://discussion.fedoraproject.org/t/gocryptfs-not-available-on-fedora-36).
25 changes: 25 additions & 0 deletions dracut-module/Containerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Install and run a dracut module
FROM quay.io/fedora/fedora-coreos:stable

# Install dracut module requirements
RUN rpm-ostree install busybox rng-tools pcsc-tools bluez && \
ostree container commit

# Add dracut module files
COPY files/ /usr/lib/dracut/modules.d/10systemd-echo-here/

# Run dracut to build a new initrd
RUN stock_arguments=$(lsinitrd /lib/modules/6.4.7-200.fc38.x86_64/initramfs.img | grep '^Arguments: ' | sed 's/^Arguments: //') && \
mkdir -p /tmp/dracut /var/roothome && \
bash <(/usr/bin/echo "dracut $stock_arguments") && \
rm -rf /var/* /tmp/* && \
ostree container commit

# Move the new initrd into place while keeping the stock initrd in the image for reference.
RUN export KERNEL_VERSION="$(rpm -qa kernel --queryformat '%{VERSION}-%{RELEASE}.%{ARCH}')" && \
mv -v "/lib/modules/${KERNEL_VERSION}/initramfs.img" "/lib/modules/${KERNEL_VERSION}/initramfs.stock.img" && \
mv -v /boot/initramfs*.img "/lib/modules/${KERNEL_VERSION}/initramfs.img" && \
ostree container commit

# Show that the initrd includes the echo-here service:
RUN lsinitrd /lib/modules/*/initramfs.img | grep echo-here
7 changes: 7 additions & 0 deletions dracut-module/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Install and run a dracut module

This example adds a dracut module to the container and calls dracut to build a new initrd using this module.

This is useful when something needs to run inside of the initrd, which is very early in the boot process.

This specific example registers a systemd service that prints out when it was executed.
13 changes: 13 additions & 0 deletions dracut-module/files/echo-here.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[Unit]
Description=Service to Echo Here During initrd Startup
DefaultDependencies=no
ConditionVirtualization=!container

Requires=systemd-udev-settle.service
After=systemd-udev-settle.service
Before=cryptsetup.target

[Service]
Type=oneshot
ExecStart=/usr/bin/echo --------------------HERE--------------------

9 changes: 9 additions & 0 deletions dracut-module/files/module-setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
depends() {
echo systemd
return 0
}

install() {
inst_simple "${moddir}/echo-here.service" "${systemdsystemunitdir}/echo-here.service"
$SYSTEMCTL -q --root "$initdir" add-wants cryptsetup.target echo-here.service
}

0 comments on commit 95f79b0

Please sign in to comment.