dushenda

李德胜大大粉丝

dushenda

编译内核

下载

kernel:https://mirrors.edge.kernel.org/pub/linux/kernel/

镜像:https://mirrors.ustc.edu.cn/kernel.org/linux/kernel/

编译

1
2
root@dushenda:/home/dsd/Code/linux-5.18.10# make menuconfig
root@dushenda:/home/dsd/Code/linux-5.18.10# make -j`nproc`

编译完成得到

制作initramfs

使用busybox

1
2
3
root@dushenda:/home/dsd/Code/busybox-1.36.1# make menuconfig
root@dushenda:/home/dsd/Code/busybox-1.36.1# make -j`nproc`
root@dushenda:/home/dsd/Code/busybox-1.36.1# make install

编译完成得到 制作initramfs.img,首先构造如下的目录结构 init文件内容如下:

1
root@dushenda:/home/dsd/Code/initramfs_dir# find . -print0 | cpio -ov --null --format=newc | gzip -9 > ../initramfs.img
最后生成文件 qemu运行新内核
1
2
3
4
5
6
root@dushenda:/home/dsd/Code/initramfs_dir# qemu-system-x86_64 \  
-kernel bzImage \
-initrd initramfs.img \
-m 1G \
-nographic \
-append "earlyprintk=serial,ttyS0 console=ttyS0"
运行结果如下

注意

init需要设置为可执行权限

qemu退出快捷键ctrl+a按下后释放,再按x

安装

Ubuntu

BCC已经打包到Ubuntu的multiverse仓库,名字bpfcc-tools,使用如下命令安装

1
sudo apt-get install build-essential bpfcc-tools linux-header-$(uname -r) bpftrace

使用

funccount

stackcount

背景介绍

编译edk2代码,配置开发环境,服务器使用华为云耀云服务器,OS信息如下

特点

  • apt-get源可以访问
  • github不能访问
  • gitee可以访问

远程仓库迁移

因为编译需要clone相关仓库到指定路径,并且为了今后的同步方便,所以把github仓库迁移到gitee后再配置相关环境。配置流程如下

  1. 建立组织,用来合并仓库环境

  2. 迁移主仓库

  3. 导入submodule,因为edk2后续编译还需要一些子模块,找到如下仓库的路径,按照2导入到组织

  4. 修改主仓库的submodule路径

下载

下载edk2代码仓

1
git clone git@gitee.com:edk2_back/edk2.git
下载子模块到对应路径,可以看到地址都替换了gitee路径
1
git submodule update --init

编译工具链安装

1
2
3
4
5
-> # apt-get install build-essential uuid-dev iasl git gcc nasm python3

-> # python3 --version
Python 3.10.12
-> # ln -s /usr/bin/python3.10 /usr/bin/python

编译

基本工具

看一下当前的目录结构,使用make -C BaseTools编译基本工具

1
2
3
4
5
6
7
8
9
-> # ls
ArmPkg CryptoPkg FatPkg Maintainers.txt pip-requirements.txt SignedCapsulePkg
ArmPlatformPkg DynamicTablesPkg FmpDevicePkg MdeModulePkg PrmPkg SourceLevelDebugPkg
ArmVirtPkg edksetup.bat IntelFsp2Pkg MdePkg ReadMe.rst StandaloneMmPkg
BaseTools edksetup.sh IntelFsp2WrapperPkg NetworkPkg RedfishPkg UefiCpuPkg
Conf EmbeddedPkg License-History.txt OvmfPkg SecurityPkg UefiPayloadPkg
CONTRIBUTING.md EmulatorPkg License.txt PcAtChipsetPkg ShellPkg UnitTestFrameworkPkg

-> # make -C BaseTools
编译基本工具完成

编译目标文件

设置环境变量,path/to/edk/BaseTools需要换成当前的BaseTools所在路径。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
-> # export EDK_TOOLS_PATH=`path/to/edk/BaseTools`
-> # ./edksetup.sh --help
Usage: edksetup.sh [Options]

The system environment variable, WORKSPACE, is always set to the current
working directory.

Options:
--help, -h, -? Print this help screen and exit.

--reconfig Overwrite the WORKSPACE/Conf/*.txt files with the
template files from the BaseTools/Conf directory.

Please note: This script must be 'sourced' so the environment can be changed.
. edksetup.sh
source edksetup.sh
-> # source edksetup.sh BaseTools
edk目录下使用build命令编译
1
-> # build

Linux

通过文件系统

rotational为1代表可以旋转,为hdd,为0代表不能旋转,为ssd

查看位置在/sys/block/sd*/queue/rotational

1
2
3
4
[root@dushenda home]# grep ^ /sys/block/sd*/queue/rotational  
/sys/block/sda/queue/rotational:1
/sys/block/sdb/queue/rotational:1
/sys/block/sdc/queue/rotational:1

lsblk

