linux移植ntpdate「建议收藏」

linux移植ntpdate「建议收藏」今天想让板子在开机的时候自动去同步网络上的时间,网上查了一下,需要使用到ntpdate命令。但是我使用的文件系统(busybox制作的文件系统)没有该命令,所以移植了一下。由于移植ntpdate需要用到openssl的头文件和库,所以也移植了openssl。PC系统:UbuntuUbuntu12.04.4LTS1.创建工作目录1mkdirc

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE稳定放心使用

今天想让板子在开机的时候自动去同步网络上的时间,网上查了一下,需要使用到ntpdate命令。但是我使用的文件系统(busybox制作的文件系统)没有该命令,所以移植了一下。由于移植ntpdate需要用到openssl的头文件和库,所以也移植了openssl。

PC系统:Ubuntu Ubuntu 12.04.4 LTS

1. 创建工作目录

1

mkdir crossCompileDir

2. 获取openssl和ntpdate源码
我是直接使用apt-get来获取源码的,也可以去官网下载: www.ntp.org 和 www.openssl.org

1

2

3

cd crossCompileDir


apt-get source ntpdate


apt-get source openssl

3. 移植openssl

1

2

cd openssl-1.0.1


mkdir
/opt
/crossCompileInstallDir
/openssl-1.0.1
-p

配置

1

2

3

NM=arm-linux-gnueabihf-nm
AR=arm-linux-gnueabihf-ar \


RANLIB=arm-linux-gnueabihf-ranlib
CC=arm-linux-gnueabihf-gcc \

.
/config no-asm shared
–prefix=
/opt
/crossCompileInstallDir
/openssl-1.0.1

然后修改Makefile,将里面的-m64全部去掉(两个地方)
还有:
INSTALL_PREFIX=/opt/crossCompileInstallDir/openssl-1.0.1
不然make install 的时候不对

编译 不能使用多线程编译,否则会报错的!

1

2

make


make
install

需要处理一下:

1

2

mv
/opt
/crossCompileInstallDir
/openssl-1.0.1
/opt
/crossCompileInstallDir
/openssl-1.0.1
*
/opt
/crossCompileInstallDir
/openssl-1.0.1


rm
-rf
/opt
/crossCompileInstallDir
/openssl-1.0.1
/opt

4. 移植ntpdate命令(ntpdate在ntp软件包中)

1

2

cd ..
/ntp-4.2.6.p3+dfsg
/


mkdir
/opt
/crossCompileInstallDir
/ntp-4.2.6.p3+dfsg

配置

1

2

3

CC=arm-linux-gnueabihf-gcc .
/configure
–prefix=
/opt
/crossCompileInstallDir
/ntp-4.2.6.p3+dfsg \


–host=arm-linux-gnueabihf
–with-openssl-libdir=
/opt
/crossCompileInstallDir
/openssl-1.0.1
/lib \


–with-openssl-incdir=
/opt
/crossCompileInstallDir
/openssl-1.0.1
/include

编译

1

2

make


make
install

错误:

1、./keyword-gen ./ntp_parser.h > k-g.out
/bin/bash: ./keyword-gen: cannot execute binary file
make[4]: *** [k-g-u-submake] Error 126

Fix cross-compile ntpd 4.2.6: keyword-gen: cannot execute binary file

This happens when ntp version is cross compiled, In this case keyword-gen is generated for the target architecture. During compilation of ntpd keyword-gen is also executed thus it fails as it is created for some other architecture.

Solution: Compile ntp using gcc(Don’t cross compile). Now replace keyword-gen in cross compiled ntp with keyword-gen in gcc compiled ntp. Now cross compile ntp again.

先用gcc make然后再用arm-linux-gcc make

5. 板子上使用
将移植出来的文件拷贝到板子上的对应目录中。然后使用,出现了一下错误1:

1

2

3

4

ntpdate
-u ntp.api.bz

Error resolving ntp.api.bz: Servname not supported
for ai_socktype
(
8
)

 
5 Mar
17:
55:
22 ntpdate
[
211
]: Can
‘t find host ntp.api.bz: Servname not supported for ai_socktype (-8)
 5 Mar 17:55:22 ntpdate[211]: no servers can be used, exiting

解决办法是将以下两行内容:

1

2

ntp             123/tcp

ntp             123/udp

写进/etc/services文件中,就可以了使用命令同步网络时间了。

