Skip to content

Building an AutoSD image that includes a custom kernel

On a native AArch64 architecture system, you can compile a custom version of the OS kernel and then build a version of the AutoSD operating system (OS) image that includes the customized kernel. You can then install and run the customized AutoSD OS in either a virtualized environment or on an ARM board.

Note

Cross-compilation is unsupported for kernel customizations.

You must compile custom kernels on AArch64 hardware that is running a supported Linux host. See Getting Started on Linux, Sample OSBuild manifests, and Packaging applications with RPM for more information about software and hardware requirements for AArch systems.

The overall process consists of the following general steps:

  1. Customize the kernel source, compile a new kernel, and build RPM files.

  2. Build a custom AutoSD OS image and run it in a virtual environment.

  3. Build a custom AutoSD OS image and run it on physical hardware.

Compile a customized AutoSD kernel and build new RPM files

On a supported Linux host system running on AArch64 hardware, compile a customized kernel and modules from the CentOS Stream 9 kernel source code.

Note

This procedure assumes that you are using a CentOS Stream 9 host running on ARM hardware. If you use a different host system, some steps in this procedure might not work.

Prerequisites

Procedure

  1. Install the tools and dependencies necessary to compile the kernel:

    sudo dnf update
    sudo dnf groupinstall "Development Tools"
    sudo dnf install ncurses-devel bison flex elfutils-libelf-devel openssl-devel dwarves
    
  2. Clone the CentOS Stream automotive kernel source code Git repository to a local directory of your choice:

    git clone --depth 1 --branch main-automotive https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9.git/
    
  3. Go to the centos-stream-9 directory that contains the source code:

    cd centos-stream-9
    
  4. Add to or modify the kernel source code according to your requirements.

    Important

    You must stage and commit your changes in Git, or the make command will not pick up the changes and build them into the RPM packages.

  5. Generate the RPM workspace, which includes the kernel spec file, for the build:

    make -j$(nproc) dist-srpm
    
  6. Install the dependencies necessary to build the kernel RPM files:

    sudo dnf config-manager --set-enabled crb && sudo dnf builddep redhat/rpm/SPECS/kernel.spec
    
  7. Compile the custom kernel and build the RPM files. The following example uses _mykernel as the custom string to be appended to the new versions of the RPM file names:

    make -j$(nproc) DISTLOCALVERSION=_mykernel dist-all-rpms
    

    By appending a custom string, you can differentiate your custom build from the standard version.

    Important

    The custom version string must consist of alphanumeric characters plus any of the following optional separators: ., _, +, ~, and ^. The string cannot contain spaces or certain other characters, such as hyphens (-). If the string contains illegal characters, the build will fail.

    See the “Spec file format” RPM documentation for more information about using the ~ and ^ separators in version strings.

After a successful build, RPM files are installed to the following directory: ./redhat/rpm/RPMS/aarch64/.

Build an AutoSD image with a custom kernel and run it in a virtual environment

After you create your custom kernel RPM files, you can build a custom AutoSD image that includes the files and will run in a QEMU virtual machine.

Prerequisites

  • You have successfully built RPM package files that contain kernel customizations.

  • You have installed QEMU.

Procedure

  1. Go to your home directory:

    cd ~
    
  2. If you have not done so already, install the OSBuild utility:

    sudo dnf install osbuild
    
  3. Recursively clone the sample-images Gitlab repository:

    git clone --recursive https://gitlab.com/CentOS/automotive/sample-images.git
    
  4. Go to the automotive-image-builder directory:

    cd sample-images/automotive-image-builder
    
  5. Deploy the custom kernel RPM files:

    1. If you have not done so already, install the createrepo utility:

      sudo dnf install createrepo
      
    2. Create a new directory to use as a local RPM repository:

      sudo mkdir my_repo
      
    3. Copy your RPM files to the new directory:

      sudo cp -rp ~/centos-stream-9/redhat/rpm/RPMS/* my_repo
      
    4. Initialize the directory as an RPM package repository:

      sudo createrepo my_repo
      
  6. To build an OS image in .qcow format to run in a QEMU virtual environment, run the automotive-image-builder script, substituting your values for the RPM repo directory location and the kernel version name:

    ./automotive-image-builder build --distro cs9 --mode package --target qemu \
    --export qcow2 ~/sample-images/images/developer.mpp.yml my-custom-kernel.qcow2 \
    --define 'extra_repos=[{"id":"kernel","baseurl":"file:///<absolute-path-to-my_repo-directory>"}]' \
    --define 'kernel_version="5.14.0-515.464_mykernel.el9iv"'
    

    Note

    • The value for kernel_version should match the name of your custom kernel. You can find the name in the ~/centos-stream-9/redhat/rpm/RPMS/aarch64/ directory, which contains your custom built RPM files.

    • The value for baseurl can be any valid URL to an RPM repository that contains your custom kernel RPM files.

  7. Run the image:

    ./automotive-image-runner my-custom-kernel.qcow2
    
  8. After the image boots in QEMU, log in as root using the password password.

  9. Verify that your packaged software is present in your image by running the following command and verifying that the custom kernel name is returned:

    uname -r
    

Important

If you build multiple images, run dnf clean all between builds to clear the build artifacts and reset the DNF cache.

Build an AutoSD image with a custom kernel and run it on physical hardware

You can create an OS image in a specific format to install on specific physical hardware.

Prerequisites

  • You have recursively cloned the sample-images repository.

  • You are running an AArch64 system with Internet access.

  • You have successfully built RPM package files that contain kernel customizations.

Procedure

  1. If you have not done so already, install Podman:

    sudo dnf install podman
    
  2. Go to the automotive-image-builder directory:

    cd ~/sample-images/automotive-image-builder
    
  3. Deploy the custom kernel RPM files:

    1. If you have not done so already, install the createrepo utility:

      sudo dnf install createrepo
      
    2. Create a new directory to use as a local RPM repository:

      sudo mkdir my_repo
      
    3. Copy your RPM files to the new directory:

      sudo cp -rp ~/centos-stream-9/redhat/rpm/RPMS/* my_repo
      
    4. Initialize the directory as an RPM package repository:

      sudo createrepo my_repo
      
  4. Identify the image format appropriate for installation on your board:

    ./automotive-image-builder list-exports
    
  5. Identify the appropriate hardware target for your board:

    ./automotive-image-builder list-targets
    
  6. Build the image, specifying the appropriate target and the export file format and substituting your values for the RPM repo directory location and the kernel version name:

    ./automotive-image-builder --container build --distro autosd --mode package \
    --target <target> --export <export_image_format> ~/sample-images/images/developer.mpp.yml my-custom-kernel.img \
    --define 'extra_repos=[{"id":"kernel","baseurl":"file:///<absolute-path-to-my_repo-directory>"}]' \
    --define 'kernel_version="5.14.0-515.464_mykernel.el9iv"'
    

    Note

    • The value for kernel_version should match the name of your custom kernel. You can find the name in the ~/centos-stream-9/redhat/rpm/RPMS/aarch64/ directory, which contains your custom built RPM files.

    • The value for baseurl can be any valid URL to an RPM repository that contains your custom kernel RPM files.

  7. Follow the relevant procedure in the “Provisioning hardware” section to flash the OS image to your board.

  8. After the image boots, log in as root using the password password.

  9. Verify that your packaged software is present in your image by running the following command and verifying that the custom kernel name is returned:

    uname -r
    

Note

If you build multiple images, run dnf clean all between builds to clear the build artifacts and reset the DNF cache.

Additional resources


© Red Hat