Solved How to package compiled kernel

I compile and install my own kernel (mostly because my hardware isn't supported yet, so I add my product IDs).

How can I package that compiled kernel neatly into a nice package so I can unpack it and install it on another machine? I need this because the other machine also needs custom hardware IDs and is much slower for compilation that my 8-core laptop.

I glanced at the release(7) manpage, but I'm not sure that is what I need even? Is there like a simple make target to create a package that will just simply replicate what make installkernel does on the machine where it's compiled? I don't think we'd need a .pkg for this, or ...?
 
I've not experienced in this (just going to try it) but found these in build(7):
Code:
     distributekernel  Install the kernel to the directory
                       ${DISTDIR}/kernel/boot/kernel.  This target is used
                       while building a release; see release(7).
     packagekernel     Archive the results of distributekernel, placing the
                       results in DISTDIR.  This target is used while building
                       a release; see release(7).
 
It packaged both kernel and debug version into .txz files. I first did buildkernel, then distributekernel which in turn created /kernel directory in my root fs / (i don't know if it's necessary, try ignoring it) and lastly packagekernel.

Code:
root@freebsd:/usr/src # ls -lahi /kernel*
1685663 -rw-r--r--  1 root wheel  108M Dec 28 20:43 /kernel-dbg.txz
1685541 -rw-r--r--  1 root wheel   47M Dec 28 20:42 /kernel.txz

/kernel:
total 20
1682880 drwxr-xr-x   4 root wheel    4B Dec 28 20:41 .
     34 drwxr-xr-x  23 root wheel   30B Dec 28 20:42 ..
1683002 drwxr-xr-x   3 root wheel    3B Dec 28 20:41 boot
1682881 drwxr-xr-x   3 root wheel    3B Dec 28 20:41 usr

# tar -tf /kernel.txz | head -10
./
./boot/
./usr/
./usr/lib/
./usr/lib/debug/
./usr/lib/debug/boot/
./usr/lib/debug/boot/kernel/
./boot/kernel/
./boot/kernel/at45d.ko
./boot/kernel/ng_split.ko

# tar -tf /kernel-dbg.txz  | head -10
./usr/lib/debug/boot/kernel/irdma.ko.debug
./usr/lib/debug/boot/kernel/if_lio.ko.debug
./usr/lib/debug/boot/kernel/if_axp.ko.debug
./usr/lib/debug/boot/kernel/fdescfs.ko.debug
./usr/lib/debug/boot/kernel/if_rtw88.ko.debug
./usr/lib/debug/boot/kernel/uart.ko.debug
./usr/lib/debug/boot/kernel/iichid.ko.debug
./usr/lib/debug/boot/kernel/puc.ko.debug
./usr/lib/debug/boot/kernel/hv_netvsc.ko.debug
./usr/lib/debug/boot/kernel/bcma.ko.debug
 

Attachments

  • 2025-12-28-204138_1366x768_scrot.png
    2025-12-28-204138_1366x768_scrot.png
    146 KB · Views: 11
I guess that another simple way to do this would be to first buildkernel, then install KERNEL INSTKERNNAME=kernel.tmp (it will install kernel with modules into /boot/kernel.tmp instead of /boot/kernel), and then package it yourself with:
tar cJvf /tmp/kernel.txz /boot/kernel.tmp
Though of course that would be better with a make(1) target, because you potentially would need files in /usr/lib/debug/kernel if you'd like to use some debug-things, and you would need to include these in the archive too. But just as another way to do the thing :)
 
Back
Top