1
2
3
4
5
[root@dushenda home]# lsblk -o name,rota,VENDOR  
NAME ROTA VENDOR
sda 1 Msft
sdb 1 Msft
sdc 1 Msft

lsblk可选行信息如下等,通过lsblk --help查看

smartctl

该工具需要自行安装Ubuntu和CentOS安装包名称均为smartmontools

1
2
3
4
5
6
7
8
9
10
11
12
13
[root@dushenda home]# smartctl -a /dev/sdc  
smartctl 7.1 2019-12-30 r5022 [x86_64-linux-5.15.133.1-microsoft-standard-WSL2] (local build)
Copyright (C) 2002-19, Bruce Allen, Christian Franke, www.smartmontools.org

=== START OF INFORMATION SECTION ===
Vendor: Msft
Product: Virtual Disk
Revision: 1.0
Compliance: SPC-3
User Capacity: 1,099,511,627,776 bytes [1.09 TB]
Logical block size: 512 bytes
Physical block size: 4096 bytes
LU is thin provisioned, LBPRZ=0

Windows

powershell

1
2
3
4
5
6
(base) PS C:\Users\dushenda> Get-PhysicalDisk

Number FriendlyName SerialNumber MediaType CanPool OperationalStatus HealthStatus Usage Size
------ ------------ ------------ --------- ------- ----------------- ------------ ----- ----
1 Samsung SSD 860 EVO M.2 500GB S414NB0K722943N SSD False OK Healthy Auto-Select 465.76 GB
0 WDC WD10SPCX-24HWST1 WD-WXB1AC41L2P1 HDD False OK Healthy Auto-Select 931.51 GB

GUI

在任务管理器下查看

协议流程

仿真

组网

路由设置

1
2
3
4
5
6
7
8
9
10
11
<Huawei>sys
[Huawei]sysname AR1
[AR1]int g0/0/0
[AR1-GigabitEthernet0/0/0]ip adderss 1.1.1.200 24
[AR1]dhcp enable
[AR1]ip pool ip_pool1
[AR1-ip-pool-ip_pool1]network 1.1.1.0 24
[AR1-ip-pool-ip_pool1]gateway-list 1.1.1.200
[AR1-ip-pool-ip_pool1]lease day 3
[AR1]int g0/0/0
[AR1-GigabitEthernet0/0/0]dhcp select global

抓包

dhcp discover

dhcp offer

hexo配置

node.js配置

hexo主题配置

Obsidian配置

下载Obsidian Git插件,需要打开第三方插件按钮,下载插件。

在对应的.git目录下打开仓库,下图的打开本地仓库,生成本地目录。

配置Git设置地址等,这样就可以调用后台的git自动推送了

需要注意的是:git需要首先被安装,并且配置到环境变量

github配置

workflows配置

dependabot配置

malloc: http://blog.codinglabs.org/articles/a-malloc-tutorial.html

duartes.org: http://duartes.org/gustavo/blog/archives/

github mannul: http://www.epubit.com.cn/article/844#what

liaoxuefeng.com: http://www.liaoxuefeng.com/

TCP/IP network: http://blog.packagecloud.io/eng/2016/10/11/monitoring-tuning-linux-networking-stack-receiving-data-illustrated/

netfilter.org: https://people.netfilter.org/pablo/netdev0.1/papers/

tuning-linux-sending: https://blog.packagecloud.io/eng/2017/02/06/monitoring-tuning-linux-networking-stack-sending-data/

tuning-linux-receiving: https://blog.packagecloud.io/eng/2016/06/22/monitoring-tuning-linux-networking-stack-receiving-data/

strace: https://blog.packagecloud.io/eng/2016/02/29/how-does-strace-work/

IBM-Tim: https://www.ibm.com/developerworks/cn/views/linux/libraryview.jsp?search_by=Linux+%E5%89%96%E6%9E%90

yeolar: http://www.yeolar.com/

http://www.yeolar.com/note/2012/03/29/virtual-memory/

vxlan: https://blogs.vmware.com/vsphere/2013/07/vxlan-series-how-vmotion-impacts-the-forwarding-table-part-6.html

http://www.cisco.com/c/en/us/products/collateral/switches/nexus-5000-series-switches/white-paper-c11-733618.html#_Toc439799767

http://www.cisco.com/c/en/us/products/collateral/switches/nexus-9000-series-switches/white-paper-c11-729383.html

ali-kernel: http://kernel.taobao.org/index.php?title=%E5%86%85%E6%A0%B8%E6%9C%88%E6%8A%A52017-02

linux-performance: http://www.brendangregg.com/linuxperf.html

systemTap: https://sourceware.org/systemtap/SystemTap_Beginners_Guide/

calico: http://docs.projectcalico.org/v2.0/introduction/

docker: http://www.infoq.com/cn/articles/docker-network-and-pipework-open-source-explanation-practice

