Sharing

2012年3月7日 星期三

Build Linux Kernel 3.2


為了解掉一些問題, 不得不把 kernel 升級到 3.2, 參考了同事的作法及網路上的作法, 下面是我的紀錄
http://blog.avirtualhome.com/2012/01/13/compile-linux-kernel-3-2-for-ubuntu-11-10/

wistor@wistor-003:~/KernelBuild$ sudo apt-get install fakeroot build-essential
wistor@wistor-003:~/KernelBuild$ sudo apt-get install crash kexec-tools makedumpfile kernel-wedge
wistor@wistor-003:~/KernelBuild$ sudo apt-get build-dep linux-image-$(uname -r)
wistor@wistor-003:~/KernelBuild$ sudo apt-get install git libncurses5 libncurses5-dev libnewt-dev
wistor@wistor-003:~/KernelBuild$ sudo apt-get install python-dev
wistor@wistor-003:~/KernelBuild$ git clone git://kernel.ubuntu.com/ubuntu/ubuntu-precise.git kernel-3.2
wistor@wistor-003:~/KernelBuild$ cd kernel-3.2
wistor@wistor-003:~/KernelBuild/kernel-3.2$ git tag | grep Ubu | sort -V
wistor@wistor-003:~/KernelBuild/kernel-3.2$ git checkout Ubuntu-3.2.0-18.28 -b wistor-3.2.0-18.28


需要使用 kdump 及 scst, 所以參考這兩份來打 patch 及做開關 option 的動作

http://www.mjmwired.net/kernel/Documentation/kdump/
http://iscsi-scst.sourceforge.net/SCST_Gentoo_HOWTO.txt

flavour 的名字千萬不要有 "-" 或是 "." 都會造成最後會有 error, 如果看到類似以下的問題, 就是這個原因
dh_installdeb: package linux-image-3.2.0-18-wistor-3.2 is not in control info
dh_installdeb: package linux-image-3.2.0-18-wistor-3.2 is not in control info

wistor@wistor-003:~/KernelBuild/kernel-3.2$ cp debian.master/config/amd64/config.flavour.generic debian.master/config/amd64/config.flavour.wistor32
wistor@wistor-003:~/KernelBuild/kernel-3.2$ patch -p1 < ../../put_page_callback-3.2.patch
patching file include/linux/mm_types.h
patching file include/linux/net.h
patching file include/linux/skbuff.h
patching file net/Kconfig
patching file net/core/skbuff.c
patching file net/ipv4/Makefile
patching file net/ipv4/ip_output.c
patching file net/ipv4/tcp.c
patching file net/ipv4/tcp_zero_copy.c
wistor@wistor-003:~/KernelBuild/kernel-3.2$ patch -p1 < ../../scst_exec_req_fifo-3.2.patch
patching file block/blk-map.c
patching file include/linux/blkdev.h
Hunk #2 succeeded at 721 (offset 3 lines).
patching file include/linux/scatterlist.h
patching file lib/scatterlist.c

wistor@wistor-003:~/KernelBuild/kernel-3.2$ fakeroot debian/rules clean

wistor@wistor-003:~/KernelBuild/kernel-3.2$ debian/rules updateconfigs
# 中間會問一堆是否要新增這個選項, 是  scst 加入的
TCP/IP networking (INET) [Y/n/?] y
  TCP/IP zero-copy transfer completion notification (TCP_ZERO_COPY_TRANSFER_COMPLETION_NOTIFICATION) [N/y/?] (NEW) y
wistor@wistor-003:~/KernelBuild/kernel-3.2$ debian/rules editconfigs
check-config: /tmp/tmp.utIyJbU3V6/CONFIGS/amd64-config.flavour.wistor32: loading config
check-config: /home/wistor/KernelBuild/kernel-3.2/debian.master/config/enforce: loading checks
# 如果 Dependency 沒有問題的話, 應該要有一行這個
check-config: 41/41 checks passed -- exit 0
# 如果要調整 CONFIG Option 就執行這個
wistor@wistor-003:~/KernelBuild/kernel-3.2$ debian/rules editconfigs
Config 做好之後, 把做的東西先備份起來, 然後把 kernel build 的東西都準備好
wistor@wistor-003:~/KernelBuild/kernel-3.2$ cp debian.master/config/amd64/config.flavour.wistor32 ../
wistor@wistor-003:~/KernelBuild/kernel-3.2$ cat ../config.flavour.wistor32
#
# Config options for config.flavour.wistor32 automatically generated by splitconfig.pl
#
CONFIG_DEFAULT_CFQ=y
# CONFIG_DEFAULT_DEADLINE is not set
CONFIG_DEFAULT_IOSCHED="cfq"
CONFIG_INTEL_IDLE=y
# CONFIG_MUTEX_SPIN_ON_OWNER is not set
CONFIG_NR_CPUS=1
# CONFIG_PREEMPT_NONE is not set
CONFIG_PREEMPT_VOLUNTARY=y
# CONFIG_SMP is not set
CONFIG_X86_INTERNODE_CACHE_SHIFT=6

