@@ -11,24 +11,22 @@ enhanced security support in a single command.
1111
1212## Features
1313
14- - Dockerized tool to cross-compile an hardened kernel for the Pi with a single command
15- - Hardens the Raspberry Pi Linux kernel
16- - Add Audit support
17- - Add SELinux support
14+ - Dockerized tool to cross-compile an hardened Linux kernel for the Pi
15+ - Hardens the Linux kernel by adding
16+ - Audit support
17+ - SELinux support
1818
1919## Usage
2020
21- Run the folllowing command to see the options of the builder:
21+ This command shows the options of the builder:
2222
23- ``` console
24- $ docker run --rm tschaffter/raspberry-pi-kernel-hardened
25- Cross-compiling hardened kernels for Raspberry Pi
26- Usage: build-kernel.sh [--kernel-branch <arg>] [--kernel-defconfig <arg>] [--kernel-localversion <arg>] [-h|--help]
27- --kernel-branch: Kernel branch to build (default: '')
28- --kernel-defconfig: Default kernel config to use (default: '')
29- --kernel-localversion: Kernel local version (default: '')
30- -h, --help: Prints help
31- ```
23+ $ docker run --rm tschaffter/raspberry-pi-kernel-hardened
24+ Cross-compiling hardened kernels for Raspberry Pi
25+ Usage: build-kernel.sh [--kernel-branch <arg>] [--kernel-defconfig <arg>] [--kernel-localversion <arg>] [-h|--help]
26+ --kernel-branch: Kernel branch to build (default: '')
27+ --kernel-defconfig: Default kernel config to use (default: '')
28+ --kernel-localversion: Kernel local version (default: '')
29+ -h, --help: Prints help
3230
3331## Build the hardened kernel
3432
@@ -45,100 +43,97 @@ Examples:
4543### Identify the default configuration to use
4644
4745Go to the page [ Kernel building] [ raspberrypi_kernel_build ] of the Raspberry Pi
48- website to identify the default build configuration to use for the target Pi.
46+ website to identify the configuration to apply for your Pi.
4947
5048Examples:
5149
5250- ` bcmrpi_defconfig ` for Raspberry Pi 1, Pi Zero, Pi Zero W, and Compute Module
5351- ` bcm2709_defconfig ` for Raspberry Pi 2, Pi 3, Pi 3+, and Compute Module 3
5452- ` bcm2711_defconfig ` for Raspberry Pi 4
5553
56- Check the above documentation to make sure that these examples are up-to-date.
54+ Please visit the above page to make sure that these examples are up-to-date.
5755
5856### Cross-compile the kernel
5957
60- The command below builds the branch ` rpi-5.4.y ` for the Raspberry Pi 4
61- (` bcm2711_defconfig ` ). Because this branch is in progress, we include today's
62- date to the value of ` --kernel-localversion ` (` 5.4.y-20200804-hardened ` ). You
63- can set the value of ` --kernel-localversion ` to anything you want.
64-
65- Once installed, the full kernel name will be:
66-
67- ``` console
68- $ uname -a
69- Linux raspberrypi 5.4.51-5.4.y-20200804-hardened+ #1 SMP Sun Jun 14 15:06:51 UTC 2020 armv7l GNU/Linux
70- ```
71-
72- This command builds kernel:
73-
74- ``` console
75- $ docker run \
76- --rm \
77- -v $PWD/output:/output \
78- tschaffter/raspberry-pi-kernel-hardened \
79- --kernel-branch rpi-5.4.y \
80- --kernel-defconfig bcm2711_defconfig \
81- --kernel-localversion 5.4.y-$(date '+%Y%m%d')-hardened
82- Cloning into '/home/builder/tools'...
83- Installing cross compiler toolchain
84- Checking out files: 100% (19059/19059), done.
85- Getting kernel source code
86- Cloning into '/home/builder/linux'...
87- ...
88-
89- Moving .deb packages to /output
90- SUCCESS The kernel has been successfully packaged.
91-
92- INSTALL
93- sudo dpkg -i linux-*-5.4.y-20200804-hardened*.deb
94- sudo sh -c "echo 'kernel=vmlinuz-5.4.51-5.4.y-20200804-hardened+' >> /boot/config.txt"
95- sudo reboot
96-
97- ENABLE SELinux
98- sudo apt-get install selinux-basics selinux-policy-default auditd
99- sudo sh -c "sed -i '$ s/$/ selinux=1 security=selinux/' /boot/cmdline.txt"
100- sudo touch /.autorelabel
101- sudo reboot
102- sestatus
103- ```
58+ Below is a command that build the branch ` rpi-5.4.y ` for the Raspberry Pi 4
59+ (` bcm2711_defconfig ` ). Because this branch is still in development, we recommand
60+ to include today's date to the value of ` --kernel-localversion ` . The value of
61+ ` --kernel-localversion ` can be set to anything you want.
62+
63+ $ mkdir -p output && docker run \
64+ --rm \
65+ -v $PWD/output:/output \
66+ tschaffter/raspberry-pi-kernel-hardened \
67+ --kernel-branch rpi-5.4.y \
68+ --kernel-defconfig bcm2711_defconfig \
69+ --kernel-localversion $(date '+%Y%m%d')-hardened
70+ Cloning into '/home/builder/tools'...
71+ Installing cross compiler toolchain
72+ Checking out files: 100% (19059/19059), done.
73+ Getting kernel source code
74+ Cloning into '/home/builder/linux'...
75+ ...
76+
77+ Moving .deb packages to /output
78+ SUCCESS The kernel has been successfully packaged.
79+
80+ INSTALL
81+ sudo dpkg -i linux-*-5.4.y-20200804-hardened*.deb
82+ sudo sh -c "echo 'kernel=vmlinuz-5.4.51-20200804-hardened+' >> /boot/config.txt"
83+ sudo reboot
84+
85+ ENABLE SELinux
86+ sudo apt-get install selinux-basics selinux-policy-default auditd
87+ sudo sh -c "sed -i '$ s/$/ selinux=1 security=selinux/' /boot/cmdline.txt"
88+ sudo touch /.autorelabel
89+ sudo reboot
90+ sestatus
91+
92+ After installing the above kernel, its name will be:
93+
94+ $ uname -a
95+ Linux raspberrypi 5.4.51-20200804-hardened+ #1 SMP Sun Jun 14 15:06:51 UTC 2020 armv7l GNU/Linux
96+
97+ ** Note:** The builder inside the docker container runs as a non-root user. The command
98+ ` mkdir output ` included in the above command ensures that the builder will be able
99+ to save the output kernel files to the output folder.
104100
105101## Install the kernel
106102
107- Copy the Debian packages ` $PWD/output/ *.deb` to the target Raspbery Pi, for
108- example using ` scp ` , then follow the instructions given at the end of the build
109- command .
103+ Copy the Debian packages ` *.deb ` generated to the target Raspbery Pi, for example
104+ using ` scp ` . Then follow the instructions given at the end of the command used to
105+ build the kernel (see above) .
110106
111107## Update the kernel
112108
113109Repeat the same protocol as given above to build and install a newer version of
114- the kernel. After installing the ` *.deb ` packages with ` dpkg ` , you only have to
115- update ` /boot/config.txt ` so that the new kernel is loaded at boot.
110+ the kernel. The only difference is that after installing the ` *.deb ` packages
111+ with ` dpkg ` , you only have to update ` /boot/config.txt ` so that the new kernel
112+ is loaded at boot.
116113
117- ## Customize your build
114+ ## Customize the build
118115
119116- The builder uses all the CPU cores available to the Docker container. By default,
120117that is all the CPU cores of the host. Use [ Docker runtime options] [ docker_runtime_options ]
121118to limit the usage of CPU cores by the builder.
122119
123- - The builder clones two GitHub repositories, the cross-compiler toolchain and
120+ - The builder clones two GitHub repositories: the cross-compiler toolchain and
124121the source code of the kernel, unless their target directories already exist
125122(` /home/builder/tools ` and ` /home/builder/linux ` ). When running the dockerized
126- builder, you can mount volumes that points to these two directories to specify
127- a different toolchain and kernel source code.
128-
129- ``` console
130- $ git clone < toolchain-repo> tools
131- $ git clone < kernel-repo> linux
132- $ docker run \
133- --rm \
134- -v $PWD/output:/output \
135- -v $PWD/tools:/home/builder/tools \
136- -v $PWD/linux:/home/builder/linux \
137- tschaffter/raspberry-pi-kernel-hardened \
138- --kernel-branch rpi-5.4.y \
139- --kernel-defconfig bcm2711_defconfig \
140- --kernel-localversion 5.4.y-$(date '+%Y%m%d')-hardened
141- ```
123+ builder, you can specify a different toolchain and kernel source code by mounting
124+ volumes that points to these two directories. For example,
125+
126+ $ git clone <toolchain-repo> tools
127+ $ git clone <kernel-repo> linux
128+ $ mkdir -p output && docker run \
129+ --rm \
130+ -v $PWD/output:/output \
131+ -v $PWD/tools:/home/builder/tools \
132+ -v $PWD/linux:/home/builder/linux \
133+ tschaffter/raspberry-pi-kernel-hardened \
134+ --kernel-branch rpi-5.4.y \
135+ --kernel-defconfig bcm2711_defconfig \
136+ --kernel-localversion $(date '+%Y%m%d')-hardened
142137
143138## Contributing change
144139
0 commit comments