Bios time in linux

How can I force Ubuntu to use the BIOS internal clock instead of NTP or whatever its being used?

My clock starts running out of sync in Ubuntu which doesn’t happen in Windows. The problem is that it just starts losing time after a moment of syncing it with an NTP server, that means the clock is broken. So How can I make the system use the hardware clock instead(I tried adjtimex). BTW: please don’t suggest the CMOS battery, it’s not the correct answer.

To clarify. you think that your internal clock is /more/ accurate than using NTP? Or are you suggesting that NTP is broken on your system? Windows uses time.windows.com or something similar to sync its clock, whereas Ubuntu doens’t ship with NTP enabled, so it’s more likely that you actually /want/ to enable NTP on Ubuntu? Maybe?

No. NTP is fine, but the clock is broken in Ubuntu. When you choose to disable time sync in windows, it just keeps working, but when you either install NTP or or manually enter the time, the clock starts to get delays. For instance, the time here is 08:38 AM, in Ubuntu, however, it is 07:59 AM. If I log in NOW to Windows, I will get something very close to 08:38 which means that windows is taking time from a source(Time servers disabled) that Ubuntu fails to use.

What happened when you tried adjtimex? I use it and it works very well on most machines, though on some the rate offset changes suddenly every once in a while. Though in my experience, the adjtimexconfig program usually gets the initial adjustment wrong. I just use ntpdate to manually tweak the FREQ and TICK values in /etc/default/adjtimex I can get it to stay within a few seconds for weeks, without ntp or ntpdate.

@nealmcb: I wasn’t sure adjtimex would help me, that’s why I didn’t test it a lot, I did one thing with it, I updated using ntpdate and then sent that time to the bios’ clock, it worked but it couldn’t keep it for a long time.

Читайте также:  Linux post installation script

3 Answers 3

By default, Ubuntu only sets the time when a network interface comes up. It does this with a small piece of the «ntp» system: ntpdate. If your machine stays connected and keeps running for days or weeks, even the best internal clock will eventually go out of sync.
Ubuntu also doesn’t try to adjust your internal clock by default, and it sounds like your clock is badly adjusted. The real time clock (hardware clock) in most systems is also not very good over the long term.

So if you want better time, I can recommend two options:

  • Install the full «ntp» package to get the Network Time Protocol, which regularly looks at Internet time servers and keeps your clock within milliseconds of the right time. See some good instructions here: Install NTP. You can also install it from the Ubuntu Software Center. This is easy and typically pretty foolproof, if your machine is usually on the Internet and doesn’t have really nasty firewalls cutting off ntp.
  • Manually adjust the frequency of your internal clock, using the adjtimex package. Actually, when you install adjtimex, it runs adjtimexconfig which sets values in /etc/default/adjtimex. But it does so quickly using the hardware clock, and in my experience the results are usually somewhere between bad and terrible. Some machines are hard to tune well, but I’ve had good luck with most of my machines by doing the manual calculation necessary to figure out the right FREQ and TICK values to put in /etc/default/adjtimex. To go this route, start by installing adjtimex via Applications/Ubuntu Software Center. To figure out manual settings for FREQ and TICK, see the nice calculator at Tuning with adjtimex as an alternative to running ntpd. That page also notes that your choice of «clocksource» can affect how accurate your clock is. The hpet (High Precision Event Timer) seems more accurate than the tsc (Time Stamp Counter).

There are tips for dealing with other glitches at UbuntuTime — Help.ubuntu.com

Thank you; adjtimex seems to be working beautifully. I’m down to a few seconds per day, and am getting closer to ideal.

I’m not sure things work the way you’re describing. I.e., there are no «software» clock process/application which either uses BIOS clock or an ntp server and which can be «broken» in Ubuntu but working in Windows. In any case the info you see on the screen comes from BIOS clock.

Читайте также:  Linux check all listening ports

If NTP server is enabled, the data coming from it is used to adjust the BIOS/hardware clock, and, when the hardware clock is thought to be «incorrect», NTP daemon adjusts time gradually in small increments instead of setting it straight away. This is done to avoid sudden «jumps» in system time which may cause all sorts of trouble (i.e. an event which happens after some other event but at earlier time).