# 這兩個步驟不一定要做, 做了之後記得 patch 又要重打
wistor@wistor-003:~/KernelBuild/kernel-3.2$ git reset --hard
HEAD is now at 26e8d2b UBUNTU: Ubuntu-3.2.0-18.28
wistor@wistor-003:~/KernelBuild/kernel-3.2$ git clean -df
Removing debian.master/config/amd64/config.flavour.wistor32
Removing debian.master/control
Removing debian.master/control.stub
Removing debian.master/d-i/kernel-versions
Removing debian/changelog
Removing debian/control
Removing debian/control.stub
Removing debian/copyright
Removing net/ipv4/tcp_zero_copy.c

wistor@wistor-003:~/KernelBuild/kernel-3.2$ cp debian.master/abi/3.2.0-17.27/amd64/generic debian.master/abi/3.2.0-17.27/amd64/wistor32
wistor@wistor-003:~/KernelBuild/kernel-3.2$ cp debian.master/abi/3.2.0-17.27/amd64/generic.modules debian.master/abi/3.2.0-17.27/amd64/wistor32.modules
wistor@wistor-003:~/KernelBuild/kernel-3.2$ cp ../config.flavour.wistor32 debian.master/config/amd64/
wistor@wistor-003:~/KernelBuild/kernel-3.2$ cat debian.master/etc/getabis
repo_list=(
        "http://archive.ubuntu.com/ubuntu/pool/main/l/linux"
        "http://ports.ubuntu.com/ubuntu-ports/pool/main/l/linux"
        "http://archive.ubuntu.com/ubuntu/pool/universe/l/linux"
        "http://ports.ubuntu.com/ubuntu-ports/pool/universe/l/linux"
)

getall armel omap
getall armhf omap
# 多加一個選項
getall amd64 generic virtual wistor32
getall i386 generic generic-pae virtual

# Ports arches and flavours.
getall powerpc powerpc powerpc-smp powerpc64-smp


wistor@wistor-003:~/KernelBuild/kernel-3.2$ cat debian.master/rules.d/amd64.mk
human_arch      = 64 bit x86
build_arch      = x86_64
header_arch     = $(build_arch)
asm_link        = x86
defconfig       = defconfig
# 多加一個選項
flavours        = generic virtual wistor32
build_image     = bzImage
kernel_file     = arch/$(build_arch)/boot/bzImage
install_file    = vmlinuz
loader          = grub
no_dumpfile     = true

wistor@wistor-003:~/KernelBuild/kernel-3.2$ cp debian.master/control.d/vars.generic debian.master/control.d/vars.wistor32
wistor@wistor-003:~/KernelBuild/kernel-3.2$ cat debian.master/control.d/vars.wistor32
arch="i386 amd64"
supported="Generic"
target="Geared toward desktop and server systems."
desc="Wistron Storage Server"
bootloader="grub-pc | grub-efi-amd64 | grub-efi-ia32 | grub | lilo (>= 19.1)"
provides="kvm-api-4, redhat-cluster-modules, ivtv-modules, ndiswrapper-modules-1.9"
wistor@wistor-003:~/KernelBuild/kernel-3.2$ git add .
wistor@wistor-003:~/KernelBuild/kernel-3.2$ git commit -a -m "wistor32 modification"
[wistor32.0-18.28 719d010] wistor32 modification
 Committer: wistor 
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly:

    git config --global user.name "Your Name"
    git config --global user.email you@example.com

After doing this, you may fix the identity used for this commit with:

    git commit --amend --reset-author

 6 files changed, 15771 insertions(+), 2 deletions(-)
 create mode 100644 debian.master/abi/3.2.0-17.27/amd64/wistor32
 create mode 100644 debian.master/abi/3.2.0-17.27/amd64/wistor32.modules
 create mode 100644 debian.master/config/amd64/config.flavour.wistor32
 create mode 100644 debian.master/control.d/vars.wistor32

