Configuring the date and time RHEL 7 (1)

Modern operating systems distinguish between the following two types of clocks:
  • A real-time clock (RTC), commonly referred to as a hardware clock, (typically an integrated circuit on the system board) that is completely independent of the current state of the operating system and runs even when the computer is shut down.
  • A system clock, also known as a software clock, that is maintained by the kernel and its initial value is based on the real-time clock. Once the system is booted and the system clock is initialized, the system clock is completely independent of the real-time clock.
The system time is always kept in Coordinated Universal Time (UTC) and converted in applications to local time as needed. Local time is the actual time in your current time zone, taking into account daylight saving time (DST). The real-time clock can use either UTC or local time. UTC is recommended.
Red Hat Enterprise Linux 7 offers three command line tools that can be used to configure and display information about the system date and time: the timedatectl utility, which is new in Red Hat Enterprise Linux 7 and is part of systemd; the traditional date command; and the hwclock utility for accessing the hardware clock.


The timedatectl utility is distributed as part of the systemd system and service manager and allows you to review and change the configuration of the system clock. You can use this tool to change the current date and time, set the time zone, or enable automatic synchronization of the system clock with a remote server.

2.1.1. Displaying the Current Date and Time

To display the current date and time along with detailed information about the configuration of the system and hardware clock, run the timedatectl command with no additional command line options:
This displays the local and universal time, the currently used time zone, the status of the Network Time Protocol (NTP) configuration, and additional information related to DST.

Example 2.1. Displaying the Current Date and Time

The following is an example output of the timedatectl command on a system that does not use NTPto synchronize the system clock with a remote server:
~]$ timedatectl
      Local time: Mon 2013-09-16 19:30:24 CEST
  Universal time: Mon 2013-09-16 17:30:24 UTC
        Timezone: Europe/Prague (CEST, +0200)
     NTP enabled: no
NTP synchronized: no
 RTC in local TZ: no
      DST active: yes
 Last DST change: DST began at
                  Sun 2013-03-31 01:59:59 CET
                  Sun 2013-03-31 03:00:00 CEST
 Next DST change: DST ends (the clock jumps one hour backwards) at
                  Sun 2013-10-27 02:59:59 CEST
                  Sun 2013-10-27 02:00:00 CET


Changes to the status of chrony or ntpd will not be immediately noticed by timedatectl. If changes to the configuration or status of these tools is made, enter the following command:

~]# systemctl restart

2.1.2. Changing the Current Time

To change the current time, type the following at a shell prompt as root:
timedatectl set-time HH:MM:SS
Replace HH with an hour, MM with a minute, and SS with a second, all typed in two-digit form.
This command updates both the system time and the hardware clock. The result it is similar to using both the date --set and hwclock --systohc commands.
The command will fail if an NTP service is enabled.

Example 2.2. Changing the Current Time

To change the current time to 11:26 p.m., run the following command as root:
~]# timedatectl set-time 23:26:00
By default, the system is configured to use UTC. To configure your system to maintain the clock in the local time, run the timedatectl command with the set-local-rtc option as root:
timedatectl set-local-rtc boolean
To configure your system to maintain the clock in the local time, replace boolean with yes (or, alternatively, y, true, t, or 1). To configure the system to use UTC, replace boolean with no (or, alternatively, n, false, f, or 0). The default option is no.

2.1.3. Changing the Current Date

To change the current date, type the following at a shell prompt as root:
timedatectl set-time YYYY-MM-DD
Replace YYYY with a four-digit year, MM with a two-digit month, and DD with a two-digit day of the month.
Note that changing the date without specifying the current time results in setting the time to 00:00:00.

Example 2.3. Changing the Current Date

To change the current date to 2 June 2013 and keep the current time (11:26 p.m.), run the following command as root:
~]# timedatectl set-time '2013-06-02 23:26:00'

2.1.4. Changing the Time Zone