Flannel: http://dockone.io/article/618

SDN: https://www.opennetworking.org/

Linux Kernel Networking: https://wiki.linuxfoundation.org/networking/start

MacVtap: https://blog.kghost.info/2013/03/27/linux-network-tun/

http://blog.csdn.net/dog250/article/details/45788279

Neutron: http://blog.csdn.net/quqi99/article/details/22853403

Linux Bridge: http://blog.csdn.net/yeasy/article/details/50728243

Docker Networking: http://edgedef.com/docker-networking.html

Tun/Tap interface: http://backreference.org/2010/03/26/tuntap-interface-tutorial/

TC ifb: http://blog.csdn.net/dog250/article/details/40680765?utm_source=tuicool&utm_medium=referral

汇编:

Ubuntu

安装crash工具

1
apt-get install linux-crashdump

检查kdump配置

1
2
3
4
5
6
7
8
9
10
11
12
13
kdump-config show

DUMP_MODE: kdump
USE_KDUMP: 1
KDUMP_COREDIR: /var/crash
crashkernel addr: 0x73000000
/var/lib/kdump/vmlinuz: symbolic link to /boot/vmlinuz-5.15.0-89-generic
kdump initrd:
/var/lib/kdump/initrd.img: symbolic link to /var/lib/kdump/initrd.img-5.15.0-89-generic
current state: ready to kdump

kexec command:
/sbin/kexec -p --command-line="BOOT_IMAGE=/boot/vmlinuz-5.15.0-89-generic root=UUID=92414257-97c5-46a0-9154-66c415ee7358 ro net.ifnames=0 consoleblank=600 console=tty0 console=ttyS0,115200n8 noibrs reset_devices systemd.unit=kdump-tools-dump.service nr_cpus=1 irqpoll nousb" --initrd=/var/lib/kdump/initrd.img /var/lib/kdump/vmlinuz

USE_KDUMP=1 代表kdump打开

KDUMP_COREDIR 代表生成的core文件在/var/crash下面

1
2
3
4
-> # dmesg | grep -i crash
[ 0.000000] Command line: BOOT_IMAGE=/boot/vmlinuz-5.15.0-89-generic root=UUID=92414257-97c5-46a0-9154-66c415ee7358 ro net.ifnames=0 consoleblank=600 console=tty0 console=ttyS0,115200n8 noibrs crashkernel=512M-:192M
[ 0.005698] Reserving 192MB of memory at 1840MB for crashkernel (System RAM: 2047MB)
[ 0.013125] Kernel command line: BOOT_IMAGE=/boot/vmlinuz-5.15.0-89-generic root=UUID=92414257-97c5-46a0-9154-66c415ee7358 ro net.ifnames=0 consoleblank=600 console=tty0 console=ttyS0,115200n8 noibrs crashkernel=512M-:192M

dmesg 显示了crashkernel保留了192M内存,kexec命令。

手动触发sysrq

1
2
cat /proc/sys/kernel/sysrq
echo c > /proc/sysrq-trigger
  1. sysrq值不为0代表工作正常
  2. echo写主动触发kdump

CentOS

安装crash工具

1
2
yum install kexec-tools
yum install crash

安装内核调试信息包

1
2
yum install kernel-debuginfo-$(uname -r)
yum install kernel-debuginfo-common-$(uname -r)

判断服务正常开启

1
systemctl status kdump

主动触发分析

这一步跟Ubuntu的一致

分析调试

1
crash /usr/lib/debug/lib/modules/$(uname -r)/vmlinux /var/crash/XX/vmcore

Ubuntu

设置如下的程序

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
#include <string.h>
using namespace std;

void crash_test()
{
char *str =0;
strcpy(str,"test"); // segment fault
}
int main()
{
cout << "crash test" << endl;
crash_test();
return 0;
}
以下就是生成了dump文件

查看coredump是否打开

查看命令:ulimit -c

打开命令:ulimit -c unlimited

0:关闭

unlimited:打开 ### 配置规则 主要看内核参数kernel.core_pattern,路径为/proc/sys/kernel/core_pattern

所以修改有两种方法

1、sysctl -w kernel.core_pattern=/root/core/core-%e.%s.%p.%t

2、echo -e "/root/core/core-%e.%s.%p.%t" > /proc/sys/kernel/core_pattern

%e:进程名称

%s:崩溃时收到的信号

%p:进程ID

%t:时间戳

注意关闭apport服务

这个服务会读取core文件分析,不会保存源文件

1
systemctl stop apport.service

CentOS

编辑/etc/security/limits.conf文件

末尾增加soft core unlimited,表示应用程序生成的core文件不受大小限制 ### 配置规则 和Ubuntu一样 ### reboot

分析崩溃

1
gdb test  /root/corefile/core-test.11.6284.1705062175

发现最后的出错函数位于strcpy这一处,源文件第8行。