一切準備就緒後, 就準備進行 build kernel
wistor@wistor-003:~/KernelBuild/kernel-3.2$ git checkout -b work
Switched to a new branch 'work'
wistor@wistor-003:~/KernelBuild/kernel-3.2$ fakeroot debian/rules clean
wistor@wistor-003:~/KernelBuild/kernel-3.2$ DEB_BUILD_OPTIONS=parallel=4 skipabi=true skipmodule=true fakeroot debian/rules binary-indep
wistor@wistor-003:~/KernelBuild/kernel-3.2$ ll ../
drwxrwxr-x  4 wistor wistor     4096 2012-03-07 15:50 ./
drwxrwxr-x  3 wistor wistor     4096 2012-03-07 11:50 ../
-rw-rw-r--  1 wistor wistor      378 2012-03-07 15:28 config.flavour.wistor32
-rw-r--r--  1 wistor wistor  4567196 2012-03-07 15:50 linux-doc_3.2.0-18.28_all.deb
-rw-r--r--  1 wistor wistor 11732448 2012-03-07 15:50 linux-headers-3.2.0-18_3.2.0-18.28_all.deb
-rw-r--r--  1 wistor wistor    73134 2012-03-07 15:50 linux-source-3.2.0_3.2.0-18.28_all.deb
-rw-r--r--  1 wistor wistor   122972 2012-03-07 15:50 linux-tools-common_3.2.0-18.28_all.deb
wistor@wistor-003:~/KernelBuild/kernel-3.2$ DEB_BUILD_OPTIONS=parallel=4 skipabi=true skipmodule=true fakeroot debian/rules binary-perarch
wistor@wistor-003:~/KernelBuild/kernel-3.2$ ll ../
drwxrwxr-x  4 wistor wistor     4096 2012-03-07 15:51 ./
drwxrwxr-x  3 wistor wistor     4096 2012-03-07 11:50 ../
-rw-rw-r--  1 wistor wistor      378 2012-03-07 15:28 config.flavour.wistor32
-rw-r--r--  1 wistor wistor  4567196 2012-03-07 15:50 linux-doc_3.2.0-18.28_all.deb
-rw-r--r--  1 wistor wistor 11732448 2012-03-07 15:50 linux-headers-3.2.0-18_3.2.0-18.28_all.deb
-rw-r--r--  1 wistor wistor    73134 2012-03-07 15:50 linux-source-3.2.0_3.2.0-18.28_all.deb
-rw-r--r--  1 wistor wistor   382732 2012-03-07 15:51 linux-tools-3.2.0-18_3.2.0-18.28_amd64.deb
-rw-r--r--  1 wistor wistor   122972 2012-03-07 15:50 linux-tools-common_3.2.0-18.28_all.deb
wistor@wistor-003:~/KernelBuild/kernel-3.2$ DEB_BUILD_OPTIONS=parallel=4 skipabi=true skipmodule=true fakeroot debian/rules binary-wistor32
wistor@wistor-003:~/KernelBuild/kernel-3.2$ ll ../
drwxrwxr-x  4 wistor wistor     4096 2012-03-08 09:27 ./
drwxrwxr-x  3 wistor wistor     4096 2012-03-08 10:03 ../
-rw-r--r--  1 wistor wistor      374 2012-03-08 10:07 config.flavour.wistor32
-rw-r--r--  1 wistor wistor  4567250 2012-03-08 10:08 linux-doc_3.2.0-18.28_all.deb
-rw-r--r--  1 wistor wistor 11733116 2012-03-08 10:08 linux-headers-3.2.0-18_3.2.0-18.28_all.deb
-rw-r--r--  1 wistor wistor  1018718 2012-03-08 10:29 linux-headers-3.2.0-18-wistor32_3.2.0-18.28_amd64.deb
-rw-r--r--  1 wistor wistor 38158318 2012-03-08 10:29 linux-image-3.2.0-18-wistor32_3.2.0-18.28_amd64.deb
-rw-r--r--  1 wistor wistor    73134 2012-03-08 10:08 linux-source-3.2.0_3.2.0-18.28_all.deb
-rw-r--r--  1 wistor wistor   402534 2012-03-08 10:09 linux-tools-3.2.0-18_3.2.0-18.28_amd64.deb
-rw-r--r--  1 wistor wistor   122908 2012-03-08 10:08 linux-tools-common_3.2.0-18.28_all.deb

