Configuring the date and time RHEL 7 (3)

hwclock is a utility for accessing the hardware clock, also referred to as the Real Time Clock (RTC). The hardware clock is independent of the operating system you use and works even when the machine is shut down. This utility is used for displaying the time from the hardware clock. hwclockalso contains facilities for compensating for systematic drift in the hardware clock.
The hardware clock stores the values of: year, month, day, hour, minute, and second. It is not able to store the time standard, local time or Coordinated Universal Time (UTC), nor set the Daylight Saving Time (DST).
The hwclock utility saves its settings in the /etc/adjtime file, which is created with the first change you make, for example, when you set the time manually or synchronize the hardware clock with the system time.

NOTE

In Red Hat Enterprise Linux 6, the hwclock command was run automatically on every system shutdown or reboot, but it is not in Red Hat Enterprise Linux 7. When the system clock is synchronized by the Network Time Protocol (NTP) or Precision Time Protocol (PTP), the kernel automatically synchronizes the hardware clock to the system clock every 11 minutes.

2.3.1. Displaying the Current Date and Time

Running hwclock with no command line options as the root user returns the date and time in local time to standard output.
hwclock
Note that using the --utc or --localtime options with the hwclock command does not mean you are displaying the hardware clock time in UTC or local time. These options are used for setting the hardware clock to keep time in either of them. The time is always displayed in local time. Additionally, using the hwclock --utc or hwclock --local commands does not change the record in the /etc/adjtime file. This command can be useful when you know that the setting saved in /etc/adjtime is incorrect but you do not want to change the setting. On the other hand, you may receive misleading information if you use the command an incorrect way. See the hwclock(8) manual page for more details.

Example 2.9. Displaying the Current Date and Time

To display the current date and the current local time from the hardware clock, run as root:
~]# hwclock
Tue 15 Apr 2014 04:23:46 PM CEST     -0.329272 seconds
CEST is a time zone abbreviation and stands for Central European Summer Time.

2.3.2. Setting the Date and Time

Besides displaying the date and time, you can manually set the hardware clock to a specific time.
When you need to change the hardware clock date and time, you can do so by appending the --set and --date options along with your specification:
hwclock --set --date "dd mmm yyyy HH:MM"
Replace dd with a day (a two-digit number), mmm with a month (a three-letter abbreviation), yyyy with a year (a four-digit number), HH with an hour (a two-digit number), MM with a minute (a two-digit number).
At the same time, you can also set the hardware clock to keep the time in either UTC or local time by adding the --utc or --localtime options, respectively. In this case, UTC or LOCAL is recorded in the /etc/adjtime file.

Example 2.10. Setting the Hardware Clock to a Specific Date and Time

If you want to set the date and time to a specific value, for example, to “21:17, October 21, 2014”, and keep the hardware clock in UTC, run the command as root in the following format:
~]# hwclock --set --date "21 Oct 2014 21:17" --utc

2.3.3. Synchronizing the Date and Time

You can synchronize the hardware clock and the current system time in both directions.
  • Either you can set the hardware clock to the current system time by using this command:
    hwclock --systohc
    Note that if you use NTP, the hardware clock is automatically synchronized to the system clock every 11 minutes, and this command is useful only at boot time to get a reasonable initial system time.
  • Or, you can set the system time from the hardware clock by using the following command:
    hwclock --hctosys
When you synchronize the hardware clock and the system time, you can also specify whether you want to keep the hardware clock in local time or UTC by adding the --utc or --localtime option. Similarly to using --set, UTC or LOCAL is recorded in the /etc/adjtime file.
The adjtime file looks like below:
0.0 0 0.0
0
UTC
The hwclock --systohc --utc command is functionally similar to timedatectl set-local-rtc false and the hwclock --systohc --local command is an alternative to timedatectl set-local-rtc true.

Example 2.11. Synchronizing the Hardware Clock with System Time

To set the hardware clock to the current system time and keep the hardware clock in local time, run the following command as root:
~]# hwclock --systohc --localtime
To avoid problems with time zone and DST switching, it is recommended to keep the hardware clock in UTC.
In case of a multi boot with a Windows system, which assumes the hardware clock runs in local time by default, and all other systems need to accommodate to it by using local time as well. It may also be needed with a virtual machine; if the virtual hardware clock provided by the host is running in local time, the guest system needs to be configured to use local time, too.

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
cz
cz-cp1250
cz-lat2
cz-lat2-prog
cz-qwerty
cz-us-qwertz
sunt5-cz-us
sunt5-us-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.

1.1. SETTING THE SYSTEM LOCALE

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
LANG="en_US.UTF-8"

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

LANG=de_DE.UTF-8
LC_MESSAGES=C

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_
en_AG
en_AG.utf8
en_AU
en_AU.iso88591
en_AU.utf8
en_BW
en_BW.iso88591
en_BW.utf8

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
#boot=/dev/sda
default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
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

NEVER SET YOUR DEFAULT RUNLEVEL TO 0, 4 OR 6!

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.

 

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.