<commit_before># Building custom kernel modules

## Create a writable overlay

The kernel modules directory `/lib/modules` is read-only on Container Linux. A writable overlay can be mounted over it to allow installing new modules.

```sh
modules=/opt/modules  # Adjust this writable storage location as needed.
sudo mkdir -p "$modules" "$modules.wd"
sudo mount \
    -o "lowerdir=/lib/modules,upperdir=$modules,workdir=$modules.wd" \
    -t overlay overlay /lib/modules
```

The following systemd unit can be written to `/etc/systemd/system/lib-modules.mount`.

```ini
[Unit]
Description=Custom Kernel Modules
Before=local-fs.target
ConditionPathExists=/opt/modules

[Mount]
Type=overlay
What=overlay
Where=/lib/modules
Options=lowerdir=/lib/modules,upperdir=/opt/modules,workdir=/opt/modules.wd

[Install]
WantedBy=local-fs.target
```

Enable the unit so this overlay is mounted automatically on boot.

```sh
sudo systemctl enable lib-modules.mount
```

## Prepare a CoreOS Container Linux development container

Read system configuration files to determine the URL of the development container that corresponds to the current Container Linux version.

```sh
. /usr/share/coreos/release
. /usr/share/coreos/update.conf
. /etc/coreos/update.conf  # This might not exist.
url="http://${GROUP:-stable}.release.core-os.net/$COREOS_RELEASE_BOARD/$COREOS_RELEASE_VERSION/coreos_developer_container.bin.bz2"
```

Download, decompress, and verify the development container image.

```sh
gpg2 --recv-keys <KEY>  # Fetch the buildbot key if neccesary.<commit_msg>os/kernel-modules: do not check /etc for channel information<commit_after># Building custom kernel modules

## Create a writable overlay

The kernel modules directory `/lib/modules` is read-only on Container Linux. A writable overlay can be mounted over it to allow installing new modules.

```sh
modules=/opt/modules  # Adjust this writable storage location as needed.
sudo mkdir -p "$modules" "$modules.wd"
sudo mount \
    -o "lowerdir=/lib/modules,upperdir=$modules,workdir=$modules.wd" \
    -t overlay overlay /lib/modules
```

The following systemd unit can be written to `/etc/systemd/system/lib-modules.mount`.

```ini
[Unit]
Description=Custom Kernel Modules
Before=local-fs.target
ConditionPathExists=/opt/modules

[Mount]
Type=overlay
What=overlay
Where=/lib/modules
Options=lowerdir=/lib/modules,upperdir=/opt/modules,workdir=/opt/modules.wd

[Install]
WantedBy=local-fs.target
```

Enable the unit so this overlay is mounted automatically on boot.

```sh
sudo systemctl enable lib-modules.mount
```

## Prepare a CoreOS Container Linux development container

Read system configuration files to determine the URL of the development container that corresponds to the current Container Linux version.

```sh
. /usr/share/coreos/release
. /usr/share/coreos/update.conf
url="http://${GROUP:-stable}.release.core-os.net/$COREOS_RELEASE_BOARD/$COREOS_RELEASE_VERSION/coreos_developer_container.bin.bz2"
```

Download, decompress, and verify the development container image.

```sh
gpg2 --recv-keys <KEY>  # Fetch the buildbot key if neccesary.
{'fraction_non_alphanumeric': 0.10856958762886598, 'fraction_numerical': 0.001288659793814433, 'mean_word_length': 4.914285714285715, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4783031', 'n_tokens_mistral': 959, 'n_tokens_neox': 898, 'n_words': 295}