首页 > 代码库 > 编译zpool命令
编译zpool命令
环境:192.168.50.239(在 illumos源码中编译zpool命令)
PS:由于对zpool命令的工作原理不熟悉,所以编译,可在其中加入调试语句来明白其原理
首先介绍 illumos-soulos开发环境搭建,过程如下:
一、系统环境
PC机采用Windows系统,使用“putty.exe”工具中SSH功能
二、putty配置
1.打开putty.exe,Host Name(IP address)填入192.168.2.238
2.左侧点击SSH->Auth,在Private key file authentication中导入ddd.ppk文件
3.点击Open,连接到192.168.2.238主机上配置属于个人的开发环境
三、开发环境搭建
1.配置个人开发环境
登录到主机用户名root,在超级用户权限下执行步骤1-5
1.新建文件夹:zfs create rpool/export/home/huakai
2.添加用户名:useradd -d /export/home/huakai/ -s /bin/bash huakai
3.设置密码:passwd huakai 密码设置为1
4.修改文件夹的拥有者:chown -R huakai /export/home/huakai/
5.修改相应的配置文件,使用户名hanhua具有权限使用sudo
编辑/etc/sudoers文件,在hhk ALL=(ALL) NOPASSWD: ALL 后面添加
huakai ALL=(ALL) NOPASSWD: ALL
登录到个人用户名“huakai”, 在普通用户权限下执行步骤6-9
6.新建文件夹.ssh,用于存放密匙id_dsa
7.从代码服务器获取密匙:wget http://192.168.2.5/id_dsa
8.修改id_dsa的权限:sudo chmod 0400 id_dsa
9.从代码服务器下载源文件:
git clone soulos@192.168.2.5:~/panoview
git clone soulos@192.168.2.5:~/panoservice
git clone soulos@192.168.2.5:~/illumos-soulos
git clone soulos@192.168.2.5:~/soulos-build
2.配置illumos-soulos开发环境
1.将目录 /export/home/huakai/illumos-soulos/usr/src/tools/env下的illumos.sh文件拷贝到源文件illumos-soulos的顶层目录下,修改illumos.sh配置文件如下:
> export NIGHTLY_OPTIONS=‘-FnCDlmprt‘修改为:
< export NIGHTLY_OPTIONS=‘-nDFCmpr‘
> export CODEMGR_WS="$HOME/ws/$GATE"修改为:
< export CODEMGR_WS=/export/home/huakai/illumos-soulos
> export CLONE_WS=‘ssh://anonhg@hg.illumos.org/illumos-gate‘修改为:
< export CLONE_WS=‘soulos@192.168.2.5:~/illumos-soulos‘
> export VERSION="$GATE"修改为:
< export VERSION=‘soulos-d9579da‘
> # export PKGPUBLISHER_REDIST=‘on-redist‘修改为:
< export PKGPUBLISHER_REDIST=‘soulos‘
同时添加以下内容:
< export __GNUC=‘‘
< export __GNUC4=‘‘
< export GCC_ROOT="/opt/gcc-4.4.4"
< export CW_GCC_DIR="$GCC_ROOT/bin"
< export CW_NO_SHADOW=1
< ONNV_BUILDNUM=151007; export ONNV_BUILDNUM;
< export MULTI_PROTO=yes
< RELEASE_DATE=2013.11.19
2.将文件on-closed-bins-nd.i386.tar.bz2和on-closed-bins.i386.tar.bz2拷贝到源文件illumos-soulos的顶层目录下,并执行命令:tar xvpf on-closed-bins-nd.i386.tar.bz2和tar xvpf on-closed-bins.i386.tar.bz2
注:on-closed-*这两个文件是solaris 不开源的一部分文件,是二进制的,很多地方依赖
3.编译工具,执行命令:/opt/onbld/bin/bldenv -d illunos.sh -c “cd usr/src && dmake setup”
注:在这个命令中,dmake setup只需执行一次,/opt/onbld/bin/bldenv -d illunos.sh每次重新登录时都要执行,目的是导入环境变量
四、编译模块示例
1.编译lib中libdevinfo库模块流程
1.进入目录/export/home/huakai/illumos-soulos/usr/src/lib/libdevinfo中,执行命令dmake
2.编译该模块完成之后,如果在该目录下的amd64和i386文件夹下都会生成lint.out、libdevinfo.so.1、llib-ldevinfo.ln以及pics等文件,则说明编译模块成功。
2.编译cmd中fmadm命令模块流程
1.进入目录/export/home/huakai/illumos-soulos/usr/src/cmd/fm/fmadm中,由于编译该模块时缺少依赖的库文件,所以直接执行dmake命令不能编译成功。
2.由于在/export/home/huakai/illumos-soulos/proto/root_i386/usr/lib/fm不存在这些依赖的库文件,因此需要在/export/home/huakai/illumos-soulos/usr/src/lib/fm编译需要的模块,分别是:libfmd_adm、libfmd_msg和topo三个库模块,编译过程按照编译libdevinfo库模块流程,编译成功之后,执行命令dmake install,将生成的库文件安装到proto目录下。此时/export/home/huakai/illumos-soulos/proto/root_i386/usr/lib/fm中的文件如下所示:
3.执行命令dmake,在/export/home/huakai/illumos-soulos/usr/src/cmd/fm/fmadm/i386目录下生成fmadm可执行文件,则说明编译模块成功。
注:不要将当前开发环境上的动态库复制到proto下,有可能开发环境下的版本和源码里版本不匹配,没有特殊需要不要这样做以免引入不必要麻烦。默认情况下,proto下的文件全部使用源码生成,用dmake install命令。
3.编译i86pc中xsvc内核模块流程
1.进入目录/export/home/huakai/illumos-soulos/usr/src/uts/i86pc/xsvc下,执行命令dmake编译内核模块。
2.在当前文件夹下生成debug32和debug64两个目录,这两个目录中都包含了xsvc和xsvc.o
文件,则说明编译内核模块成功。
下面介绍 zpool 命令编译,过程如下:
1.
-bash-4.2$ /opt/onbld/bin/bldenv -d illumos.sh
Build type is DEBUG
RELEASE is
VERSION is soulos-d9579da
RELEASE_DATE is 2013.11.19
The top-level ‘setup‘ target is available to build headers and tools.
Using /bin/bash as shell.
2.
bash-4.2$ cd usr/src/cmd/zpool/
bash-4.2$ dmake
/export/home/huakai/code/illumos-soulos/usr/src/tools/proto/root_i386-nd/opt/onbld/bin/i386/cw -_gcc -O -xspace -Xa -xildoff -errtags=yes -errwarn=%all -erroff=E_EMPTY_TRANSLATION_UNIT -erroff=E_STATEMENT_NOT_REACHED -_gcc=-Wno-missing-braces -_gcc=-Wno-sign-compare -_gcc=-Wno-unknown-pragmas -_gcc=-Wno-unused-parameter -_gcc=-Wno-missing-field-initializers -_gcc=-Wno-array-bounds -_gcc=-Wno-unused-function -_gcc=-Wno-uninitialized -_gcc=-Wno-parentheses -xc99=%none -W0,-xglobalstatic -_gcc=-fno-inline-small-functions -_gcc=-fno-inline-functions-called-once -_gcc=-fno-ipa-cp -g -xc99=%none -W0,-noglobal -xdebugformat=stabs -DTEXT_DOMAIN=\"SUNW_OST_OSCMD\" -D_TS_ERRNO -I/export/home/huakai/code/illumos-soulos/proto/root_i386/usr/include -D_LARGEFILE64_SOURCE=1 -D_REENTRANT -I../../common/zfs -I/export/home/huakai/code/illumos-soulos/usr/src/cmd/stat/common -DDEBUG -Bdirect -M/export/home/huakai/code/illumos-soulos/usr/src/common/mapfiles/common/map.noexstk -M/export/home/huakai/code/illumos-soulos/usr/src/common/mapfiles/common/map.pagealign -M/export/home/huakai/code/illumos-soulos/usr/src/common/mapfiles/common/map.noexdata -o zpool zpool_main.o zpool_vdev.o zpool_iter.o zpool_util.o timestamp.o -L/export/home/huakai/code/illumos-soulos/proto/root_i386/lib -L/export/home/huakai/code/illumos-soulos/proto/root_i386/usr/lib -lzfs -lnvpair -ldevid -lefi -ldiskmgt -luutil -lumem
+ /opt/gcc-4.4.4/bin/gcc -fident -finline -fno-inline-functions -fno-builtin -fno-asm -fdiagnostics-show-option -nodefaultlibs -D__sun -O -Wall -Wextra -Werror -Wno-missing-braces -Wno-sign-compare -Wno-unknown-pragmas -Wno-unused-parameter -Wno-missing-field-initializers -Wno-array-bounds -Wno-unused-function -Wno-uninitialized -Wno-parentheses -std=gnu89 -fno-inline-small-functions -fno-inline-functions-called-once -fno-ipa-cp -gdwarf-2 -std=gnu89 -DTEXT_DOMAIN="SUNW_OST_OSCMD" -D_TS_ERRNO -I/export/home/huakai/code/illumos-soulos/proto/root_i386/usr/include -D_LARGEFILE64_SOURCE=1 -D_REENTRANT -I../../common/zfs -I/export/home/huakai/code/illumos-soulos/usr/src/cmd/stat/common -DDEBUG -Wl,-Bdirect -Wl,-M/export/home/huakai/code/illumos-soulos/usr/src/common/mapfiles/common/map.noexstk -Wl,-M/export/home/huakai/code/illumos-soulos/usr/src/common/mapfiles/common/map.pagealign -Wl,-M/export/home/huakai/code/illumos-soulos/usr/src/common/mapfiles/common/map.noexdata -o zpool zpool_main.o zpool_vdev.o zpool_iter.o zpool_util.o timestamp.o -L/export/home/huakai/code/illumos-soulos/proto/root_i386/lib -L/export/home/huakai/code/illumos-soulos/proto/root_i386/usr/lib -lzfs -lnvpair -ldevid -lefi -ldiskmgt -luutil -lumem -lc
ld: fatal: library -luutil: not found
ld: fatal: file processing errors. No output written to zpool
collect2: ld returned 1 exit status
*** Error code 1
dmake: Fatal error: Command failed for target `zpool‘
Current working directory /export/home/huakai/code/illumos-soulos/usr/src/cmd/zpool
3.
从上面的出错信息中可以看到,缺少库文件“libuutil”
bash-4.2$ pwd
/export/home/huakai/code/illumos-soulos/usr/src/lib/libuutil
bash-4.2$ dmake
bash-4.2$ dmake install
/export/home/huakai/code/illumos-soulos/usr/src/lib/libuutil/native
/export/home/huakai/code/illumos-soulos/usr/src/lib/libuutil/i386
/usr/bin/rm -f /export/home/huakai/code/illumos-soulos/proto/root_i386/lib/libuutil.so.1; install -s -m 755 -f /export/home/huakai/code/illumos-soulos/proto/root_i386/lib libuutil.so.1
/usr/bin/rm -f /export/home/huakai/code/illumos-soulos/proto/root_i386/lib/llib-luutil.ln; install -s -m 644 -f /export/home/huakai/code/illumos-soulos/proto/root_i386/lib llib-luutil.ln
/usr/bin/rm -f /export/home/huakai/code/illumos-soulos/proto/root_i386/lib/libuutil.so; /usr/bin/ln -s libuutil.so.1 /export/home/huakai/code/illumos-soulos/proto/root_i386/lib/libuutil.so
/usr/bin/rm -f /export/home/huakai/code/illumos-soulos/proto/root_i386/lib/llib-luutil; install -s -m 644 -f /export/home/huakai/code/illumos-soulos/proto/root_i386/lib ../common/llib-luutil
/export/home/huakai/code/illumos-soulos/usr/src/lib/libuutil/amd64
/usr/bin/rm -f /export/home/huakai/code/illumos-soulos/proto/root_i386/lib/amd64/libuutil.so.1; install -s -m 755 -f /export/home/huakai/code/illumos-soulos/proto/root_i386/lib/amd64 libuutil.so.1
/usr/bin/rm -f /export/home/huakai/code/illumos-soulos/proto/root_i386/lib/amd64/llib-luutil.ln; install -s -m 644 -f /export/home/huakai/code/illumos-soulos/proto/root_i386/lib/amd64 llib-luutil.ln
/usr/bin/rm -f /export/home/huakai/code/illumos-soulos/proto/root_i386/lib/amd64/libuutil.so; /usr/bin/ln -s libuutil.so.1 /export/home/huakai/code/illumos-soulos/proto/root_i386/lib/amd64/libuutil.so
/usr/bin/rm -f /export/home/huakai/code/illumos-soulos/proto/root_i386/lib/llib-luutil; install -s -m 644 -f /export/home/huakai/code/illumos-soulos/proto/root_i386/lib ../common/llib-luutil
4.
bash-4.2$ pwd
/export/home/huakai/code/illumos-soulos/usr/src/cmd/zpool
bash-4.2$ dmake
/export/home/huakai/code/illumos-soulos/usr/src/tools/proto/root_i386-nd/opt/onbld/bin/i386/cw -_gcc -O -xspace -Xa -xildoff -errtags=yes -errwarn=%all -erroff=E_EMPTY_TRANSLATION_UNIT -erroff=E_STATEMENT_NOT_REACHED -_gcc=-Wno-missing-braces -_gcc=-Wno-sign-compare -_gcc=-Wno-unknown-pragmas -_gcc=-Wno-unused-parameter -_gcc=-Wno-missing-field-initializers -_gcc=-Wno-array-bounds -_gcc=-Wno-unused-function -_gcc=-Wno-uninitialized -_gcc=-Wno-parentheses -xc99=%none -W0,-xglobalstatic -_gcc=-fno-inline-small-functions -_gcc=-fno-inline-functions-called-once -_gcc=-fno-ipa-cp -g -xc99=%none -W0,-noglobal -xdebugformat=stabs -DTEXT_DOMAIN=\"SUNW_OST_OSCMD\" -D_TS_ERRNO -I/export/home/huakai/code/illumos-soulos/proto/root_i386/usr/include -D_LARGEFILE64_SOURCE=1 -D_REENTRANT -I../../common/zfs -I/export/home/huakai/code/illumos-soulos/usr/src/cmd/stat/common -DDEBUG -Bdirect -M/export/home/huakai/code/illumos-soulos/usr/src/common/mapfiles/common/map.noexstk -M/export/home/huakai/code/illumos-soulos/usr/src/common/mapfiles/common/map.pagealign -M/export/home/huakai/code/illumos-soulos/usr/src/common/mapfiles/common/map.noexdata -o zpool zpool_main.o zpool_vdev.o zpool_iter.o zpool_util.o timestamp.o -L/export/home/huakai/code/illumos-soulos/proto/root_i386/lib -L/export/home/huakai/code/illumos-soulos/proto/root_i386/usr/lib -lzfs -lnvpair -ldevid -lefi -ldiskmgt -luutil -lumem
+ /opt/gcc-4.4.4/bin/gcc -fident -finline -fno-inline-functions -fno-builtin -fno-asm -fdiagnostics-show-option -nodefaultlibs -D__sun -O -Wall -Wextra -Werror -Wno-missing-braces -Wno-sign-compare -Wno-unknown-pragmas -Wno-unused-parameter -Wno-missing-field-initializers -Wno-array-bounds -Wno-unused-function -Wno-uninitialized -Wno-parentheses -std=gnu89 -fno-inline-small-functions -fno-inline-functions-called-once -fno-ipa-cp -gdwarf-2 -std=gnu89 -DTEXT_DOMAIN="SUNW_OST_OSCMD" -D_TS_ERRNO -I/export/home/huakai/code/illumos-soulos/proto/root_i386/usr/include -D_LARGEFILE64_SOURCE=1 -D_REENTRANT -I../../common/zfs -I/export/home/huakai/code/illumos-soulos/usr/src/cmd/stat/common -DDEBUG -Wl,-Bdirect -Wl,-M/export/home/huakai/code/illumos-soulos/usr/src/common/mapfiles/common/map.noexstk -Wl,-M/export/home/huakai/code/illumos-soulos/usr/src/common/mapfiles/common/map.pagealign -Wl,-M/export/home/huakai/code/illumos-soulos/usr/src/common/mapfiles/common/map.noexdata -o zpool zpool_main.o zpool_vdev.o zpool_iter.o zpool_util.o timestamp.o -L/export/home/huakai/code/illumos-soulos/proto/root_i386/lib -L/export/home/huakai/code/illumos-soulos/proto/root_i386/usr/lib -lzfs -lnvpair -ldevid -lefi -ldiskmgt -luutil -lumem -lc
至此,编译zpool命令成功!
命令测试如下:
bash-4.2$ pwd
/export/home/huakai/code/illumos-soulos/usr/src/cmd/zpool
bash-4.2$ ls -l zpool
-rwxr-xr-x 1 huakai other 116496 Jul 4 16:40 zpool
bash-4.2$ ./zpool list
NAME SIZE ALLOC FREE EXPANDSZ CAP DEDUP HEALTH ALTROOT
rpool 928G 47.5G 881G - 5% 2.01x ONLINE -
bash-4.2$ ./zpool get all
NAME PROPERTY VALUE SOURCE
rpool size 928G -
rpool capacity 5% -
rpool altroot - default
rpool health ONLINE -
rpool guid 2706717091747937110 default
rpool version - default
rpool bootfs rpool/ROOT/soulos local
rpool delegation on default
rpool autoreplace off default
rpool cachefile - default
rpool failmode wait default
rpool listsnapshots off default
rpool autoexpand off default
rpool dedupditto 0 default
rpool dedupratio 2.01x -
rpool free 881G -
rpool allocated 47.5G -
rpool readonly off -
rpool comment - default
rpool expandsize 0 -
rpool freeing 0 default
rpool feature@async_destroy enabled local
rpool feature@empty_bpobj active local
rpool feature@lz4_compress enabled local
rpool feature@multi_vdev_crash_dump enabled local
rpool feature@spacemap_histogram active local
rpool feature@extensible_dataset enabled local