티스토리 뷰

반응형

듀얼 부팅(Dual Boot) 시간 동기화(timedatectl & hwclock)

 

듀얼 부팅(Dual Boot) 시간 동기화(timedatectl & hwclock)

 

윈도 + 리눅스 조합으로 듀얼 부팅(Dual Boot) 시스템을 구성하는 경우, 리눅스의 locale 설정이 달라지게 되면 리눅스를 종료하고 다시 윈도로 부팅할 때 윈도 시스템 시간이 계속 변경되는 상황이 발생할 수 있습니다.

리눅스에서 자꾸 Bios의 시간을 바꾸기 때문에 이런 문제가 발생합니다.
그 해결법에 대해서 살펴보도록 하겠습니다.

 

운영체제 간 시간 불일치 상황 (Time difference between Windows and Linux)

 

timedatectl

 

리눅스 설치 시 와이파이를 끈 상태로 설치해서 인지 Time zone: Aisa/Seoul로 제대로 설정되어 있음에도 불구하고 Local Time에 엉뚱한 시간이 Universal time에 한국 시간이 표시되고 있습니다.

System clock synchronized:no 상태군요. 우선 System clock synchoronized: yes로 바꿔줘야 합니다.
NTP(Network Time Protocol)을 통해서 시간을 동기화시킬 수 있습니다.
이 시간이 맞지 않는 경우 리눅스에서 OTP를 사용하는 추가 인증에도 문제가 생길 수 있습니다.

man timedatectl 명령어를 사용하여 timedatectl의 옵션과 사용법을 사용해보세요. 자주 사용하는 옵션 및 예제는 아래 코드 블록 내용 참고하시면 될 것 같습니다.

 

timedatectl manual(man page)

 

# timedatectl man page에서 일부만 가져왔습니다.

TIMEDATECTL(1)                               timedatectl                              TIMEDATECTL(1)

NAME
       timedatectl - Control the system time and date

SYNOPSIS
       timedatectl [OPTIONS...] {COMMAND}

DESCRIPTION
       timedatectl may be used to query and change the system clock and its settings, and enable or
       disable time synchronization services.

       Use systemd-firstboot(1) to initialize the system time zone for mounted (but not booted)
       system images.

       timedatectl may be used to show the current status of time synchronization services, for
       example systemd-timesyncd.service(8).

COMMANDS
       The following commands are understood:

       status
           Show current settings of the system clock and RTC, including whether network time
           synchronization is active. If no command is specified, this is the implied default.

       show
           Show the same information as status, but in machine readable form. This command is
           intended to be used whenever computer-parsable output is required. Use status if you are
           looking for formatted human-readable output.

           By default, empty properties are suppressed. Use --all to show those too. To select
           specific properties to show, use --property=.

       set-time [TIME]
           Set the system clock to the specified time. This will also update the RTC time
           accordingly. The time may be specified in the format "2012-10-30 18:17:16".

       set-timezone [TIMEZONE]
           Set the system time zone to the specified value. Available timezones can be listed with
           list-timezones. If the RTC is configured to be in the local time, this will also update
           the RTC time. This call will alter the /etc/localtime symlink. See localtime(5) for more
           information.

       list-timezones
           List available time zones, one per line. Entries from the list can be set as the system
           timezone with set-timezone.

       set-local-rtc [BOOL]
           Takes a boolean argument. If "0", the system is configured to maintain the RTC in
           universal time. If "1", it will maintain the RTC in local time instead. Note that
           maintaining the RTC in the local timezone is not fully supported and will create various
           problems with time zone changes and daylight saving adjustments. If at all possible, keep
           the RTC in UTC mode. Note that invoking this will also synchronize the RTC from the
           system clock, unless --adjust-system-clock is passed (see above). This command will
           change the 3rd line of /etc/adjtime, as documented in hwclock(8).

       set-ntp [BOOL]
           Takes a boolean argument. Controls whether network time synchronization is active and
           enabled (if available). If the argument is true, this enables and starts the first
           existing network synchronization service. If the argument is false, then this disables
           and stops the known network synchronization services. The way that the list of services
           is built is described in systemd-timedated.service(8).
           
           EXAMPLES
           Show current settings:

           $ timedatectl
                          Local time: Thu 2017-09-21 16:08:56 CEST
                      Universal time: Thu 2017-09-21 14:08:56 UTC
                            RTC time: Thu 2017-09-21 14:08:56
                           Time zone: Europe/Warsaw (CEST, +0200)
           System clock synchronized: yes
                         NTP service: active
                     RTC in local TZ: no

       Enable network time synchronization:

           $ timedatectl set-ntp true
           ==== AUTHENTICATING FOR org.freedesktop.timedate1.set-ntp ===
           Authentication is required to control whether network time synchronization shall be enabled.
           Authenticating as: user
           Password: ********
           ==== AUTHENTICATION COMPLETE ===

           $ systemctl status systemd-timesyncd.service
           ● systemd-timesyncd.service - Network Time Synchronization
              Loaded: loaded (/lib/systemd/system/systemd-timesyncd.service; enabled)
              Active: active (running) since Mo 2015-03-30 14:20:38 CEST; 5s ago
                Docs: man:systemd-timesyncd.service(8)
            Main PID: 595 (systemd-timesyn)
              Status: "Using Time Server 216.239.38.15:123 (time4.google.com)."
              CGroup: /system.slice/systemd-timesyncd.service
                      └─595 /lib/systemd/systemd-timesyncd
           ...

       Show current status of systemd-timesyncd.service(8):

           $ timedatectl timesync-status
                  Server: 216.239.38.15 (time4.google.com)
           Poll interval: 1min 4s (min: 32s; max 34min 8s)
                    Leap: normal
                 Version: 4
                 Stratum: 1
               Reference: GPS
               Precision: 1us (-20)
           Root distance: 335us (max: 5s)
                  Offset: +316us
                   Delay: 349us
                  Jitter: 0
            Packet count: 1
               Frequency: -8.802ppm

 

