Practice Exams:

LPI 101-500 – 108.1: Manage the system time

  1. date, hwclock

This chapter summarizes the time. Every computer has battery powered hardware clock or cmos clock. It is of course essential that this hardware clock is battery operated, otherwise you would have to reset it every time the computer is switched off. It continues to run like a normal clock or watch, even when it is switched off. The time of this hardware clock can be set in bios or oaf. linux only uses this hardware clock when starting the operating system. The time from the cmos clock is read and converted into the kernel time, so the kernel internal system clock is set. The kernel clock or the system clock has a somewhat unusual format because it does not directly display the time as we know it, but the time and seconds.

Since the first January 1970 at zero dot zero utc. utc stands for Universal Time Coordinated and denotes the so called world time. With the tool HW clock, we can display the cmos time. HW clock naturally stands for hardware clock. Of course, HW clock has to be run as root, otherwise you will get an error message, namely the following sorry for the German translation here in English, we have to be root for HW clock. Here stands no access type was found with which the hardware clock could be accessed. And as I said, basically they just want to tell us to be root. So let’s do that with pseudo su. And now again, HW clock. And now the hardware time is displayed.

So this is now the fourth February 2021 and it is 1633 German time. So it’s 04:33 p. m. And 15 seconds. And these are here the hundreds and thousands. But of course they are very uninteresting for us. With date you can display the system time. And now you should see the difference between the system time and the hardware time. The hardware time says it’s 1633 and the system time says it’s 1833, so 06:33 p. m. . So the two times are different. Of course, I did this consciously for the following example, because HW clock can also be used to match the system clock to the hardware clock or vice versa. To be able to understand the following example, or to be able to imitate it yourself, I would ask you to carry out the following two steps.

So the first step should be go to the settings and then at the bottom there is date and time. And here the first one. The first configuration here is set date and time automatically. You have to deactivate it as I did. And the second step is please enter the following command system ctl Stop and then System D time sync d if you do not take these two steps, then you cannot change the date. Or better saying, you can change the date, but after 3 seconds the system will automatically change your setting back and you cannot do the examples that will follow. Okay, so that’s it. Please do these two steps. Okay, let’s say we want to set the system clock to the same time as the hardware clock.

So again, to repeat, the system clock says it’s 18:33. P. m. Or 06:33 p. m. And the hardware clock says 1633. So 04:33 p. m. And well, that’s a few minutes ago. Now that means we now choose the command Hclock again HW clock and now it’s 60 and 36, nearly 37. And so we now take the HW clock command and use the option HC to sys. So hardware clock to system. So we take the hardware time and feed it into the system time, so to speak. So let’s try it out. HW clock with the option HC two hardware clock, two system clock. alternatively, you could use the option S instead of HC to this. That’s the same thing, just a different spelling. But now I use HC to this.

So let’s compare the times again. Date it’s 1638 and HW clock it’s also 1638. So that worked. The times are now completely identical again, just as we wanted it to be. Let’s change the system time again. For another example, we use the Date command for this.You should definitely be familiar with Date from previous lessons. Date without an option only shows the current date and time. You can also use Date, for example, to display the date or time in a different format. Or you can use Date to even change the date or time. The spelling of this command always looks a bit complicated, but it’s actually not at all and you just have to remember a few things. So let’s just put the time and hour forward. So now it’s 1638. So we are going to set it to 70 1738.

The command is date plus percent ts and then 1738. The plus symbol here at this point must always be put in front when changing the date or time, the person sign introduces an option, in this case the option T for time and the option S means set. And this is given as a string here so as text and quotation marks. And I will do that now and that is the result that is shown to us. I run Date again without an option and we see Monday, Thursday, sorry, Thursday the fourth February and it’s 1738. So I run HW clock again and we see that we have two different times again. So just like we planned it now, but let’s stay with the date for a moment. I recommend reading the man page again here.

There are many different ways to view or change the time or date instead of the command we just entered. When changing the time, we could do this like this. For example date plus and then percent H colon m sorry, percent M colon and then percent S and then again S and then maybe 23:11 P. m. For example. And here we have of course H stands for hours, M stands for minutes and S stands for seconds. So that’s basically just the longer spelling of the option T here. So T is basically a short form of hms in this case. So when we run the command, or we have run the command and we see that it worked, it’s 11:00 P. m. At the moment and HW clock says it is 1642.

Okay, let’s change the date, only the date. Now we can do it also with the command date and then plus percent D. The D stands for date and then S and then for example like this and the D is for date, the S is for set. And we have to use the American spelling for date here. And we see that the date has successfully changed. So it is now Wednesday, the fourth November in the year 2020, just like I entered it here. And we see something else because the time has also changed here we have zero colon, zero so 0 hour, zero minutes 0 second. This means that if we change the date, the system assumes that it will start at 12:00, as in this case. So we have now changed the date and time.

