@@ -34,30 +34,22 @@ cd /mnt/work
3434
3535``` shell
3636modules=/opt/modules # Adjust this writable storage location as needed.
37- sudo mkdir -p " ${modules} " " ${modules} .wd"
38- ```
39-
40- Create a mount unit to use ` /opt/modules ` at boot - ` /etc/systemd/system/usr-lib-modules.mount ` :
41- ``` ini
42- [Unit]
43- Description =Custom Kernel Modules
44- Before =local-fs.target
45- ConditionPathExists =/opt/modules
46-
47- [Mount]
48- Type =overlay
49- What =overlay
50- Where =/usr/lib/modules
51- Options =lowerdir =/usr/lib/modules,upperdir =/opt/modules,workdir =/opt/modules.wd
52-
53- [Install]
54- WantedBy =local-fs.target
55- ```
56-
57- Enable the unit so this overlay becomes available:
58-
59- ``` shell
60- sudo systemctl enable --now usr-lib-modules.mount
37+ sudo mkdir -p " ${modules} .wd"
38+
39+ # prepare the structure for kernel-modules sysext
40+ sudo mkdir -p /var/lib/extensions/kernel-modules/usr/lib/{extension-release.d,modules}
41+
42+ # the kmod depends on current kernel and architecture, so include it in the metadata
43+ # this causes systemd-sysext to skip loading the sysext after upgrade
44+ source /etc/os-release && \
45+ printf " ID=flatcar\nVERSION_ID=%s\nARCHITECTURE=%s\n" \
46+ " $VERSION_ID " \
47+ " $( hostnamectl | grep ' Architecture:' | awk ' {print $2}' ) " \
48+ | sudo tee /var/lib/extensions/kernel-modules/usr/lib/extension-release.d/extension-release.kernel-modules
49+
50+ sudo mount -t overlay overlay \
51+ -o lowerdir=/usr/lib/modules,upperdir=/var/lib/extensions/kernel-modules/usr/lib/modules/,workdir=/opt/modules.wd \
52+ /var/lib/extensions/kernel-modules/usr/lib/modules/
6153```
6254
6355## Prepare a Flatcar Container Linux development container
@@ -84,7 +76,7 @@ Start the development container with the host's writable modules directory mount
8476Since the container requires access to loopback devices, ` --capability=CAP_NET_ADMIN ` is required.
8577``` shell
8678sudo systemd-nspawn \
87- --bind=/usr/lib/modules \
79+ --bind=/var/lib/extensions/kernel-modules/usr/lib/modules:/ usr/lib/modules \
8880 --capability=CAP_NET_ADMIN \
8981 --image=flatcar_developer_container.bin
9082```
@@ -107,3 +99,21 @@ In case the installation step didn't update the module dependency files automati
10799``` shell
108100sudo depmod
109101```
102+
103+ ## Clean up and activate the sysext
104+
105+ Exit the developer container and unmount the path on host and actvate the built sysext.
106+
107+ ``` shell
108+ # unmount the overlay
109+ sudo umount /var/lib/extensions/kernel-modules/usr/lib/modules/
110+
111+ # verify the final contents
112+ find /var/lib/extensions/kernel-modules/
113+
114+ # merge the freshly created sysext
115+ sudo systemd-sysext refresh
116+
117+ # load the module
118+ sudo modprobe < module name>
119+ ```
0 commit comments