Add comments to clarify build directory setup and root filesystem cre… #141
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Makefile CI | |
| env: | |
| VERSION: linux-6.16.2 | |
| on: | |
| push: | |
| branches: [ "main" ] | |
| pull_request: | |
| branches: [ "main" ] | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Cache the kernel | |
| id: cache-kernel | |
| uses: actions/cache@v4 | |
| with: | |
| path: ${{ env.VERSION }} | |
| key: ${{ env.VERSION }} | |
| # https://kernel.org | |
| - name: Download | |
| if: steps.cache-kernel.outputs.cache-hit != 'true' | |
| run: wget https://cdn.kernel.org/pub/linux/kernel/v6.x/${{ env.VERSION }}.tar.xz | |
| # https://docs.kernel.org/admin-guide/README.html#installing-the-kernel-source | |
| - name: Install the kernel source | |
| if: steps.cache-kernel.outputs.cache-hit != 'true' | |
| run: | | |
| xz -cd ${{ env.VERSION }}.tar.xz | tar xvf - | |
| cd ${{ env.VERSION }} | |
| make mrproper | |
| - name: Install libelf-dev | |
| if: steps.cache-kernel.outputs.cache-hit != 'true' | |
| run: sudo apt-get install -y libelf-dev | |
| # https://docs.kernel.org/admin-guide/README.html#build-directory-for-the-kernel | |
| # https://docs.kernel.org/admin-guide/README.html#configuring-the-kernel | |
| - name: Configure the kernel | |
| if: steps.cache-kernel.outputs.cache-hit != 'true' | |
| run: | | |
| cd ${{ env.VERSION }} | |
| make defconfig | |
| # https://docs.kernel.org/admin-guide/README.html#compiling-the-kernel | |
| - name: Compile the kernel | |
| if: steps.cache-kernel.outputs.cache-hit != 'true' | |
| run: | | |
| cd ${{ env.VERSION }} | |
| make | |
| - name: Build root filesystem | |
| run: | | |
| mkdir -p iso/boot | |
| pwd | |
| ls -l | |
| # https://docs.kernel.org/filesystems/ramfs-rootfs-initramfs.html | |
| # https://docs.kernel.org/filesystems/ramfs-rootfs-initramfs.html#contents-of-initramfs | |
| - name: Create initramfs image | |
| run: | | |
| mkdir initramfs | |
| cat > hello.c << EOF | |
| #include <stdio.h> | |
| #include <unistd.h> | |
| int main(int argc, char *argv[]) | |
| { | |
| printf("Hello world!\n"); | |
| sleep(999999999); | |
| } | |
| EOF | |
| gcc -static hello.c -o initramfs/init | |
| (cd initramfs; find . | cpio -o -H newc | gzip) > iso/boot/initramfs.cpio.gz | |
| - name: Install the kernel | |
| run: | | |
| cd ${{ env.VERSION }} | |
| install $(make -s image_name) ../iso/boot/vmlinuz | |
| install System.map ../iso/boot/System.map | |
| install .config ../iso/boot/config | |
| # https://www.gnu.org/software/grub/manual/grub/html_node/Making-a-GRUB-bootable-CD_002dROM.html | |
| - name: Make a GRUB bootable CD-ROM | |
| run: | | |
| sudo apt-get install -y mtools xorriso | |
| mkdir -p iso/boot/grub | |
| cat << EOF > iso/boot/grub/grub.cfg | |
| set default=0 | |
| set timeout=0 | |
| menuentry 'Linux' { | |
| linux /boot/vmlinuz console=ttyS0 console=tty0 ignore_loglevel | |
| initrd /boot/initramfs.cpio.gz | |
| } | |
| EOF | |
| grub-mkrescue -o grub.iso iso | |
| - name: Archive the ISO | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: grub.iso | |
| path: grub.iso |