To list all available time zones, type the following at a shell prompt:
timedatectl list-timezones
To change the currently used time zone, type as root:
timedatectl set-timezone time_zone
Replace time_zone with any of the values listed by the timedatectl list-timezones command.

Example 2.4. Changing the Time Zone

To identify which time zone is closest to your present location, use the timedatectl command with the list-timezones command line option. For example, to list all available time zones in Europe, type:
~]# timedatectl list-timezones | grep Europe
To change the time zone to Europe/Prague, type as root:
~]# timedatectl set-timezone Europe/Prague

2.1.5. Synchronizing the System Clock with a Remote Server

As opposed to the manual adjustments described in the previous sections, the timedatectl command also allows you to enable automatic synchronization of your system clock with a group of remote servers using the NTP protocol. Enabling NTP enables the chronyd or ntpd service, depending on which of them is installed.
The NTP service can be enabled and disabled using a command as follows:
timedatectl set-ntp boolean
To enable your system to synchronize the system clock with a remote NTP server, replace boolean with yes (the default option). To disable this feature, replace boolean with no.

Example 2.5. Synchronizing the System Clock with a Remote Server

To enable automatic synchronization of the system clock with a remote server, type:
~]# timedatectl set-ntp yes
The command will fail if an NTP service is not installed.

Changing the keyboard layout RHEL 7

The keyboard layout settings enable the user to control the layout used on the text console and graphical user interfaces.

1.2.1. Displaying the Current Settings

As mentioned before, you can check your current keyboard layout configuration with the following command:
localectl status
In the following output, you can see the keyboard layout configured for the virtual console and for the X11 window system.
~]$ localectl status
   System Locale: LANG=en_US.utf8
       VC Keymap: us
      X11 Layout: us

1.2.2. Listing Available Keymaps

To list all available keyboard layouts that can be configured on your system, type:
localectl list-keymaps

Example 1.5. Searching for a Particular Keymap

You can use grep to search the output of the previous command for a specific keymap name. There are often multiple keymaps compatible with your currently set locale. For example, to find available Czech keyboard layouts, type:
~]$ localectl list-keymaps | grep cz

1.2.3. Setting the Keymap

To set the default keyboard layout for your system, use the following command as root:
localectl set-keymap map
Replace map with the name of the keymap taken from the output of the localectl list-keymaps command. Unless the --no-convert option is passed, the selected setting is also applied to the default keyboard mapping of the X11 window system, after converting it to the closest matching X11 keyboard mapping. This also applies in reverse, you can specify both keymaps with the following command as root:
localectl set-x11-keymap map
If you want your X11 layout to differ from the console layout, use the --no-convert option.
localectl --no-convert set-x11-keymap map
With this option, the X11 keymap is specified without changing the previous console layout setting.

Example 1.6. Setting the X11 Keymap Separately

Imagine you want to use German keyboard layout in the graphical interface, but for console operations you want to retain the US keymap. To do so, type as root:
~]# localectl --no-convert set-x11-keymap de
Then you can verify if your setting was successful by checking the current status:
~]$ localectl status
   System Locale: LANG=de_DE.UTF-8
       VC Keymap: us
      X11 Layout: de
Apart from keyboard layout (map), three other options can be specified:
localectl set-x11-keymap map model variant options
Replace model with the keyboard model name, variant and options with keyboard variant and option components, which can be used to enhance the keyboard behavior. These options are not set by default.

System Locale Configuration-RHEL 7

The system locale specifies the language settings of system services and user interfaces. The keyboard layout settings control the layout used on the text console and graphical user interfaces.
These settings can be made by modifying the /etc/locale.conf configuration file or by using the localectl utility.


System-wide locale settings are stored in the /etc/locale.conf file, which is read at early boot by the systemd daemon. The locale settings configured in /etc/locale.conf are inherited by every service or user, unless individual programs or individual users override them.
The basic file format of /etc/locale.conf is a newline-separated list of variable assignments.

sudo cat /etc/locale.conf

German locale with English messages in /etc/locale.conf looks as follows:


