-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Build chrome os kernel and kernel modules
This page will explain howto build your own chrome os kernel and kernel modules. We are especially interested in the kernel modules as we can't use a different kernel with crouton.
When you build your own kernel modules, you also are able to build the kernel. It could be of use for chrubuntu users.
There's a git repo where the kernel sources can be found, but you have to know which branch you're on. Branches can be identified by chromeos-<version> where version is your kernel version.
On the HP chromebook 14 I have kernel 3.8.11 so I need the chromeos-3.8 branch.
To determine your kernel version you can use.
$ uname -r
Note: Older devices will use "kernel" instead of "kernel-next".
First we need some tools installed in our chroot. I did this on a precise with xfce chroot, but it should also work on others.
Note: All the shell commands on this page need to be done in the shell of your chroot if not specified otherwise.
$ sudo apt-get install git-core make kernel-package
Cloning the kernel branch chromeos-3.8 to our home folder.
$ cd ~
$ git clone https://chromium.googlesource.com/chromiumos/third_party/kernel-next -b chromeos-3.8
Before we start building we need to setup our kernel config. More info can be found on the chromium dev pages
First I had to turn off -Werror, because I got one small problem when building some wifi module. This could be a problem with the gcc compiler I used.
Just use your favorite text editor and edit "chromeos/config/base.config" in the kernel-next dir.
$ cd kernel-next
$ vi chromeos/config/base.config
Search for CONFIG_ERROR_ON_WARNING=y and make it CONFIG_ERROR_ON_WARNING=n
If you want to build extra modules that are in the kernel source, now is the time to enable them. For example say we want to build binfmt_misc.ko Search for "CONFIG_BINFMT_MISC" in chromeos/config/base.config. It should say
# CONFIG_BINFMT_MISC is not set
Change it to
CONFIG_BINFMT_MISC=m
Note: "m" stands for a separate module, if you choose "y" it will be build in the kernel. When build in the kernel, we can't use it. You will always need to choose "m" for a separate module so we can load and unload it.
Now prepare the kernel config.
Look at which flavor you need for your chromebook. We have x86_64 so we setup the config for chromeos-intel-pineview.
More info on which flavor to choose see the kernel config info site mentioned above.
$ ./chromeos/scripts/prepareconfig chromeos-intel-pineview
$ make oldconfig
If you enabled a module it can be that when running "make oldconfig" you will be asked to set additional config options needed for the module.
Most of the time it will be good to just leave them at the default. Which means just pressing enter at the input field.
Now you are all set to build the kernel and kernel modules. This is done by just typing make in the directory of your kernel source.
Note: Go get some coffee, this will take some time.
$ make
When it is finished without errors, you can list the build modules (in our case binfmt_misc.ko) with.
$ find ./ -name *.ko|grep binfmt
./fs/binfmt_misc.ko
Note: This step is only needed when you want to install the modules in /lib/modules. If not then you can skip this and go to the next.
We need to unmount /lib/modules which is bind mounted in enter-chroot.
This can be done in rc.local.
Create the following /etc/rc.local or add this to your /etc/rc.local if you already have one.
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
# unmount bindmounts /lib/modules from enter-chroot
for m in `cat /proc/mounts | /usr/bin/cut -d ' ' -f2 | grep /lib/modules| grep -v "^/$" `; do
umount "$m"
done
echo 0
Also be sure to change the execution bit
$ sudo chmod +x /etc/rc.local
You can now logout and login again in your chroot to see if the script rc.local works.
If all is well, everything in /lib/modules is unmounted.
You can check this with the following.
$ cat /proc/mounts | grep /lib/modules
$ sudo make modules_install
$ sudo depmod -a
This will install all modules in INSTALL_MOD_PATH which is by default /lib/modules/<kernel version> in our case /lib/modules/3.8.11.
When you want to install it in a different path, to copy it to another chroot then change the INSTALL_MOD_PATH variable as follows.
As an example we use "tmp" directory in our kernel source directory.
$ export INSTALL_MOD_PATH="./tmp"
$ make modules_install
To be able to load modules we need to disable module_locking. This can be done by writing to the sysfs path.
$ sudo chmod 0666 /sys/module/lsm/parameters/module_locking
$ echo 0 > /sys/module/lsm/parameters/module_locking
You can enable it again after you loaded the module. It is not needed to be disabled for unloading modules.
$ echo 1 > /sys/module/lsm/parameters/module_locking
$ sudo chmod 0400 /sys/module/lsm/parameters/module_locking