annotate Linux/Kernel/debug_build.md @ 134:e965a4b3e697 default tip

backup 2023-11-14
author autobackup
date Tue, 14 Nov 2023 00:10:04 +0900
parents b6c284fd5ae4
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
e12992dca4a0 init from Growi
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 # FedoraでLinuxのkernelをdebug buildする
e12992dca4a0 init from Growi
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 - linuxをgdbでデバッグトレースしたい!!
e12992dca4a0 init from Growi
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 - ansibleがなんとあるので使うといい感じにできる
e12992dca4a0 init from Growi
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
4
e12992dca4a0 init from Growi
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 ## ansible
e12992dca4a0 init from Growi
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 - http://www.cr.ie.u-ryukyu.ac.jp/hg/Ansible/fedora_kernel_build/
e12992dca4a0 init from Growi
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
7
2
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
8 ## virshを使ったやりかた
0
e12992dca4a0 init from Growi
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 - まずdebug buildしたいfedoraのvmをつくる
2
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
10 - 大学のdalmoreサーバーでやると便利
0
e12992dca4a0 init from Growi
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 - 結構パワーが必要なので、ansibleのファイルにある通りVMの設定を書き換える
e12992dca4a0 init from Growi
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 - CPUのコア数を8コア
e12992dca4a0 init from Growi
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 - HDDの容量を30GBは確保する
e12992dca4a0 init from Growi
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 - cpuのコア数はvirshのxmlを書き換える
2
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
15 - HDDの容量は、qemu-imgでresizeしたあとに、VMにログインしてファイルシステムを拡張する
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
16 - ここまで準備が出来たら実行可能! VMのmac addressをakatsukiに登録して、別のマシンから以下のコマンドでansibleを実行する
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
17 - 実行する前にVMのipを書いたhostsファイルを用意する
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
18 - main.ymlのユーザー名を変更するなどもしておく
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
19 ```
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
20 $screen -L ansible-playbook -i hosts main.yml --ask-become-pass
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
21 ```
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
22
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
23
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
24 - 完了したらビルドしたファイルをyomitanなどに転送する
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
25 ```
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
26 ssh localhost -p 2222 -l root 'cd /usr/src/kernels ; tar czf - fedora' | dd of=fedora26-kernel.tgz
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
27 ```
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
28 - ここのlocalhostはVMのIPとかに変えておこう。あとユーザーとかもそんな感じで...
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
29
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
30 ## 起動するkernelを切り替える
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
31 - ansibleをかけただけでは、VMが起動するkernelが切り替わってないので切り替える必要がある
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
32 - ちまたでは`awk`を使って番号を決めて`grub2-`で解決する方法が出回っている
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
33 - 最近のFedoraでは `grub2.config`をいくらgrepしてもkernel情報が乗ってない
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
34 - 最近のfedoraでは次の通りにする
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
35
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
36 ### kernelの変更
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
37 - `$ grubby --info=ALL` を実行して、切り替えたいkernelを探す
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
38 - `$grubby --set-default /boot/vmlinuz-4.2.0-1.fc23.x86_64`で切り替える
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
39
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
40 ### 参考
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
41 - [Working with the GRUB 2 Boot Loader](https://docs.fedoraproject.org/en-US/fedora/rawhide/system-administrators-guide/kernel-module-driver-configuration/Working_with_the_GRUB_2_Boot_Loader/)
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
42
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
43
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
44
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
45 ## gdbでdebugするには(学内限定)
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
46 1. debugしたいvmを`ie-virsh define-gdb`でdefineしなおす
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
47 - すでにdefineしていたらundefineする
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
48 - gdbのportが開放されたxmlファイルが生成される
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
49 2. `ie-virsh dumpxml 04(defineした番号)`で、gdbのportを確認する
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
50 3. `ie-virsh strart 04`して起動する
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
51 4. kernelから転送したvmlinuxをgdbで `gdb vmlinux`する
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
52 5. breakpointを設定する
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
53 6. `target remote localhost:(確認したport)`にするとVMに接続される
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
54 7. `c`してあとは自由に!!
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
55
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
56 # Tips
b6c284fd5ae4 backup 2020-12-16
autobackup
parents: 0
diff changeset
57 - dalmoreのvirshのxmlを書き換えるにはroot権限が必要