Here, the LC_MESSAGES option determines the locale used for diagnostic messages written to the standard error output. To further specify locale settings in /etc/locale.conf

Table 1.1. Options configurable in /etc/locale.conf

Option Description
LANG Provides a default value for the system locale.
LC_COLLATE Changes the behavior of functions which compare strings in the local alphabet.
LC_CTYPE Changes the behavior of the character handling and classification functions and the multibyte character functions.
LC_NUMERIC Describes the way numbers are usually printed, with details such as decimal point versus decimal comma.
LC_TIME Changes the display of the current time, 24-hour versus 12-hour clock.
LC_MESSAGES Determines the locale used for diagnostic messages written to the standard error output.

1.1.1. Displaying the Current Status

The localectl command can be used to query and change the system locale and keyboard layout settings. To show the current settings, use the status option:
localectl status


Example 1.1. Displaying the Current Status

The output of the previous command lists the currently set locale, keyboard layout configured for the console and for the X11 window system.
~]$ localectl status
   System Locale: LANG=en_US.UTF-8
       VC Keymap: us
      X11 Layout: n/a

1.1.2. Listing Available Locales

To list all locales available for your system, type:
localectl list-locales

Example 1.2. Listing Locales

Imagine you want to select a specific English locale, but you are not sure if it is available on the system. You can check that by listing all English locales with the following command:
~]$ localectl list-locales | grep en_

output truncated

1.1.3. Setting the Locale

To set the default system locale, use the following command as root:
localectl set-locale LANG=locale
Replace locale with the locale name, found with the localectl list-locales command.

Example 1.3. Changing the Default Locale

For example, if you want to set British English as your default locale, first find the name of this locale by using list-locales. Then, as root, type the command in the following form:
~]# localectl set-locale LANG=en_GB.utf8


How does linux work?

Basics of Linux:

Linux is a multitask and multiuser operating system. Now, a little explanation of this terminology.

An operating system is a collection of programs that run in a computer so that a person can easily access the hardware and all resources of the computers. The operating system is the big program that makes your computer life easy.

multitask operating system is capable of doing several tasks at the same time.

multiuser operating sytem has a concept of “userquot;, a way to identify the person that is using the system, and can allow different users to perform different taks in the computer, and protect one user’s tasks from interfering with another user’s programs.

Some terminology:

There are a few other terms that will help you to understand the rest of the this manual:

  • shell: this is a program in the system that allows you to give the commands you want to execute. It is the basic programs that connects you to the operating sytem.
  • process: any task that you run in the system is called a process (again, a process is something a little more complex than just a task, but that definition is good enough to start).
  • file: a part of the hard disk that contains data owned by a user of the system.
  • X-windows (or simply windows): this is a mode of Linux where you screen (monitor) can be split in small “parts” called windows, that allow you to do several things at the same time (or rather change from one task to another easily) and view graphics in a nice way.
  • text terminal: by this I mean a monitor that has only the capability to display text stuff, no graphics (or perhaps a very basic graphics display).
  • session: the time you spend between logging on in the system and logging out of the system.

Linux boot process:

In many ways Linux is no different from any other operating system. It runs on the same computer, and the inner workings are the same as those that drive Windows, Linux, BSD, MacOS, etc. But there are fundamental and compounding differences from that point forward. Here we will cover how Linux works? Starting at power on, and finally reaching the desktop.

When you press the “On” button on your PC to start it, the computer wakes up the same way we do every morning. We open our eyes and check if there is anything wrong from the time we went to sleep. On a computer this is performed by the BIOS (Basic Input Output System) on the motherboard. The BIOS is the small chip that has the responsibility of identifying, checking and initializing system devices such as graphics cards, hard disks, etc.

To do this the BIOS makes a POST (Power On Self Test) and then checks which drive to use as the primary boot device. Normally this is set through the BIOS configuration screen and the first boot device can be identified as the CD-ROM, USB drive, hard disk or floppy disk. Let’s say that our system is configured to boot from CD-ROM and then Hard Disk. The BIOS checks the CD-ROM device to see if a CD/DVD resides there and is bootable. If so it boots from the CD-ROM, if not it turns to the hard disk, and hands over the control of the computer.