其中我遇到了 compile error, 原因是我把 CONFIG_SMP 關起來 error: struct cpuinfo_x86 has no member named phys_proc_id 但我也很幸運的找到解決的方法, 把某一行 code 用 compile option 包起來即可 https://lkml.org/lkml/2011/12/6/28
wistor@wistor-003:~/KernelBuild/$ sudo dpkg -i linux-tools-common_3.2.0-18.28_all.deb
wistor@wistor-003:~/KernelBuild/$ sudo dpkg -i linux-headers-3.2.0-18_3.2.0-18.28_all.deb
wistor@wistor-003:~/KernelBuild/$ sudo dpkg -i linux-headers-3.2.0-18-wistor32_3.2.0-18.28_amd64.deb linux-image-3.2.0-18-wistor32_3.2.0-18.28_amd64.deb linux-tools-3.2.0-18_3.2.0-18.28_amd64.deb
(Reading database ... 104160 files and directories currently installed.)
Preparing to replace linux-headers-3.2.0-18-wistor32 3.2.0-18.28 (using linux-headers-3.2.0-18-wistor32_3.2.0-18.28_amd64.deb) ...
Unpacking replacement linux-headers-3.2.0-18-wistor32 ...
Selecting previously deselected package linux-image-3.2.0-18-wistor32.
Unpacking linux-image-3.2.0-18-wistor32 (from linux-image-3.2.0-18-wistor32_3.2.0-18.28_amd64.deb) ...
Done.
Preparing to replace linux-tools-3.2.0-18 3.2.0-18.28 (using linux-tools-3.2.0-18_3.2.0-18.28_amd64.deb) ...
Unpacking replacement linux-tools-3.2.0-18 ...
Setting up linux-headers-3.2.0-18-wistor32 (3.2.0-18.28) ...
Setting up linux-image-3.2.0-18-wistor32 (3.2.0-18.28) ...
Running depmod.
update-initramfs: deferring update (hook will be called later)
Examining /etc/kernel/postinst.d.
run-parts: executing /etc/kernel/postinst.d/initramfs-tools 3.2.0-18-wistor32 /boot/vmlinuz-3.2.0-18-wistor32
update-initramfs: Generating /boot/initrd.img-3.2.0-18-wistor32
run-parts: executing /etc/kernel/postinst.d/zz-update-grub 3.2.0-18-wistor32 /boot/vmlinuz-3.2.0-18-wistor32
Generating grub.cfg ...
Found linux image: /boot/vmlinuz-3.2.0-18-wistor32
Found initrd image: /boot/initrd.img-3.2.0-18-wistor32
Found linux image: /boot/vmlinuz-3.0.0-15-wistor
Found initrd image: /boot/initrd.img-3.0.0-15-wistor
Found memtest86+ image: /boot/memtest86+.bin
done
Setting up linux-tools-3.2.0-18 (3.2.0-18.28) ...

wistor@wistor-003:/boot$ ll
total 43520
drwxr-xr-x  3 root root     4096 2012-03-08 11:12 ./
drwxr-xr-x 25 root root     4096 2012-03-08 11:12 ../
-rw-r--r--  1 root root   782586 2012-03-08 10:28 abi-3.2.0-18-wistor32
-rw-r--r--  1 root root   139225 2012-03-08 10:28 config-3.2.0-18-wistor32
drwxr-xr-x  3 root root    12288 2012-03-08 11:12 grub/
-rw-r--r--  1 root root 13708482 2012-03-08 11:12 initrd.img-3.2.0-18-wistor32
-rw-r--r--  1 root root   176764 2011-05-03 07:07 memtest86+.bin
-rw-r--r--  1 root root   178944 2011-05-03 07:07 memtest86+_multiboot.bin
-rw-------  1 root root  2794037 2012-03-08 10:28 System.map-3.2.0-18-wistor32
-rw-------  1 root root  4700432 2012-03-08 10:28 vmlinuz-3.2.0-18-wistor32

Reference for kdump: http://www.dedoimedo.com/computers/kdump.html

3/12 補:
http://www.ubuntuupdates.org/package/core/precise/main/base/linux-source-3.2.0
在 3.2.0-18.28 時 apparmor 有大改動, 其中拿掉了 SECURITY_APPARMOR_COMPAT_24, 這個造成安裝某些軟體時會出現 "Kernel needs AppArmor 2.4 compatibility patch." 這樣的 warning, 由於不知道會有什麼影響, 於是最後決定用 3.2.0-17.27 

沒有留言: