BUILD LINUX KERNEL
2015
Based on EPFL assignment
SinhVienZone.com
/>
2
Prepare for disaster!
SinhVienZone.com
/>
Ubuntu 12.04 in Virtual Box
3
/>Note:
Hard drive: 20GB
Ubuntu 64bit
SinhVienZone.com
/>
4
Compile Kernel, the Ubuntu ways
SinhVienZone.com
/>
Videos
5
/> />
SinhVienZone.com
/>
Tools & source code
6
$sudo apt-get install dpkg-dev git
$sudo apt-get build-dep linux-image-$(uname -r)
$git clone git://kernel.ubuntu.com/ubuntu/ubuntuprecise.git
Other options:
Down
load code from kernel.org
Use apt-get
SinhVienZone.com
/>
Verify and checkout
7
$cd ubuntu-precise
$git tag -l Ubuntu-lts-3.11*
$git checkout -b os_assignment_1 Ubuntu-lts-3.11.015.25
SinhVienZone.com
/>
Complie
8
$sudo apt-get install fakeroot
$sudo fakeroot debian/rules clean
$sudo fakeroot debian/rules binary-headers binarygeneric
SinhVienZone.com
/>
Tips on recompile process
9
$sudo apt-get install ccache
$vi ~/.bashrc
+export CCACHE_DIR="<your home directory>/.ccache"
+export CC="ccache gcc“
+export CXX="ccache g++"
+export PATH="/usr/lib/ccache:$PATH"
$source ~/.bashrc
$ccache -M 4G
SinhVienZone.com
/>
Voilà
10
$ls ../*.deb
../linux-headers-3.11.0-15-generic_3.11.015.25~precise1_amd64.deb
../linux-image-3.11.0-15-generic_3.11.015.25~precise1_amd64.deb
../linux-tools-3.11.0-15-generic_3.11.015.25~precise1_amd64.deb
SinhVienZone.com
/>
Instal headers
11
../linux-headers-3.11.0-15_3.11.015.25~precise1_all.deb
$sudo apt-get install linux-lts-saucy-tools-3.11.0-15
SinhVienZone.com
/>
Load new kernel
12
$sudo dpkg -i *.deb
$sudo reboot
SinhVienZone.com
/>
Verify
13
$uname -a
SinhVienZone.com
/>
14
Compile kernel, geeky ways
SinhVienZone.com
/>
Get kernel source
15
$uname –a
$wget />$tar xjvf 3.11.5.tar.xz
SinhVienZone.com
/>
Config
16
$sudo apt-get install ncurses-dev
Ncurse: toolkit for developing "GUI-like" application software that
runs under a terminal emulator.
$sudo make menuconfig
(Use old config: sudo make oldconfig)
SinhVienZone.com
/>
Make
17
$sudo make
$sudo make modules_install install
SinhVienZone.com
/>
Install
18
#make install
Result in /boot
System.map-…
config-…
vmlinuz-…
SinhVienZone.com
/>
initrd
19
“initrd images contains device driver which needed to
load rest of the operating system later on. Not all
computer requires initrd, but it is safe to create one”
# cd /boot
# mkinitrd -o initrd.img-… …
SinhVienZone.com
/>
grub
20
# vi /boot/grub/menu.lst
title
Debian GNU/Linux, kernel … Default
root
(hd0,0)
kernel
/boot/vmlinuz root=/dev/hdb1 ro
initrd
/boot/initrd.img-…
savedefault
boot
SinhVienZone.com
/>
Here it is!
21
# reboot
SinhVienZone.com
/>
22
Add system call
SinhVienZone.com
/>
Your first system call!
23
Return a system wide unique identier each time it is
called
sys_get_unique_id (int * uuid )
uuid: location to store the unique identifier after the call
return:
0 for success
(minus) error code otherwise
SinhVienZone.com
/>
System call list
24
arch/x86/syscalls/syscall_64.tbl
543
<number> <abi> <name> <entry point>
abi: 64, x32, or common
entry point: sys_
arch/x86/syscalls/syscall_32.tbl
351
SinhVienZone.com
/>
Header file
25
include/linux/syscalls.h
SinhVienZone.com
/>