@@ -34,30 +34,22 @@ cd /mnt/work
34
34
35
35
``` shell
36
36
modules=/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/
61
53
```
62
54
63
55
## Prepare a Flatcar Container Linux development container
@@ -84,7 +76,7 @@ Start the development container with the host's writable modules directory mount
84
76
Since the container requires access to loopback devices, ` --capability=CAP_NET_ADMIN ` is required.
85
77
``` shell
86
78
sudo systemd-nspawn \
87
- --bind=/usr/lib/modules \
79
+ --bind=/var/lib/extensions/kernel-modules/usr/lib/modules:/ usr/lib/modules \
88
80
--capability=CAP_NET_ADMIN \
89
81
--image=flatcar_developer_container.bin
90
82
```
@@ -107,3 +99,21 @@ In case the installation step didn't update the module dependency files automati
107
99
``` shell
108
100
sudo depmod
109
101
```
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