LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 03-21-2022, 10:34 AM   #1
random_guy
Member
 
Registered: Sep 2006
Location: TX,USA
Distribution: Slackware-15.0
Posts: 30

Rep: Reputation: 15
Fresh Slackware 15.0 install - system date/time not preserved after reboot.


This weekend I decided to take the plunge and did a fresh install of Slackware-15.0. Everthing went well, except for one small thing - the system date/time (CST timezone) does not get preserved after reboots. Note, on Friday, with a 14.2 installation, there was no issue with the system date (time zone etc).

Things I've checked and tried so far.

-- BIOS date and time is correct, I double checked this.

-- Shows the correct date and time (CDT)
# hwclock --show
2022-03-20 14:33:02.293381-05:00

-- Off by 5 hrs
# date
Sun Mar 20 09:34:15 CDT 2022

# cat /etc/adjtime
0.000000 1647804661 0.000000
1647804661
LOCAL

# ls -ld /etc/*time*
-rw-r--r-- 1 root root 46 Mar 20 2022 /etc/adjtime
lrwxrwxrwx 1 root root 35 Mar 20 2022 /etc/localtime -> /usr/share/zoneinfo/America/Chicago

# cat /etc/hardwareclock
# /etc/hardwareclock
#
# Tells how the hardware clock time is stored.
# You should run timeconfig to edit this file.

localtime

Over the years, there have been similar reports of users of other distros having this problem. So I tried some of their tips, which didn't work:
1. Set hwclock
2. Set system date with, date command
3. Renamed /etc/adjtime
4. Reboot

Repeated the above steps 1 and 2 but left /etc/adjtime in place. This didn't work either.

Sorry for the long post. Did not want to waste anyones time
Any tips, comments or advice would be greatly appreciated.

TIA
 
Old 03-22-2022, 04:03 AM   #2
subscrive
Member
 
Registered: Feb 2022
Posts: 72

Rep: Reputation: 12
As root, enter "netdate time.nist.gov"

https://www.linux.org/threads/how-to...ackware.23706/
 
Old 03-22-2022, 06:25 AM   #3
kjhambrick
Senior Member
 
Registered: Jul 2005
Location: Round Rock, TX
Distribution: Slackware64 15.0 + Multilib
Posts: 2,159

Rep: Reputation: 1512Reputation: 1512Reputation: 1512Reputation: 1512Reputation: 1512Reputation: 1512Reputation: 1512Reputation: 1512Reputation: 1512Reputation: 1512Reputation: 1512
Quote:
Originally Posted by subscrive View Post
As root, enter "netdate time.nist.gov"

https://www.linux.org/threads/how-to...ackware.23706/
Yes, that works for me too but I also noticed what the O.P. ( random_guy ) says.

And I believe that his point is more-or-less 'Why doesn't the kernel set the System Time from the Hardware Clock' ?

IOW, how do I set the System Time at boot if my Server is isolated from the internet ?

-- kjh
 
Old 03-22-2022, 06:55 AM   #4
GazL
LQ Veteran
 
Registered: May 2008
Posts: 6,915

Rep: Reputation: 5033Reputation: 5033Reputation: 5033Reputation: 5033Reputation: 5033Reputation: 5033Reputation: 5033Reputation: 5033Reputation: 5033Reputation: 5033Reputation: 5033
A dodgy TZ environment variable can make 'date' show misleading information
e.g.
Code:
$ date
Tue 22 Mar 11:57:40 GMT 2022
$ TZ=':America/Chicago'  date
Tue 22 Mar 06:57:45 CDT 2022
$ TZ=CDT date
Tue 22 Mar 11:57:48 CDT 2022
... makes it look like CDT, but it's not.

Not saying that's your issue, but it's something to check.

Last edited by GazL; 03-22-2022 at 06:58 AM.
 
1 members found this post helpful.
Old 03-22-2022, 10:05 AM   #5
random_guy
Member
 
Registered: Sep 2006
Location: TX,USA
Distribution: Slackware-15.0
Posts: 30

Original Poster
Rep: Reputation: 15
Thanks everyone for the responses.

@GazL, good call, I checked my TZ env. var and its not set. Any idea what sets this value in the environment or during install? I've never had to manipulate it in the past. I ran timeconfig this morning and selected US/Central it changed the zoneinfo(see below) but did not set the TZ variable. Thoughts?