Let’s use HW clock again, but this time the other way around. So we choose the system time. So the fixtures time from 2020 at midnight. We could now like to project this into the hardware time. That means we use the same option as before, only in reverse. So we just had HW clock and then HC two sys, the hardware clock to the system clock. And now let’s do it the other way around. So with SIS two HC we check it with HW clock and we see on the hardware clock we have the fourth November 2000, 2020 and it’s two minutes after midnight now, the same as our system time with date. So the times have completely aligned again. Instead of HC to this, you can also choose the short form S and instead of SIS to HC you can use you can also use the short form W. This is also the same, just a different spelling, but you should keep that in mind for the exam.

You can find these options of course in the main page. And here you can see s is the same as HC to this and W is the same as sister HC. I would say the subject is closed. With that I would briefly change my system clock to a correct time and date again. So I use this time the following command date plus percent D, colon percent T and then S for set. And now I have to enter the string. And today it is the February 4, 2021 and it is 1647 at the moment. So now the date and the time are correct again. Let’s check the hardware clock. This is wrong. So we can use HW clock with SIS to HC or with W. So that’s just ww this time and let’s check it and now, the hardware clock is also correct. That’s it for this lesson. See you in the next one.

  1. ntpd, ntpdate, chrony

If you look at the LPIC page to see which commands, tools and paths you need to know for this chapter, a few commands you know from the last chapter appear that would be user share zone info at the time zone at the local time and timedaped Ctl. Again, maybe very briefly to repeat, in the file at Ctl time zone there is an entry for the current time zone. In my case this is Europe Berlin europe Berlin this entry is also a file that is located in user share zone info. And here in this directory there is also the subdirectory Europe. So let’s switch to Europe. And here we find Berlin. We cannot display the file berlin got berlin see here not possible. And yeah, the file Berlin contains information about the time zone, such as the time offset between UTC and local Time, daylight saving and wintertime regulations and so on.

The Etsy local time file is basically a shortened link to the corresponding time zone file in user share zone info. We cannot open this file either at the local time and here too we only get our cryptic symbols again. But with Ll we can see that this is a link at the local time, and we see that the link points to user share zoning for Europe Berlin the timed eight Ctl command shows us various time related information time date Ctl and here we see the local time, the universal time, RTC time zone and so on. Various information can be used to display further information, for example, the available time zones with time date Ctl list time zones, and here you can see the time zones.

You can also change the time or the time zones with time date Ctl. But we have already discussed this in detail in the penultimate video, which is why I will not go into it again in detail here. Then we come to the last topic in this chapter. This is about time synchronization using NTP. NTP means network time protocol and is a standard for synchronizing times in computer systems over the network or over the Internet. In a company network it is important that the times of the individual systems are as identical as possible, and ideally also correspond as precisely as possible to the time shown in the atomic clocks. To ensure this NTP is used, a common NTP demon is called NTPD. NTPD can be used as a client as well as a server.

As a client, NTPD communicates with so called time service, so the service that provide the correct time formulated a little more simply. As a server, NTPD can forward the received time to other computers in the network. Let’s take a look at this. In practice, my Ubuntu doesn’t have NTPD installed by default, so let’s install it now. The package is simply called NTP, so pseudo apt install NTP so NTP is installed. Let’s see if it started automatically. I almost assume so. Systemctl status NTP. So NTP is running fine. Let’s first take a look at the anti PD configuration file. As always, we find configuration files within At C. In this case it is at CP conf. The most important part in this file is the so called NTP pool.

This is here. In this place we have these NTP pool addresses. The four addresses here. Behind each pool address given here, there are most likely a few hundred or even a few thousand time servers. If our NTP Demon uses the NTP pool, it is passed on almost randomly to a time server somewhere in the world, from which it then obtains the exact time. The eyeburst option after the time server pool address means that the system should pick up the current time immediately after the system starts. If a corresponding network has many servers and clients, then one server should be chosen as the NTP server. This should then receive the corresponding time via the NTP pool and then pass this on to all other servers and clients in the network.

At the top we see a reference to the so called drift file. Here, systematic deviations in the CMOS clock are recorded in this file. Of course, entity has to work for a while to be able to collect the relevant data. Below that we see a reference to the leap file here. At this point, corresponding time jumps are recorded here. For example, leap seconds. The rest may not really be relevant. For the IPIC one exam, we now check whether the NTP server is doing its job correctly. So we are going out of this file again and we just change the time manually again. We know from the last video how it works. So let’s see what we have for a time. Now it’s 19 two so 07:00 p. m. So that you can see that almost.

Let’s say the other way around. Let’s say we want to go back to 18:00 so date plus percent T s and then 1818. And you can see here 18. And now it’s already changed back to 19 three so seems like the NTP server works. Let’s check the clock. And that’s not exactly the same time you see here. You remember in the last video I have set the time manually and not automatically over the Internet. Because of that, we have a little difference here. Okay, for the next command, we have to change the time manually again so that this is not immediately overwritten by NTPD. We have to stop it first. We do that with system Ctl stop NTP. Let’s check if it’s really stopped exactly how we want it.

Now we are not changing the time again. This time, for example, at 1840 plus percent T and then S and then 1840. So 1840 the NTP server is switched off and now our set time remains and it is not automatically overwritten again. We now look at the NTP date command with the program NTP date. We can synchronize our system time once with the time server from the Internet. At least on my system it is not installed by default, which is why I quickly catch up with Apt install NTP date. Now we use the NTP date command followed by a time server address. We can simply use a pool address in the NTP confile again. So let’s take a quick look again cat@cntp. com. I copy this address here. This one without pool and without eyeburst of course.

