linux下常用工具提取

  

目录

方法论

提取二进制

确认工具是否适合采用此方法

提取

下载安装包

解压安装包    

将二进制及可能的库文件拷贝出来

其他适用此方法的命令

静态编译源码

i2cdetect

源码下载

编译

FIO

源码下载

 编译

iperf

下载地址

静态编译


所谓提取,也就是不通过yum apt等安装器从安装源安装,直接运行之。

方法论

包括直接提取二进制和静态编译两种方式。根据情况采用不同的方法。

提取二进制

确认工具是否适合采用此方法

将工具通过apt安装,然后在(cat /var/log/apt/history.log 获取安装历史),

  • 例如针对FIO,我们看到FIO在安装时还额外安装了很多它的依赖包。那么此种就不适合直接提取二进制,因而在提取二进制时我们需要把他依赖的包也要全部搞一遍,非常费事。
Commandline: apt install fio
Requested-By: user (1000)
Install: libibverbs1:arm64 (28.0-1ubuntu1, automatic), libgfapi0:arm64 (7.2-2build1, automatic), 
python2.7-minimal:arm64 (2.7.18~rc1-2, automatic), libtirpc-common:arm64 (1.2.5-1, automatic),
 librbd1:arm64 (15.2.1-0ubuntu1, automatic), ibverbs-providers:arm64 (28.0-1ubuntu1, automatic), 
python2.7:arm64 (2.7.18~rc1-2, automatic), fio:arm64 (3.16-1), libgfrpc0:arm64 (7.2-2build1, automatic),
 libnuma1:arm64 (2.0.12-1, automatic), libgfxdr0:arm64 (7.2-2build1, automatic), libaio1:arm64 (0.3.112-5, automatic), 
librdmacm1:arm64 (28.0-1ubuntu1, automatic), libtirpc3:arm64 (1.2.5-1, automatic), libglusterfs0:arm64 (7.2-2build1, automatic),
libpython2.7-minimal:arm64 (2.7.18~rc1-2, automatic), libpython2.7-stdlib:arm64 (2.7.18~rc1-2, automatic), librados2:arm64 (15.2.1-0ubuntu1, automatic)
  • 例如针对lsscsi,查看他的安装历史,只安装了工具包本身,则此种工具可以直接提取
Start-Date: 2021-03-24  10:54:58
Commandline: apt-get install -y lsscsi
Install: lsscsi:arm64 (0.30-0.1)
End-Date: 2021-03-24  10:54:58

提取

   以lsscsi为例子

下载安装包

   

1)apt-cache search lsscsi (搜索包名)

lsscsi - list all SCSI devices (or hosts) currently on system
nagios-plugins-contrib - Plugins for nagios compatible monitoring systems

2)apt download lsscsi (下载包)

lsscsi_0.28-0.1_amd64.deb

解压安装包    

1) dpkg -X lsscsi_0.28-0.1_amd64.deb ./
输出信息:
./
./usr/
./usr/bin/
./usr/bin/lsscsi
./usr/share/
./usr/share/doc/
./usr/share/doc/lsscsi/
./usr/share/doc/lsscsi/AUTHORS
./usr/share/doc/lsscsi/CREDITS
./usr/share/doc/lsscsi/README
./usr/share/doc/lsscsi/changelog.Debian.gz
./usr/share/doc/lsscsi/copyright
./usr/share/man/
./usr/share/man/man8/
./usr/share/man/man8/lsscsi.8.gz

将二进制及可能的库文件拷贝出来

1)查看依赖库 ldd lsscsi
        linux-vdso.so.1 (0x00007fff9b480000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f0639e91000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f063a493000)

没有特别依赖库,直接将lsscsi拷贝出来作为以后在同种系统同CPU架构下运行的工具。

其他适用此方法的命令

1. memtester 

apt-cache search memtester
memtest86+ - thorough real-mode memory tester
memtester - Utility for testing the memory subsystem
apt download memtester

2. stress

即可以通过  apt download stress_1.0.4-2_amd64.deb 下载,也可以通过如下网址下载包然后解压

https://debian.pkgs.org/10/debian-main-amd64/stress_1.0.4-4_amd64.deb.html

3. modetest

apt download libdrm-tests

4. can

5. iperf

iperf3 依赖一个库文件,iperf则只一个可执行文件即可 

iPerf - Download iPerf3 and original iPerf pre-compiled binaries

静态编译源码

静态编译首先要知道项目源码地址

i2cdetect

源码下载

I2C Tools - Linux i2c Wiki (kernel.org)  i2c wiki

Index of /pub/software/utils/i2c-tools/ (kernel.org) 下载地址

编译

make BUILD_DYNAMIC_LIB=0 BUILD_STATIC_LIB=1

查看编译后的文件,虽然还是动态连接的文件,但是依赖的库已经为系统常规库

ldd /usr/sbin/i2cdetect
        linux-vdso.so.1 (0x0000007f97dc9000)
        libi2c.so.0 => /lib/aarch64-linux-gnu/libi2c.so.0 (0x0000007f97d57000)
        libc.so.6 => /lib/aarch64-linux-gnu/libc.so.6 (0x0000007f97be4000)
        /lib/ld-linux-aarch64.so.1 (0x0000007f97d99000)

我们对比通过apt 命令安装后的命令的动态库信息

ldd /usr/sbin/i2cdetect
        linux-vdso.so.1 (0x0000007f87c89000)
        libi2c.so.0 => not found  (此处多一个i2c的库)
        libc.so.6 => /lib/aarch64-linux-gnu/libc.so.6 (0x0000007f87ab7000)
        /lib/ld-linux-aarch64.so.1 (0x0000007f87c59000)

FIO

源码下载

此处下载和apt 安装后版本一致的fio版本。主要fio依赖多,如果不一致,导致可能在静态编译时,要重新编译他的很多依赖库。

Tags · axboe/fio · GitHub

 编译

 执行下面命令后,就可以在install目录下生成静态的fio文件

./configure --build-static --prefix=./install/

make && make install

查看文件类型,可以看到已经是静态连接。

file fio

fio: ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux), statically linked, BuildID[sha1]=a375d6ce966b3ec51f1c3aa730de6633968d0f07, for GNU/Linux 3.2.0, with debug_info, not stripped

iperf

iperf 分为2和3两个版本。

为什么我们在前期已经从deb包中提取了iperf,现在还要再次重新编译。因为此工具依赖的基础包,例如glibc,在不同版本的OS中也会有差异,导致不能运行,因而需要我们做静态编译。

下载地址

iperf3 下载地址: Release 3.11 · esnet/iperf · GitHub

iperf2 下载地址: Iperf 2 - Browse Files at SourceForge.net 

静态编译

iperf3 的版本
https://github.com/esnet/iperf

./configure CFLAGS=-static --enable-static-bin


2版本:
https://sourceforge.net/projects/iperf2/

静态编译:
./configure CFLAGS=-static

笔者采用2.1.7和3.11版本可以正确编译。2.0.5的则编译不过。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

proware

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值