Which perfectly explains the behaviour you’re seeing — as soon as the «correct» data comes from the NTP server, the daemon starts gradually adjusting your system time.

I think your timezone/daylight saving time may be set incorrectly. Another possibility may be that Ubuntu expects the BIOS clock to be set to UTC time while Windows sets the clock in your local timezone, which results in Ubuntu thinking your system clock are late/early by your GMT offset

Источник

Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.

Very often when seeing setup guides and similar, it is written that syncing to bios/rtc time in UTC/GMT is ‘recommended’ but there is never a reason given and googling so far did not help me find one. I guess the most likely reason here is tradition and that it might confuse the odd sysadmin or program that somehow relies on bios time being in utc?

The question should be asked the other way around: UTC is the obvious default; why would setup guides recommend using anything else?

2 Answers 2

Machine firmwares don’t keep track of what timezone they are in, so is you want them to track what the absolute current time is, you must pick some standard, and there really isn’t any other obvious choice for that beside UTC. If different people chose different standards then either the machine firmware would have to provide an interface to tell the OS which one is in use, or provide an interface to the time in a «standard» time zone — and we’re back to UTC.

What’s worse, many timezones in the world don’t have a fixed offset away from UTC: they have two different fixed offsets from UTC depending on what time of the year it is. The machine firmware would have to know those rules and apply them. For every timezone you could conceivably want to use! And those rules change from time to time! If the machine firmware doesn’t track and apply those rules, but yet you still want to keep the firmware time in the local (variable-offset) timezone, the OS must compensate by applying a hack — but then it cannot be reliably determined whether or not the hack is currently applied. It’s just not tenable.

Читайте также:  Linux busybox built in shell

So. UTC FTW. Machine firmware is low level. Does it really have any reason to need to know the local time in the place where it’s running?

Источник

Настройка даты и времени в Linux

Изображение баннера

При работе в сети синхронизация времени и даты это важный фактор увеличивающий стабильность и безопасность работы всех систем.

В этой статье вы узнаете как настраивать дату и время вручную. И, что более важно — как синхронизировать их с ntp сервером.

Узнать текущее системное время

Узнать текущее системное время можно командой date

Узнать текущее время BIOS

Узнать текущее системное время BIOS можно командой hwclock

date и hwclock могут показывать совершенно разное время

Исправить текущее время

Сначала нужно задать время командой date

Также можно вводить «date MMDDhhmmCCYY» без секунд, тогда секунды выставляются на ноль.

После выполнения date нужно внести новое установленное время в BIOS:

Теперь осталось только проверить сохранились ли изменения

Синхронизация с ntp

Проверьте установлен ли ntp командой

Если ntp не установлен выполните

Проверьте запускается ли ntpd автоматически командой

systemctl list-unit-files | grep ntpd.s

Если ntpd неактивен (disabled) выполните

systemctl start ntpd
systemctl enable ntpd

Проверить добавлен ли сервис ntp в зону public в firewall можно командой

sudo firewall-cmd —get-services | grep ntp

Если ещё не добавлен, то чтобы разрешить UDP траффик от ntp выполните

firewall-cmd —permanent —add-service=ntp
firewall-cmd —reload

Отредактируйте файл ntp.conf с настройками сервера

Найдите свою временную зону на сайте www.ntppool.org

Я нашёл зону Helsinki и добавляю строки

server 0.fi.pool.ntp.org server 1.fi.pool.ntp.org server 2.fi.pool.ntp.org server 3.fi.pool.ntp.org

Теперь нужно перезапустить ntpd

Проверить откуда берётся время можно командой

remote refid st t when poll reach delay offset jitter ============================================================================== time.cloudflare 10.79.8.177 3 u 14 64 7 3.987 -0.366 0.016 37.228.129.2 193.66.253.94 2 u 16 64 7 5.301 -1.639 1.908 ivanova.ganneff 237.17.204.95 2 u 13 64 7 5.296 3.850 0.266 ntp23.kashra-se 192.168.100.15 2 u 12 64 5 32.935 -2.213 0.192

Выставить время BIOS по только что полученному времени можно командой

Заставить систему синхронизовать время с ntp

Вместо 0.fi.pool.ntp.org поставьте нужный вам сервер

Источник

Оцените статью
Adblock
detector