The boot of the operating system starts here, with the boot partition always located at the same place for all operating systems: track 0, head 0 and cylinder 0. Then the small program here, which is GRUB (GRand Unified Boot loader) or LILO (LInux LOader) performs the initialization and boot of the operating system, and since many distributions implement GRUB as their default bootloader, I will go with this one.

The configuration file (/boot/grub/grub.conf), which is used to create the list of operating systems to boot in GRUB’s menu interface, essentially allows the user to select a pre-set group of commands to execute.

It looks like below:

 # grub.conf generated by anaconda
# Note that you do not have to rerun grub after making changes to this file
# NOTICE: You have a /boot partition. This means that
# all kernel and initrd paths are relative to /boot/, eg.
# root (hd0,0)
# kernel /vmlinuz-version ro root=/dev/mapper/vg_centos-lv_root
# initrd /initrd-[generic-]version.img
title CentOS (2.6.32-642.13.1.el6.x86_64)
 root (hd0,0)
 kernel /vmlinuz-2.6.32-642.13.1.el6.x86_64 ro root=/dev/mapper/vg_centos -lv_root rd_NO_LUKS LANG=en_US.UTF-8 rd_LVM_LV=vg_centos/lv_swap rd_NO_MD SYSFON T=latarcyrheb-sun16 crashkernel=auto rd_LVM_LV=vg_centos/lv_root KEYBOARDTYPE=p c KEYTABLE=us rd_NO_DM rhgb quiet
 initrd /initramfs-2.6.32-642.13.1.el6.x86_64.img
title CentOS (2.6.32-504.8.1.el6.x86_64)
 root (hd0,0)
 kernel /vmlinuz-2.6.32-504.8.1.el6.x86_64 ro root=/dev/mapper/vg_centos- lv_root rd_NO_LUKS LANG=en_US.UTF-8 rd_LVM_LV=vg_centos/lv_swap rd_NO_MD SYSFONT =latarcyrheb-sun16 crashkernel=auto rd_LVM_LV=vg_centos/lv_root KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet
 initrd /initramfs-2.6.32-504.8.1.el6.x86_64.img
title CentOS 6 (2.6.32-504.el6.x86_64)
 root (hd0,0)
 kernel /vmlinuz-2.6.32-504.el6.x86_64 ro root=/dev/mapper/vg_centos-lv_r oot rd_NO_LUKS LANG=en_US.UTF-8 rd_LVM_LV=vg_centos/lv_swap rd_NO_MD SYSFONT=lat arcyrheb-sun16 crashkernel=auto rd_LVM_LV=vg_centos/lv_root KEYBOARDTYPE=pc KEY TABLE=us rd_NO_DM rhgb quiet
 initrd /initramfs-2.6.32-504.el6.x86_64.img

The GRUB is either in /boot/grub/menu.lst or /boot/boot/menu.lst. The menu.lst file is symlink to grub.conf. So both files are same.

Now, the GRUB knows that the kernel version 2.6.32 is to be loaded and it is in root (/) directory (the kernel is a compressed file and can decompress itself in case of a system call.) GRUB makes a call to the kernel (which is the vmlinuz-2.6.32-504.8.1.el6.x86_64 file in the configuration above) to decompress itself and start.

The kernel checks if your graphics card is there and running and if it supports complex text modes. After that it checks the hardware present on the computer (hard disks, network cards, TV cards etc.) and loads the relevant drivers. The kernel displays all the progress with informative messages during this time, as you can see in the screenshot.

After this boot stage the kernel tries to mount the file system. It tries to auto detect the file system and if it succeeds, carries on. If not, a kernel panic occurs and the system stops. If not, the kernel finally hands over the remaining job to the process named init and waits.

Init is the first process in the Linux system, with Process ID (PID) 1 and it initializes the rest of the system.

One of the most important concepts in how Linux works are the runlevels. These modes of operation allow Linux to run in V-style initialization state. After we see what is the system state in each runlevel, we continue with the initialization process in all Linux systems. Discussing the step by step process of what Linux initialization does. This will help to explain how does Linux work. Then we discuss the graphical login window, which means the system is up and running for the graphical user mode.

Linux Runlevels

Users migrating from Windows have difficulty understanding the runlevel concept in Linux. We have to understand what is a runlevel? And what does the computer do at the specified runlevel? to understand the remaining init process.

Linux is a multiuser system and it loads/halts the necessary programs to act as single user, multiuser, graphical desktop, and to halt or restart the system. The runlevels are numbered from 1 to 6 and the corresponding system states are as follows:

Runlevel 0: shutdown/halt the system

Runlevel 1: single user mode

Runlevel 2: multi user mode without network

Runlevel 3: multi user mode with network

Runlevel 4: reserved for local use (GUI mode for Slackware only)

Runlevel 5: graphical user interface (GUI) mode

Runlevel 6: reboot

There are programs that have to be started in each runlevel. These programs are listed in rcX.d files present in /etc, where X indicates the runlevel number (for example rc3.d is the file that holds information about which programs to start/stop for runlevel 3.) /etc/init.d directory holds the information to point at these files for the init to look for.

The rc3.d contains symbolic links to /etc/init.d files as:

S90crond -> ../init.d/crond

K88sssd -> ../init.d/sssd


We said the programs are started or stopped. If the computer is booting, the programs are started and preceded with S in the rcX.d files. If the computer is shutting down, they are preceded with K. ‘S’ is for ‘start’ and ‘K’ is for ‘kill’.Having all these in mind, let’s go on with the init process.

  • Init

    When the init process starts, it checks configuration files to carry on its job. First of all, it looks at the /etc/inittab which tells the init which processes to start. In the /etc/inittab file is the information about the runlevels. The default runlevel for the system is indicated by the line id:X:initdefault where X is the runlevel number.

    As you may have guessed, the runlevels have direction settings 1 -> 2 -> 3 -> 5. Meaning, if you want your computer to boot to runlevel 3, runlevel 1 programs are started, then runlevel 2 programs then runlevel 3, and the system is booted. In this scenario, runlevel 5 programs are not started.

    Then the init performs system initialization, named sysinit.

    Depending on the runlevel, init tries to figure out if it is a part of a network. Then it mounts /proc, where Linux keeps track of various processes and hardware (try cat /proc/cpuinfo at the command line), and checks the BIOS to align the system with the BIOS settings such as date and time, and sets the time zone. After that init mounts the swap partition (which Windows users know as pagefile) as defined in the /etc/fstab. When finished, it goes on to setting the hostname, which is the system’s “name” in the network. After that, it mounts the root file system (/ in Linux notation) and checks the /etc/fstab again to verify the other file systems if specified.

    Then it goes on to identify the Plug’n’Play devices in the system and makes the operating system aware of them by executing some routines. Init finally checks if there are any RAID devices in the system and verifies them. Reaching the last stages, it mounts all the file systems defined in /etc/fstab. Of course, if there are any other tasks specified in the /etc/fstab, init executes them also.

Logging in

When all of the above are completed successfully, init executes the /sbin/mingetty processes, which shows the graphical login screen of the distribution. Reaching this state means that the system is up and running in graphical user interface mode and waiting to know which user will log in.


Structure Of Linux Operating System

An operating system is a collection of software, each designed for a specific function.

Linux OS has following components:

1) Kernel

kernel is the core of the operating system. It establishes communication between devices and software. Moreover, it manages the system resources. Basically it has four responsibilities:

  • device management: A system has many devices connected to it like CPU, memory device, sound cards, graphic cards, etc. A kernel stores all the data related to all the devices in device driver (without this kernel won’t be able to control the devices). Thus kernel knows what a device can do and how to manipulate it to bring out the best performance. It also manages communication between all the devices. Kernel has certain rules that has to be followed by all the devices.
  • Memory management: Another function that kernel has to manage is the memory management. Kernel keeps a track of used and unused memory and make sure that processes shouldn’t manipulate data of each other using virtual memory address.
  • Process management: In process management kernel assign enough time and gives priorities to processes before handling CPU to other process. It also deals with security and ownership information.
  • Handling system calls: Handling system calls means a programmer can write a query or ask the kernel to perform a task.

2) System Libraries

System libraries are special programs that helps in accessing the kernel’s features. A kernel has to be triggered to perform a task and this triggering is done by the applications. But applications must know how to place a system call because each kernel has a different set of system calls. Programmers have developed standard library of procedures to communicate with kernel. Each operating system supports these standards and then these are transferred to system calls for that operating system.

Most well known system library for Linux is glibc (GNU C library).

3) System Tools

Linux OS has a set of utility tools which are usually simple commands. It is a software which GNU project has written and publish under their open source license so that software is freely available to everyone.

With the help of commands you can access your files, edit and manipulate data in your directories or files, change location of files or anything.

4) Development Tools

With the above three components your OS is running and working. But to update your system you have additional tools and libraries. These additional tools and libraries are written by the programmers and are called tool chain. A tool chain is a vital development tool used by the developers to produce a working application.

5) End User Tools

These end tools make a system unique for a user. End tools are not required for the operating system but are necessary for a user.

Some examples of end tools are graphic design tools, office suites, browsers, multimedia players, etc.

Hello World, I am linux

What is Linux?

Every desktop computer uses an operating system. The most popular operating systems in use today are:

  • Windows
  • Mac OS
  • UNIX

Linux is an operating system — very much like UNIX — that has become very popular over the last several years.

What is Operating System?

Operating systems are computer programs. An operating system is the first piece of software that the computer executes when you turn the machine on. The operating system loads itself into memory and begins managing the resources available on the computer. It then provides those resources to other applications that the user wants to execute. Typical services that an operating system provides include:

  • A task scheduler – The task scheduler is able to allocate the execution of the CPU to a number of different tasks. Some of those tasks are the different applications that the user is running, and some of them are operating system tasks. The task scheduler is the part of the operating system that lets you print a document from your word processor in one window while you are downloading a file in another window and recalculating a spreadsheet in a third window.
  • A memory manager – The memory manager controls the system’s RAM and normally creates a larger virtual memory space using a file on the hard disk.
  • A disk manager – The disk manager creates and maintains the directories and files on the disk. When you request a file, the disk manager brings it in from the disk.
  • A network manager – The network manager controls all data moving between the computer and the network.
  • Other I/O services manager – The OS manages the keyboard, mouse, video display, printers, etc.
  • Security manager – The OS maintains the security of the information in the computer’s files and controls who can access the computer.

An operating system normally also provides the default user interface for the system. The standard “look” of Windows 98 includes the Start button, the task bar, etc. The Mac OS provides a completely different look and feel for Macintosh computers.

Linux is as much a phenomenon as it is an operating system.

How was Linux created?

Linux was created in 1991 by Linus Torvalds, a then-student at the University of Helsinki. Torvalds built Linux as a free and open source alternative to Minix, another Unix clone that was predominantly used in academic settings. He originally intended to name it “Freax,” but the administrator of the server Torvalds used to distribute the original code named his directory “Linux” after a combination of Torvalds’ first name and the word Unix, and the name stuck.

Who “owns” Linux?

By virtue of its open source licensing, Linux is freely available to anyone. However, the trademark on the name “Linux” rests with its creator, Linus Torvalds. The source code for Linux is under copyright by its many individual authors, and licensed under the GPLv2 license. Because Linux has such a large number of contributors from across multiple decades of development, contacting each individual author and getting them to agree to a new license is virtually impossible, so that Linux remaining licensed under the GPLv2 in perpetuity is all but assured.