# Compiling Kernel from Kernel.org...Howto...and some questions

**URL:** <https://forum.systemcrafters.net/t/compiling-kernel-from-kernel-org-howto-and-some-questions/1473>\
**Category:** Guix\
**Created:** [March 10, 2025, 10:58am UTC](https://forum.systemcrafters.net/t/compiling-kernel-from-kernel-org-howto-and-some-questions/1473 "2025-03-10T10:58:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rats](https://avatars.discourse-cdn.com/v4/letter/r/439d5e/32.png) [@Rats](https://forum.systemcrafters.net/u/Rats)\
**Post date:** [March 10, 2025, 10:58am UTC](https://forum.systemcrafters.net/t/compiling-kernel-from-kernel-org-howto-and-some-questions/1473/1 "2025-03-10T10:58:15Z")

</div>

I am trying to compile a Kernel from [Kernel.org](http://Kernel.org) on guix. I ran into several Problems when creating environment and building until it successfully built. Most of the time it was some package missing…

In hope it will be helpful for other noobs and users here what worked for me…

Goal was:

- Get the source from [kernel.org](http://kernel.org) (as example linux-6.13.6)
- create an environment
- create localmodconfig
- compile the Kernel

# 1. Download Kernel and unpack it

```auto
wget https://cdn.kernel.org/pub/linux/kernel/v6.x/linux-6.13.6.tar.xz
tar xvf linux-6.13.6.tar.xz
cd linux-6.13.6

```

# 2 extract config of current running kernel

```auto
zcat /proc/config.gz > .config

```

# 3. Create environment

```auto
guix environment --pure --ad-hoc gcc-toolchain make glibc bash coreutils bc flex bison openssl perl sed grep gawk findutils diffutils util-linux ncurses elfutils zlib python pkg-config kmod gzip gmp mpc

```

Propmpt `[env]$` shows that environment is entered or active

# 4. clean up, create headers then get running Kernel config from proc

```auto
# clean clean clean
make clean

# generate headers, scripts and whatever(dependencies???)
make prepare

# get current running Kernel config from "/proc"
zcat /proc/config.gz > .config

```

# 5. make localmodconfig

confirm by pressing return to all questions to accept defaults or read through the Questions and answer them one by one…

```auto
make localmodconfig

```

# 6. compile Kernel

```auto
# make make make 
make -j$(nproc)

# or make make make and log it....
make -j$(nproc) > build.log 2>&1

```

When you run `make -j$(nproc)`, it builts the kernel image (e.g., vmlinuz or bzImage) and, if your `.config` includes any options set to `=m` (module), it also compiles the corresponding .ko module files. These are typically placed in the modules directory of your kernel build output.

To check:

```auto
find . -name "*.ko"

```

So if i see it right there is no need to make modules.

~~"# My Question: "~~  
~~“- What about installing modules and using the Kernel? Do i have to think of any Guix specific stuff or can i simply do `make modules_install` ?”~~

# config system with the new Kernel:

# 1 Created 2 modules

- my-custom-firmware

```auto
(define my-custom-firmware
  (package
    (name "my-custom-firmware")
    (version "2025.03.10")
    (source (local-file "/home/support/firmware-minimal" #:recursive? #t))
    (build-system trivial-build-system)
    (arguments
     `(#:modules ((guix build utils))
       #:builder
       (begin
         (use-modules (guix build utils))
         (let* ((source (assoc-ref %build-inputs "source"))
                (output (assoc-ref %outputs "out"))
                (firmware-dir (string-append output "/lib/firmware")))
           (mkdir-p firmware-dir)
           (copy-recursively source firmware-dir)
           #t))))
    (synopsis "Custom firmware for my kernel")
    (description "Firmware files required for hardware support with my custom Linux kernel.")
    (home-page "https://kernel.org")
    (license (list gpl2))))

```

- my-custom-kernel

```auto
(define my-custom-kernel
  (package
    (name "my-custom-kernel")
    (version "6.13.6")
    (source (local-file "/home/support/kernel-6.13.6-staging" #:recursive? #t))
    (build-system trivial-build-system)
    (arguments
     `(#:modules ((guix build utils))
       #:builder
       (begin
         (use-modules (guix build utils))
         (let* ((source (assoc-ref %build-inputs "source"))
                (output (assoc-ref %outputs "out"))
                (kernel-root (string-append output "/bzImage"))
                (kernel-boot (string-append output "/boot/bzImage"))
                (system-map-root (string-append output "/System.map"))
                (system-map-boot (string-append output "/boot/System.map"))
                (modules (string-append output "/lib/modules/6.13.6")))
           (mkdir-p (dirname kernel-boot))
           (copy-file (string-append source "/boot/bzImage") kernel-root)
           (copy-file (string-append source "/boot/bzImage") kernel-boot)
           (copy-file (string-append source "/boot/System.map") system-map-root)
           (copy-file (string-append source "/boot/System.map") system-map-boot)
           (mkdir-p modules)
           (copy-recursively (string-append source "/lib/modules/6.13.6") modules)
           #t))))
    (synopsis "Custom-built Linux kernel 6.13.6")
    (description "A custom Linux kernel compiled from source with specific module configurations for testing on Guix System.")
    (home-page "https://kernel.org")
    (license gpl2)))

```

- adapted operating system part to include both

```auto

  (kernel my-custom-kernel)
  (initrd-modules (append (list "ahci" "btrfs" "virtio_blk" "virtio_pci" 
"dm_crypt" "iwlwifi")
                          %base-initrd-modules))
  (firmware (list my-custom-firmware))

```

\*\*Catastropic! \*\*  
**I ran into so many errors…unbelievable…**

I carried out `make modules_install` but this installed into `/lib/modules/6.13.6` which siomehow did not work. Somehow reconfigure did not work so i started copying files like crazy. What i first thought would do the trick is …

```auto
mkdir -p /home/support/to-delete-minimal-kernel-localmodconfig-test/linux-6.13.6/lib/modules/
cp -r /lib/modules/6.13.6 /home/support/to-delete-minimal-kernel-localmodconfig-test/linux-6.13.6/lib/modules/

```

…but no…error message was something along the line of `'guix build: error: fport_write: Connection reset by peer` and really annoying…

at some point i doubted if guix is able to deal with the large folder so i assembled a small one with bzimage system-map and the modules… no idea why that worked… i think the config looks so wrong…

```auto
mkdir -p /home/support/kernel-6.13.6-staging/boot /home/support/kernel-6.13.6-staging/lib/modules
cp /home/support/to-delete-minimal-kernel-localmodconfig-test/linux-6.13.6/arch/x86/boot/bzImage /home/support/kernel-6.13.6-staging/boot/
cp /home/support/to-delete-minimal-kernel-localmodconfig-test/linux-6.13.6/System.map /home/support/kernel-6.13.6-staging/boot/
cp -r /home/support/to-delete-minimal-kernel-localmodconfig-test/linux-6.13.6/lib/modules/6.13.6 /home/support/kernel-6.13.6-staging/lib/modules/

```

Some depmods errors like this one:

```auto
depmod: FATAL: could not load /gnu/store/95mh207pm5n5jijg7plpm7nghjsfyfah-linux-module-database/System.map: No such file or directory
Backtrace:
           2 (primitive-load "/gnu/store/dfjk2pbj5y16hi8pywchw2hyzfz?")
In ice-9/eval.scm:
    619:8 1 (_ #(#(#(#(#(#(#(#(#(#<direc?> ?) ?) ?) ?) ?) ?) ?) ?) ?))
In guix/build/utils.scm:
    822:6 0 (invoke "depmod" "-e" "-b" "/gnu/store/95mh207pm5n5jij?" ?)
guix/build/utils.scm:822:6: In procedure invoke:
ERROR:
  1. &invoke-error:
      program: "depmod"
      arguments: ("-e" "-b" "/gnu/store/95mh207pm5n5jijg7plpm7nghjsfyfah-linux-module-database" "-F" "/gnu/store/95mh207pm5n5jijg7plpm7nghjsfyfah-linux-module-database/System.map" "6.13.6")
      exit-status: 1

```

later and it suddenly guix system reconfigure was successfull…  
Reboot failed. Grub could not find bzImage so i adapted my-custom-kernel with:

```auto
           (copy-file (string-append source "/boot/bzImage") kernel-root)
           (copy-file (string-append source "/boot/bzImage") kernel-boot)
           (copy-file (string-append source "/boot/System.map") system-map-root)
           (copy-file (string-append source "/boot/System.map") system-map-boot)

```

Reboot worked… I have the feeling i did everything wrong…simply because it took so long and i went into error loops so often…

What really helped was getting the module into seperate files(kernel-test.scm and firmware-test.scm) and build (guix build -f scm-file.scm)these until they did not show an error anymore. that did not make reconfigure work out of the box but gave a good feeling…

Hope it helps someone just in case…

---

<div class="post-metadata">

**Author:** ![Trisk3lion](https://avatars.discourse-cdn.com/v4/letter/t/9e8a1a/32.png) [@Trisk3lion](https://forum.systemcrafters.net/u/Trisk3lion)\
**Post date:** [March 22, 2025, 1:02pm UTC](https://forum.systemcrafters.net/t/compiling-kernel-from-kernel-org-howto-and-some-questions/1473/2 "2025-03-22T13:02:47Z")

</div>

Interesting, and good work getting to end!

But did you take a look at the package gnu/packages/linux.scm?  
It exposes a procedure called `customize-linux` which could maybe help you a bit.

I have used to customize config flags for the kernel but you can specify source as well.
