diff --git a/.github/workflows/dracut-module.yml b/.github/workflows/dracut-module.yml new file mode 100644 index 0000000..dc94532 --- /dev/null +++ b/.github/workflows/dracut-module.yml @@ -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 diff --git a/README.md b/README.md index 46debdf..469da1f 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/convert-ubuntu-package/README.md b/convert-ubuntu-package/README.md index 13b427c..f7f3722 100644 --- a/convert-ubuntu-package/README.md +++ b/convert-ubuntu-package/README.md @@ -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). diff --git a/dracut-module/Containerfile b/dracut-module/Containerfile new file mode 100644 index 0000000..ffab98f --- /dev/null +++ b/dracut-module/Containerfile @@ -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 diff --git a/dracut-module/README.md b/dracut-module/README.md new file mode 100644 index 0000000..5ff2fac --- /dev/null +++ b/dracut-module/README.md @@ -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. diff --git a/dracut-module/files/echo-here.service b/dracut-module/files/echo-here.service new file mode 100644 index 0000000..2ceef96 --- /dev/null +++ b/dracut-module/files/echo-here.service @@ -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-------------------- + diff --git a/dracut-module/files/module-setup.sh b/dracut-module/files/module-setup.sh new file mode 100644 index 0000000..bda742a --- /dev/null +++ b/dracut-module/files/module-setup.sh @@ -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 +}