错误2:

ntpdate: /usr/lib/libcrypto.so.1.0.0: no version information available (required by ntpdate)

解决办法:

用编译的openssl更新libcrypto.so.1.0.0

但是还有一个问题,同步出来的时间和所在的时区不对,如下所示:

1

2

3

4

5

ntpdate
-u ntp.api.bz

 
5 Mar 09:
58:05 ntpdate
[
217
]: adjust
time server 61.153.197.226 offset –
0.010535 sec


#使用date命令可以看到是UTC(协调世界时)的时间的


date

Thu Mar  
5 09:
58:
35 UTC
2015

设置时区:
从pc机上拷贝/usr/share/zoneinfo/Asia/Hong_Kong (或者使用 Shanghai Chongqing)到板子上的对应位置,然后再 cp /usr/share/zoneinfo/Asia/Hong_Kong /etc/localtime,或者做一个软连接即可。
再次同步时间:

1

2

3

4

5

ntpdate
-u ntp.api.bz

 
5 Mar
18:06:
10 ntpdate
[
221
]: adjust
time server 61.153.197.226 offset –
0.018679 sec

date

Thu Mar  
5
18:06:
24 HKT
2015

6. 添加开机同步网络时间

将命令ntpdate -u ntp.api.bz添加到/etc/profile文件中即可。

当然想要开机同步网络时间,前提是板子开机起来就直接可以上网。

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/189823.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • Activity跳转fragment

    Activity跳转fragmentfragment不能单独存在,必须依附在Activity上,所以在Activity跳转时,实际是跳到fragment的宿主上代码:Activity点击跳转里Intentintent=newIntent(ListDetailsActivity.this,MainActivity.class);intent.putExtra("id",2);startActivity(intent);frag…

    2022年5月21日
    35
  • 大数据学习之Linux基础[通俗易懂]

    大数据学习之Linux基础[通俗易懂]大数据学习之Linux基础自定义Linux虚拟机安装网络配置1.node1网络配置2.通过快照克隆虚拟机3.配置其他三个节点虚拟机Linux简单命令shell命令运行原理图1.关机与重启2.判断命令的命令3.常用功能命令4.文件系统命令文件系统层次化标准(FileSystemHierarchyStandard)5.文本操作命令vi全屏文本编辑器全屏编辑器模式1.打开文件2.关闭文件3.编辑…

    2022年6月3日
    30
  • 数据库设计-简化字典表[通俗易懂]

    开发工具与关键技术:工具:SQLServer2014ManagementStudio作者:范子超 撰写时间:2019-03-29  在进行数据库设计时,我们经常会遇到各种各样的业务需求,从而设计出各种各样的表。而想要做好一个数据库,不但需要前期对各种业务需求的深度理解,还需要在后期项目完善的过程中对数据库更新修改从而使得数据库设计的越发完美。  对于那些涉及到业务的表或许不太好入…

    2022年4月9日
    142
  • js对数字数组排序[通俗易懂]

    js对数字数组排序[通俗易懂]js中经常需要用到对数组进行排序的操作,当数组中的元素均为数字时,直接使用sort()进行排序得到的结果可能不是你想要的结果。假如我有数组arrayNums=[15,2,16],直接使用arrayNums.sort()的排序结果将是[15,16,2],这是因为Javascript的sort()函数在默认情况下是按照字符串顺序对值进行排序的。正因如此,sort()方法在对数值排序时会产生…

    2022年5月15日
    41
  • mutual information loss_munication

    mutual information loss_munication今天挺paperreading的时候,听到了最大化互信息,还不清楚互信息是个什么东东,google了一下,从http://en.wikipedia.org/wiki/Mutual_information摘过来了:    DefinitionofmutualinformationFormally,themutualinformationoftwod

    2022年9月17日
    0
  • pycharm不支持32位系统怎么办_win10更新一直安装失败

    pycharm不支持32位系统怎么办_win10更新一直安装失败出现ThisinstallationcontainsJetBrainsRuntime11whichdoesnotsupportMicrosoftWindows32-bitversion.这个导致的原因是电脑操作系统是32位的,不支持Pycharm64位的软件安装,因此需要我们去下载一个Pycharm32位的软件版本。可以在https://www.jetbrains.com/pycharm/download/other.html这里进入,选择Pycharm低版本的,例如2018版本P

    2022年8月25日
    3

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号