文章目录
ubuntu 20.04 SystemTap安装
参考链接:
https://wiki.ubuntu.com/Kernel/Systemtap
安装依赖
sudo apt-get install elfutils
sudo apt-get install libdw-dev
安装内核debug symbols(dbgsym)
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys C8CAB6595FDFF622
codename=$(lsb_release -c | awk '{print $2}')
sudo tee /etc/apt/sources.list.d/ddebs.list << EOF
deb http://ddebs.ubuntu.com/ ${codename} main restricted universe multiverse
deb http://ddebs.ubuntu.com/ ${codename}-security main restricted universe multiverse
deb http://ddebs.ubuntu.com/ ${codename}-updates main restricted universe multiverse
deb http://ddebs.ubuntu.com/ ${codename}-proposed main restricted universe multiverse
EOF
sudo apt-get update
sudo apt-get install linux-image-$(uname -r)-dbgsym
安装systemtap
这里不能用sudo apt-get install systemtap去安装, 因为这样安装的是4.2版本的, 不支持这个内核, 除非更改为其他linux内核才行
我们这里下载4.6的源码包去安装
下载地址:
https://sourceware.org/systemtap/ftp/releases/systemtap-4.6.tar.gz/
# 创建个临时目录, 并解压缩源码包
mkdir ~/tmp
cd ~/tmp
tar -vxzf systemtap-4.6.tar.gz
cd systemtap-4.6/
# 安装
./configure #运行完看看有没有报错信息, 提示缺少依赖包之类的, 前面安装了依赖, 这里一般不会再报错了
sudo make install # 等待一段时间, 安装完成再看
测试下hello world
#编写个hello world脚本 hello.stp
#! /usr/bin/env stap
probe oneshot { println("hello world") }
# 运行脚本
sudo stap hello.stp
#如果打印hello world表示安装成功
#如果提示stap-server之类的信息, 可能是UFEI secure boot引起的, 解决办法继续往后看
问题解决
可能运行hello world脚本后会提示stap-server之类的, 这个是因为secure boot启动方式, 为了安全, 需要一个stap-server来执行脚本,
官方解决方法:
sudo stap --list-servers=all
查看所有可用server, 我执行这个命令提示我这个版本不支持, 如果你也是这个问题, 就看我后面的方法
#根据上个命令的得到的服务名和端口, 来执行脚本
sudo stap --use-server=<name>:<port> hello.stp
关闭secure boot解决:
sudo mokutil --disable-validation #会提示输入密码, 这里要记住你的密码, 重启后会验证密码
reboot
提示change secure boot, 选这项
安装提示输入密码, 关闭secure boot
启动, 左上角会提示insecure boot
#再启动后, 重新执行hello.stp
sudo stap hello.stp
#打印 hello world
#安装成功