And let’s run the command NTP date and then paste it here the pool address. And you can actually enter a second pool address in case the first one doesn’t work for any reason. So just a space and then another address, this one for example, or this one. So for the reason the first pool isn’t working, then entity Date will use the second pool address here and we see. It takes a few seconds. Let’s wait a little bit.And now we are also shown which server was used for the time synchronization, namely this one here or this IP address. And we can check the result. And it is 19 eight. So seven eight P m and the time should now be correct. So let’s check HW clock, which is a little bit different as had before, but they are nearly equal.

Okay, let’s switch anti PD back on system Ctl start Antp. Let’s look again at whether it started systemctl status NTP. Yes, it works. For the exam we still need knowledge of the ntpq command. That means nothing else then that we need to know that it exists and what it is for. However, we don’t really have to master it with ntpq. We can look at a list of the NTP service use and their specific data. For this we use the function p so ANTPQ and the option P. And here we see now corresponding table. We don’t have to be able to name every column for the test for the exam, but maybe the most important ones here. Here on the far left under remote we find the corresponding time server.

Here in the column REFID we can find the IP address of the server if it is a single server. Otherwise we see the word pool, because it is a pool of several servers and not a single time server, as already explained before. In the third column we have the value St is the abbreviation for Stratum and describes the distance to the atomic clock. If there were a one here instead of 16, it would mean that this computer is attached directly to the atomic clock. If there is a two like here, there is another server in between. And if there is a three, then there are two other servers in between and so on. The when column shows the last contact with the synchronization server. So here we have nothing and here we have 35, 32, 33 and so on.

And no time unit, as in this case here, means that the number is to be understood in minutes. Otherwise ntpq can be used to interactively communicate with a relevant time service. Here we just specify ntpq with no options. So ntpq and we see now we have a prompt with ntpq. So it is now waiting for an input. We can input, for example, peers with the command peers, for example, you can display the list that we have already seen above. You can use help to get some commands that you can use. And for example, let’s use some sys stats. And then we get to get some statistics here. And yeah, we can see uptime recess packets, received current version and so on, but we definitely don’t have to go that deep. That was just for sake of information.

What exactly you can do now, finally, let’s get to Crony. Crony is another NTP program with which you can of course also synchronize the system time. Before we install crony, let’s uninstall NTP. In theory, that doesn’t have to be the case and it’s enough to just switch it off, but I like to clean up my computer, so I will just do it with Apt perchantp and I’m going to delete the libraries that may have been left here. So let’s change the time again, the system time before we insert Crony, we do that with date. So let’s say 04:00 p. m. , so date plus percent TS and then 16. So you see here 16. And let’s look at the hardware time again. HW clock. It’s 1913, so it’s the right time. That is the wrong time here. And yeah, now let’s let’s install Crony.

We do that with the following command apt install crony let’s see if Crony has already started. Yes, it’s running, it’s active. Let’s look what the time says and sorry, date and we see. The time has already been adjusted. Crony has taken over the time synchronization. The time is back as it should be. Let’s take a look at Crony’s configuration file. This is usually located directly in Etsy and it is called Crony conf. In the case of my Ubuntu, it is located in Etsy. Crony and then crony conf. And I think you can see at first glance that this file looks very similar to the Atpconf. Here too, we see the corresponding synchronization servers or pools, the server pools. And we also have the Ibirst option here.

We also know that from the NTP confile here too, we have a drift file. Again, it doesn’t matter that we know the entire file. Rather, at most you will be asked in the exam what is the name of the Crony configuration file and where it is located? And when you then type in at Cchronecom, then you have usually already achieved the full number of points. Okay, I’m leaving this configuration file again, and we are still looking at Crony C. As with ntpq, Crony also has an interactive mode the command is Crony C. Crony c called without parameters, starts the interactive mode. So Crony C. And here we are in the injective mode. We see the shell looks accordingly different, but I will leave it again now.

Cronyc can also be caught up directly with various options. For example, crony c tracking. With Crony C tracking we can see whether Crony is working and whether it is doing what it should. Namely synchronizing the system time. And it all looks very good. Again, of course, we don’t need to know the function of each individual line, as it is so often the case. The only thing that matters here is that we know what Crony is, what the configuration file is, where it is located and how to call the program. Let’s take a quick look, another look at the interactive mode with Crony C. And with help we can again see which commands Crony C understands. Sorry, help? Of course not help.

And we see that there are some commands here. I think you can imagine that this cannot all be the stuff of the Air pick one exam. So the complete program we can simply select server stats, for example. Then we get some statistics. But as I said, you don’t necessarily have to know that. So let’s take a look at sources, for example. And then we see the corresponding servers that are set here and so on. But as I actually said something times, we don’t actually have to go that deep. The only important thing is to know what is Crony, what does it do, what does it not do, where the configuration file is and so on. That’s it again for this category. We will see us in the next topic.