system clock synchronized 변경

 

system clock synchronized 변경

 

timedatectl의 man page에서는 sudo timedatectl set-ntp true라는 명령어의 예제를 보여줬지만 단순히 true 대신 yes를 넣어줘도 실행이 됩니다.

다시 sudo timedatectl 명령어를 입력해보면 Local time이 한국 시간으로 동기화되었음을 확인할 수 있습니다.

 

timedatectl 재실행

 

Local time을 hwclock(Bios 시간)으로 동기화시키기

 

system time을 bios time(hwclock)으로 동기화

 

정상적으로 Local time이 ntp 서버의 시간과 동기화가 되었다면 이 Local time을 Bios의 hwclock과 다시 동기화시켜주는 작업이 추가적으로 필요합니다.

이때 사용할 수 있는 명령어는 sudo hwclock --systohc --localtime입니다.

명령어에 있는 --systohc 옵션이, 시스템의 시간을 hwclock으로 동기화시키는 옵션입니다. --localtime의 옵션이 추가되었는데 시스템의 localtime을 기준으로 hwclock을 동기화시켜야 하기 때문에 추가된 옵션입니다.

자세한 사용법을 확인하시려면 man hwclock 명령어로 hwclock의 man page를 참고하세요.

 

# hwclock man page의 일부만 가져왔습니다.

HWCLOCK(8)                              System Administration                             HWCLOCK(8)

NAME
       hwclock - time clocks utility

SYNOPSIS
       hwclock [function] [option...]

DESCRIPTION
       hwclock is an administration tool for the time clocks. It can: display the Hardware Clock
       time; set the Hardware Clock to a specified time; set the Hardware Clock from the System
       Clock; set the System Clock from the Hardware Clock; compensate for Hardware Clock drift;
       correct the System Clock timescale; set the kernel’s timezone, NTP timescale, and epoch
       (Alpha only); and predict future Hardware Clock values based on its drift rate.

       Since v2.26 important changes were made to the --hctosys function and the --directisa option,
       and a new option --update-drift was added. See their respective descriptions below.
       
        -s, --hctosys
           Set the System Clock from the Hardware Clock. The time read from the Hardware Clock is
           compensated to account for systematic drift before using it to set the System Clock. See
           the discussion below, under The Adjust Function.

           The System Clock must be kept in the UTC timescale for date-time applications to work
           correctly in conjunction with the timezone configured for the system. If the Hardware
           Clock is kept in local time then the time read from it must be shifted to the UTC
           timescale before using it to set the System Clock. The --hctosys function does this based
           upon the information in the /etc/adjtime file or the command line arguments --localtime
           and --utc. Note: no daylight saving adjustment is made. See the discussion below, under
           LOCAL vs UTC.
                     
            -w, --systohc
           Set the Hardware Clock from the System Clock, and update the timestamps in /etc/adjtime.
           With the --update-drift option also (re)calculate the drift factor. Try it without the
           option if --systohc fails. See --update-drift below.

 

반응형
댓글