$ ls -ld /etc/*time*
lrwxrwxrwx 1 root root 30 Mar 22 03:16 /etc/localtime -> /usr/share/zoneinfo/US/Central

@kjhambrick you are correct. I've never used an external time service to sync the clocks on my system. Not looking to change that.
 
Old 03-22-2022, 10:57 AM   #6
GazL
LQ Veteran
 
Registered: May 2008
Posts: 6,915

Rep: Reputation: 5033Reputation: 5033Reputation: 5033Reputation: 5033Reputation: 5033Reputation: 5033Reputation: 5033Reputation: 5033Reputation: 5033Reputation: 5033Reputation: 5033
The original idea was that you set TZ from your ~/.profile, which would then allow people on different continents to share a server while allowing each to work using their own local timezone. These days $TZ isn't used so much, especially as everyone has their own system, most likely running on their local timezone by default.

It's always worth checking whether it's set or not though when weird stuff happens. If anything was likely to set it, it'd probably be one of the Desktop Environment startup files, but if TZ is not set, then that's not your issue.
 
Old 03-22-2022, 11:10 AM   #7
kjhambrick
Senior Member
 
Registered: Jul 2005
Location: Round Rock, TX
Distribution: Slackware64 15.0 + Multilib
Posts: 2,159

Rep: Reputation: 1512Reputation: 1512Reputation: 1512Reputation: 1512Reputation: 1512Reputation: 1512Reputation: 1512Reputation: 1512Reputation: 1512Reputation: 1512Reputation: 1512
random_guy --

Below is an sdiff of /etc/rc.d/rc.S 14.2 -vs- /etc/rc.d/rc.S 15.0 where hwclock is invoked at startup.

I pass the grep /proc/ioports test:
Code:
 grep " : rtc"  /proc/ioports
  0070-0077 : rtc0
And /etc/adjtime is newer than /etc/hardwareclock:
Code:
# [ /etc/adjtime -nt /etc/hardwareclock ] && echo "nt" || echo "not nt"
nt
The only diff I see us the '-a -z "$container" in the if-block ...

-- kjh
Code:
# /tmp/rc.S.14.2                                                                       # /etc/rc.d/rc.S
<<snip>>
# Set the system time from the hardware clock using hwclock --hctosys.                 # Set the system time from the hardware clock using hwclock --hctosys.
if [ -x /sbin/hwclock ]; then                                                       |  if [ -x /sbin/hwclock -a -z "$container" ]; then
  # Check for a broken motherboard RTC clock (where ioports for rtc are                  # Check for a broken motherboard RTC clock (where ioports for rtc are
  # unknown) to prevent hwclock causing a hang:                                          # unknown) to prevent hwclock causing a hang:
  if ! grep -q " : rtc" /proc/ioports ; then                                             if ! grep -q " : rtc" /proc/ioports ; then
    CLOCK_OPT="--directisa"                                                                CLOCK_OPT="--directisa"
  fi                                                                                     fi
  if [ /etc/adjtime -nt /etc/hardwareclock ]; then                                       if [ /etc/adjtime -nt /etc/hardwareclock ]; then
    if grep -q "^LOCAL" /etc/adjtime ; then                                                if grep -q "^LOCAL" /etc/adjtime ; then
      echo -n "Setting system time from the hardware clock (localtime):  "                   echo -n "Setting system time from the hardware clock (localtime):  "
    else                                                                                   else
      echo -n "Setting system time from the hardware clock (UTC):  "                         echo -n "Setting system time from the hardware clock (UTC):  "
    fi                                                                                     fi
    /sbin/hwclock $CLOCK_OPT --hctosys                                                     /sbin/hwclock $CLOCK_OPT --hctosys
  elif grep -wq "^localtime" /etc/hardwareclock 2> /dev/null ; then                      elif grep -wq "^localtime" /etc/hardwareclock 2> /dev/null ; then
    echo -n "Setting system time from the hardware clock (localtime):  "                   echo -n "Setting system time from the hardware clock (localtime):  "
    /sbin/hwclock $CLOCK_OPT --localtime --hctosys                                         /sbin/hwclock $CLOCK_OPT --localtime --hctosys
  else                                                                                   else
    echo -n "Setting system time from the hardware clock (UTC):  "                         echo -n "Setting system time from the hardware clock (UTC):  "
    /sbin/hwclock $CLOCK_OPT --utc --hctosys                                               /sbin/hwclock $CLOCK_OPT --utc --hctosys
  fi                                                                                     fi
  date                                                                                   date
fi                                                                                     fi
 
Old 03-22-2022, 11:49 AM   #8
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,762

Rep: Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931
Code:
-- Shows the correct date and time (CDT)
# hwclock --show
2022-03-20 14:33:02.293381-05:00

-- Off by 5 hrs
# date
Sun Mar 20 09:34:15 CDT 2022

# cat /etc/adjtime
0.000000 1647804661 0.000000
1647804661
LOCAL
The howclock --show always displays local time regardless if you keep the hardware clock set to UTC. The output of the date command shows CDT which appears to be the correct timezone.

The LOCAL in your /etc/adjtime configures the OS to use local time for your hardware clock. If the clock is actually set to UTC and the OS thinks its local time the system time will be off the UTC offset i.e. 5 hours.
 
1 members found this post helpful.
Old 03-22-2022, 01:24 PM   #9
random_guy
Member
 
Registered: Sep 2006
Location: TX,USA
Distribution: Slackware-15.0
Posts: 30

Original Poster
Rep: Reputation: 15
@kjhambrick thanks for the response. I too was looking at this script yesterday, here's what I see on my system.

$ grep " : rtc" /proc/ioports
0000-0000 : rtc0


$ [ /etc/adjtime -nt /etc/hardwareclock ] && echo "nt" || echo "not nt"
nt

$ cat /etc/adjtime
0.000000 1647955039 0.000000
1647955039
LOCAL

So, the script should be make it down to the IF condition below and
should print "Setting system time from the hardware clock (localtime): "

Just curioius, should the line after the IF condition be:
/sbin/hwclock $CLOCK_OPT --hctosys
OR
/sbin/hwclock $CLOCK_OPT --localtime --hctosys

Perhaps the assumption is because /etc/adjtime exists, the --localtime argument is redundant.

if grep -q "^LOCAL" /etc/adjtime ; then
echo -n "Setting system time from the hardware clock (localtime): "
else
echo -n "Setting system time from the hardware clock (UTC): "
fi
/sbin/hwclock $CLOCK_OPT --hctosys
elif grep -wq "^localtime" /etc/hardwareclock 2> /dev/null ; then
....

fi
 
Old 03-22-2022, 02:20 PM   #10
kjhambrick
Senior Member
 
Registered: Jul 2005
Location: Round Rock, TX
Distribution: Slackware64 15.0 + Multilib
Posts: 2,159

Rep: Reputation: 1512Reputation: 1512Reputation: 1512Reputation: 1512Reputation: 1512Reputation: 1512Reputation: 1512Reputation: 1512Reputation: 1512Reputation: 1512Reputation: 1512
YW random_guy ( but I don't feel very helpful here )

I am interested because I've got two Customers who do not connect their Servers to the internet.

I am still digging ...

-- kjh

`man hwclock` has an interesting 'newish' section:
Code:
# man hwclock
<<snip>>
       --systz
           This is an alternate to the --hctosys function that does not read the Hardware Clock
           nor set the System Clock; consequently there is not any drift correction. It is
           intended to be used in a startup script on systems with kernels above version 2.6
           where you know the System Clock has been set from the Hardware Clock by the kernel
           during boot.

           It does the following things that are detailed above in the --hctosys function:

           o   Corrects the System Clock timescale to UTC as needed. Only instead of
               accomplishing this by setting the System Clock, hwclock simply informs the kernel
               and it handles the change.

           o   Sets the kernel's NTP '11 minute mode' timescale.

           o   Sets the kernel's timezone.

       The first two are only available on the first call of settimeofday(2) after boot.
       Consequently this option only makes sense when used in a startup script. If the Hardware
       Clocks timescale configuration is changed then a reboot would be required to inform the
       kernel.

<<snip>>
Not sure it's applicable but there it is ...
 
Old 03-24-2022, 10:23 AM   #11
random_guy
Member
 
Registered: Sep 2006
Location: TX,USA
Distribution: Slackware-15.0
Posts: 30

Original Poster
Rep: Reputation: 15
I got things working. Perhaps this will help someone else who runs into this situation.

Summary:
1. Set Hardware clock to UTC
2. Set Hardware clock Timezone to UTC
3. Set Hardware clock to desired Timezone (US/Central, in my case)
4. Sync Hardware clock to System clock

Step-by-Step:
1. Change Hardware Clock to UTC time
# hwclock --utc --set --date='2022-03-24 01:30'

2. Change timezone to UTC
# timeconfig (Answer Yes, to Hardware Clock set to UTC, then scroll and select UTC for Timezone).
# ls -l /etc/localtime
# lrwxrwxrwx 1 root root 30 Mar 24 2022 /etc/localtime -> /usr/share/zoneinfo/UTC
-- Confirm changes by running, hwclock. There should *not* be any timezone offset i.e. it should be UTC time-0 hours instead of UTC-5 (US/Central).

3. Change timezone to local timezone
# timeconfig ( Answer Yes, to Hardware Clock set to UTC, then select US/Central)
# ls -l /etc/localtime
# lrwxrwxrwx 1 root root 30 Mar 24 2022 /etc/localtime -> /usr/share/zoneinfo/US/Central

4. Sync Hardware clock to System clock
# hwclock --hctosys
# shutdown -r now

I expect this would probably work for other distros, if they provide a helper script similar to Slackwares timeconfig script.

Last edited by random_guy; 03-24-2022 at 10:25 AM. Reason: typo.
 
2 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Sound system settings not preserved after reboot susja Linux - Newbie 1 04-04-2012 11:53 AM
[SOLVED] new line characters not preserved in bash mystupidquestion Programming 2 10-06-2011 11:08 AM
OpenBSD 4.7, sudo, PATH not being preserved. bluesword1969 *BSD 1 06-08-2010 04:11 PM
MadWifi working after fresh install but not after reboot wet Linux - Wireless Networking 2 07-14-2007 08:32 PM
session variables not preserved when navigating thru links prabhatsoni Linux - Software 2 06-13-2005 01:15 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 03:58 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration