March 2025
M T W T F S S
 12
3456789
10111213141516
17181920212223
24252627282930
31  

Categories

March 2025
M T W T F S S
 12
3456789
10111213141516
17181920212223
24252627282930
31  

CentOS / RHEL 7 : Enable NTP to start at boot after fresh install (disable chrony)

Chrony is introduced as new NTP client to replace the ntp as the default time syncing package since RHEL7, so if you configure NTP during the installation process, it just enables the chronyd service, not ntpd service.

# systemclt status ntpd.service
ntpd.service – Network Time Service
Loaded: loaded (/usr/lib/systemd/system/ntpd.service; enabled)
Active: inactive (dead)
Even when you have enabled NTP to start on boot, it will not start when chrony is enabled. So to enable NTP to start on boot, we have to disable the chrony service
In case you want to use NTP only, then below is the procedure to do so :

Please follow steps below to enable NTP service on RHEL 7:
1. Disable chronyd service.
To stop chronyd, issue the following command as root:

# systemctl stop chronyd
To prevent chronyd from starting automatically at system start, issue the following command as root:

# systemctl disable chronyd
2. Install ntp using yum:

# yum install ntp
3. Then enable and start ntpd service:

# systemctl enable ntpd.service
# systemctl start ntpd.service
4. Reboot and verify.

# systemctl status ntpd.service
ntpd.service – Network Time Service
Loaded: loaded (/usr/lib/systemd/system/ntpd.service; enabled)
Active: active (running) since Fri 2015-01-09 16:14:00 EST; 53s ago
Process: 664 ExecStart=/usr/sbin/ntpd -u ntp:ntp $OPTIONS (code=exited, status=0/SUCCESS)
Main PID: 700 (ntpd)
CGroup: /system.slice/ntpd.service
??700 /usr/sbin/ntpd -u ntp:ntp -g

CentOS / RHEL 7 : Configuring NTP using chrony

– Chrony provides another implementation of NTP.
– Chrony is designed for systems that are often powered down or disconnected from the network.
– The main configuration file is /etc/chrony.conf.
– Parameters are similar to those in the /etc/ntp.conf file.
– chronyd is the daemon that runs in user space.
– chronyc is a command-line program that provides a command prompt and a number of commands. Examples:
tracking: Displays system time information
sources: Displays information about current sources.

Installing Chrony

Install the chrony package by using the following command:

# yum install chrony
Use the following commands to start chronyd and to ensure chronyd starts at boot time:

# systemctl start chronyd
# systemctl enable chronyd
Configuring Chrony

A sample configuration would look like below :

# cat /etc/chrony.conf
server a.b.c offline
server d.e.f offline
server g.h.i offline
keyfile /etc/chrony.keys generatecommandkey
driftfile /var/lib/chrony/drift makestep 10 3
The parameters are described as follows:
server: Identifies the NTP servers you want to use. The offline keyword indicates that the servers are not contacted until chronyd receives notification that the link to the Internet is present.
keyfile: File containing administrator password. Password allows chronyc to log in to chronyd and notify chronyd of the presence of the link to the Internet.
generatecommandkey: Generates a random password automatically on the first chronyd start.
driftfile: Location and name of file containing drift data.
makestep: Step (start anew) system clock if a large correction is needed. The parameters 10 and 3 would step the system clock if the adjustment is larger than 10 seconds, but only in the first three clock updates.

Although, all these parameters are not required. For this post purpose I am using only below two lines in the configuration file.

# cat /etc/chrony.conf
server 192.0.2.1
allow 192.0.2/24
Starting chrony

Use the systemctl command to start the chrony daemon, chronyd.

# systemctl start chronyd
Verify

To check if chrony is synchronized, use the tracking, sources, and sourcestats commands. Run the chronyc tracking command to check chrony tracking. Alternatively you could run chronyc to display a chronyc> prompt, and then run the tracking command from the chronyc> prompt.

# chronyc tracking
Reference ID : 192.0.2.1 (192.0.2.1)
Stratum : 12
Ref time (UTC) : Fri Aug 05 19:06:51 2016
System time : 0.000823375 seconds fast of NTP time
Last offset : 0.001989304 seconds
RMS offset : 0.060942811 seconds
Frequency : 1728.043 ppm slow
Residual freq : 1.100 ppm
Skew : 94.293 ppm
Root delay : 0.000207 seconds
Root dispersion : 0.016767 seconds
Update interval : 65.1 seconds
Leap status : Normal
Some of the important fields are :
Reference ID: This is the reference ID and name (or IP address) if available, of the server to which the computer is currently synchronized.
Stratum: The stratum indicates how many hops away from a computer with an attached reference clock you are.
Ref time: This is the time (UT C) at which the last measurement from the reference source was processed.

Run the chronyc sources command to display information about the current time sources that chronyd is accessing.

# chronyc sources
210 Number of sources = 1
MS Name/IP address Stratum Poll Reach LastRx Last sample
=============================================================================
^* 192.0.2.1 11 6 377 63 +1827us[+6783us]…
Some of the fields are described:
M: The mode of the source. ^ means a server, = means a peer, and # indicates
a locally connected reference clock.
S: The state of the sources. “*” indicates the source to which chronyd is currently synchronized. “+” indicates acceptable sources that are combined with the selected source. “-” indicates acceptable sources that are excluded by the combining algorithm. “?” indicates sources to which connectivity has been lost or whose packets do not pass all tests. “x” indicates a clock that chronyd thinks is a false ticker, that is, its time is inconsistent with a majority of other sources. “~” indicates a source whose time appears to have too much variability. The “?” condition is also shown at start-up, until at least three samples have been gathered from it.
Name/IP address: This shows the name or the IP address of the source, or reference ID for reference clocks.

Run the chronyc sourcestats command. This command displays information about the drift rate and offset estimation
process for each of the sources currently being examined by chronyd.

# chronyc sourcestats
210 Number of sources = 1
Name/IP Address NP NR Span Frequency Freq Skew Offset Std Dev
==================================================================================
192.0.2.1 5 4 259 -747.564 1623.869 -2873us 30ms
Stop chrony

Use the systemctl command to stop the chrony daemon, chronyd.

# systemctl stop chronyd
Run the chronyc tracking command and notice chronyc cannot talk to the chronyd daemon.

# chronyc tracking
506 Cannot talk to daemon

CentOS / RHEL 7 : Tips on Troubleshooting NTP / chrony Issues

The chrony service does not change the time
The often misconception is that the chrony service is setting the time to the one given by the NTP server. This is incorrect – what actually happens is that based on the answer from the NTP server, chrony just tells the system clock to go faster or slower. For this reason, sometimes even though the time is wrong and the NTP server is working, the time does not get corrected immediately.
Only time when chrony sets time

When the chrony service starts, there are some settings in the /etc/chrony/chrony.conf file that tells it to actually set the time if specific conditions occur:

# Force system clock correction at boot time.
makestep 1000 10
which means that if chrony detects during the first 10 measurements after its start that the time is off by more than 1000 seconds it will set the clock.

Some useful commands

Below are some useful commands which can be used for the troubleshooting of chrony related issues.

# chronyc tracking
# chronyc sources
# chronyc sourcestats
# systemctl status chronyd
# chronyc activity
# timedatectl
Check chronyd status

To check the status of the chronyd daemon :

# systemctl status -l chronyd
? chronyd.service – NTP client/server
Loaded: loaded (/usr/lib/systemd/system/chronyd.service; enabled; vendor preset: enabled)
Active: active (running) since Fri 2016-08-12 13:22:22 IST; 1s ago
Process: 33263 ExecStartPost=/usr/libexec/chrony-helper update-daemon (code=exited, status=0/SUCCESS)
Process: 33259 ExecStart=/usr/sbin/chronyd $OPTIONS (code=exited, status=0/SUCCESS)
Main PID: 33261 (chronyd)
CGroup: /system.slice/chronyd.service
??33261 /usr/sbin/chronyd

Aug 12 13:22:22 NVMBD1S11BKPMED03 systemd[1]: Starting NTP client/server…
Aug 12 13:22:22 NVMBD1S11BKPMED03 chronyd[33261]: chronyd version 2.1.1 starting (+CMDMON +NTP +REFCLOCK +RTC +PRIVDROP +DEBUG +ASYNCDNS +IPV6 +SECHASH)
Aug 12 13:22:22 NVMBD1S11BKPMED03 chronyd[33261]: Frequency 0.000 +/- 1000000.000 ppm read from /var/lib/chrony/drift
Aug 12 13:22:22 NVMBD1S11BKPMED03 systemd[1]: Started NTP client/server.
The chronyc sources command

Running chronyc sources -v shows the current state of the NTP server/s configured in the system. Here is an example output, in which ntp.example.com shows as a valid server which is online:

# chronyc sources -v
210 Number of sources = 1

.– Source mode ‘^’ = server, ‘=’ = peer, ‘#’ = local clock.
/ .- Source state ‘*’ = current synced, ‘+’ = OK for sync, ‘?’ = unreachable,
| / ‘x’ = time may be in error, ‘~’ = time is too variable.
|| .- xxxx [ yyyy ] +/- zzzz
|| / xxxx = adjusted offset,
|| Log2(Polling interval) -. | yyyy = measured offset,
|| \ | zzzz = estimated error.
|| | |
MS Name/IP address Stratum Poll LastRx Last sample
============================================================================
^* ntp.example.com 3 6 40 +31us[ -98us] +/- 118ms
Note that a Source state different than ‘*’ usually indicates a problem with the NTP server.

Source state ‘~’ means that the time is too variable
If the Source state is ‘~‘, it probably means that the server is accessible but the time is too variable. This can happen if the server responds too slow or responds sometimes slower and sometimes faster. You could check the response time of the pings to the server to see if they are slow or variable. This state has also been noticed when the server is running on virtual machines which are too slow causing timing issues.

Chrony check and restart every hour

Once an hour, the chrony service checks the output of the chronyc sources -v command, by running script /usr/sbin/palladion_chrony_healthcheck which runs /usr/sbin/palladion_check_chrony and checks its output:

if /usr/sbin/palladion_check_chrony returns 1 – it means there was no online source (no source with Source state = ‘*’) , so chrony restarts in an attempt to re-initialize the server status
if /usr/sbin/palladion_check_chrony returns 0 – this means everything is ok, chrony does not need to be restarted because it already has a valid online source
# cat /etc/cron.d/chrony
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
#
# Check chrony every hour and restart if necessary.
#
16 * * * * root /usr/sbin/palladion_chrony_healthcheck
Chrony logs

There are several chrony logs that can be used to troubleshoot. Most of them are located in /var/log/chrony/. Note that the latest file is not always the *.log one. Sometimes it happens that even the *.log.2 or *.log.3 file are the ones that are more recent. Here is an example of listing the files with sorting by the most recent:

# ls -lisaht /var/log/chrony/
total 1.5M
3801115 580K -rw-r–r– 1 root root 574K Oct 21 14:56 measurements.log.3
3801131 544K -rw-r–r– 1 root root 540K Oct 21 14:56 statistics.log.3
3801166 356K -rw-r–r– 1 root root 350K Oct 21 14:56 tracking.log.3
3801089 4.0K drwxr-xr-x 16 root root 4.0K Oct 21 00:01 ..
3801114 4.0K drwxr-xr-x 2 root root 4.0K Oct 21 00:01 .
3801128 0 -rw-r–r– 1 root root 0 Oct 21 00:01 tracking.log
3801110 0 -rw-r–r– 1 root root 0 Oct 21 00:01 measurements.log
3801120 0 -rw-r–r– 1 root root 0 Oct 21 00:01 statistics.log
3801167 0 -rw-r–r– 1 root root 0 Oct 20 00:01 tracking.log.1
3801165 0 -rw-r–r– 1 root root 0 Oct 20 00:01 statistics.log.1
3801159 0 -rw-r–r– 1 root root 0 Oct 20 00:01 measurements.log.1
…………
Try setting only one NTP server by entering its IP address

If until now you have been using two or more NTP servers (either because they were set or because you entered an FQDN that resolves in different IP addresses), try to set one single NTP server by entering only one IP address. This may solve your NTP related issue.

Tracing the communication with the NTP server

To double check if the NTP server is answering or not, it is possible to trace the traffic between chrony and the NTP server for a period of time while monitoring the server:
1. Start a pcap trace with tcpdump on the NTP port 123 and leave it running until the issue appears (run it in ‘screen’ or with ‘nohup’ to avoid it from being stopped if you disconnect from the shell command)
2. As soon as the issue re-appears, get a System Diagnostics covering the entire history since you have set the server to DNS name until the gap reoccurred. If this produces a file that is too big, just get the System Diagnostics for Current data and in addition copy all the files from /var/log/chrony/, and all files called /var/log/syslog* . Remember to stop the trace you started at step 1

RHEL 7 – RHCSA Notes – input / output redirection

Three standard file descriptors :

1. stdin 0 – Standard input to the program.
2. stdout 1 – Standard output from the program.
3. stderr 2 – Standard error output from the program.
PURPOSE COMMAND
redirect std output to filename > filename or 1> filename
append std out to filename >> filename
append std out and std err to filename >> filename 2>&1 or 1>> filename 2>&1
take input from filename < filename or 0 < filename redirect std error to filename 2> filename
redirect std out and std error to filename 1> filename 2>&1 or > filename 2>&1
Some examples of using I/O redirection

# cat goodfile badfile 1> output 2> errors
This command redirects the normal output (contents of goodfile) to the file output and sends any errors (about badfile not existing, for example) to the file errors.

# mail user_id < textfile 2> errors
This command redirects the input for the mail command to come from file textfile and any errors are redirected to the file errors.

# find / -name xyz -print 1> abc 2>&1
This command redirects the normal output to the file abc. The construct “2>&1” says “send error output to the same place we directed normal output”.

Note that the order is important; command 2>&1 1>file does not do the same as command 1>file 2>&1. This is because the 2>&1 construction means redirect standard error to the place where standard output currently goes. The construction command 2>&1 1>file will first redirect standard error to where standard output goes (probably the terminal, which is where standard error goes by default anyway) then will redirect standard output to file. This is probably not what was intended.
# ( grep Bob filex > out ) 2> err
– any output of the grep command is sent to the file out and any errors are sent to the file err.

# find . -name xyz -print 2>/dev/null
This runs the find command, but sends any error output (due to inaccessible directories, for example), to /dev/null. Use with care, unless error output really is of no interest.

CentOS / RHEL 7 : Configuring static IP adress using network interface configuration files

There are various ways you can configure an IP address in RHEL 7. The posts discusses the use of network interface configuration files to configure the IP address. Each physical network device has an associated network interface configuration file. Network interface configuration files are located in the /etc/sysconfig/network-scripts directory.

1. Use the ip addr command to display your available network interfaces.

# ip addr
1: lo: [LOOPBACK,UP,LOWER_UP] mtu 65536 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: [BROADCAST,MULTICAST,UP,LOWER_UP] mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:50:56:23:2f:bc brd ff:ff:ff:ff:ff:ff
inet 192.168.43.104/24 brd 192.168.43.255 scope global dynamic eth0
valid_lft 2792sec preferred_lft 2792sec
inet6 2405:204:10a:6c1:250:56ff:fe23:2fbc/64 scope global
valid_lft forever preferred_lft forever
inet6 fe80::250:56ff:fe23:2fbc/64 scope link
valid_lft forever preferred_lft forever
3: eth1: [BROADCAST,MULTICAST,UP,LOWER_UP] mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:d5:6e:a6 brd ff:ff:ff:ff:ff:ff
Note that you have 3 Ethernet interfaces (eth0, eth1) and the loopback interface (lo). If you interface names are somthing like eno16777736, refere this post to change the interface naming to eth0 and eth1.

2. cd into the /etc/sysconfig/network-scripts directory which holds the network interface configuration files.

# cd /etc/sysconfig/network-scripts
Here you would find the network configuration file for the eth1 interface i.e. ifcfg-eth1. If not already present you can copy the interface configuration file of interface eth0.

3. We want to assign IP address 192.168.1.30 to the interface eth1. Edit the configuration file for the interface and change the highlighted parameters as show below :

# vi ifcfg-eth1
TYPE=”Ethernet”
BOOTPROTO=”none”
DEFROUTE=”no”
IPV4_FAILURE_FATAL=”no”
IPV6INIT=”yes”
IPV6_AUTOCONF=”yes”
IPV6_DEFROUTE=”yes”
IPV6_FAILURE_FATAL=”no”
NAME=”eno16777736″
UUID=”7fe712d2-5e3a-4f68-b34b-4b3f6c787a56″
ONBOOT=”yes”
IPADDR0=”192.168.1.30″
PREFIX0=”24″
HWADDR=”00:0C:29:D5:6E:9C”
IPV6_PEERDNS=”yes”
IPV6_PEERROUTES=”yes”
4. Edit the /etc/hosts file to add the entry for the new IP address :

# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.1.30 geeklab
5. Restart the network services :

# systemctl restart network
# ip addr
1: lo: [LOOPBACK,UP,LOWER_UP] mtu 65536 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: [BROADCAST,MULTICAST,UP,LOWER_UP] mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:50:56:23:2f:bc brd ff:ff:ff:ff:ff:ff
inet 192.168.43.104/24 brd 192.168.43.255 scope global dynamic eth0
valid_lft 2538sec preferred_lft 2538sec
inet6 2405:204:10a:6c1:250:56ff:fe23:2fbc/64 scope global
valid_lft forever preferred_lft forever
inet6 fe80::250:56ff:fe23:2fbc/64 scope link
valid_lft forever preferred_lft forever
3: eth1: [BROADCAST,MULTICAST,UP,LOWER_UP] mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:d5:6e:a6 brd ff:ff:ff:ff:ff:ff
inet 192.168.1.30/24 brd 192.168.1.255 scope global eth1
valid_lft forever preferred_lft forever
inet6 fe80::20c:29ff:fed5:6ea6/64 scope link
valid_lft forever preferred_lft forever
Using network interface control scripts to stop/start a specific network interface

The network interface control scripts i.e. ifup and ifdown. Use the ifdown command to stop the interface and eno16777736. Verify the status of the interface using “if addr” command (the ip address should have disappeared):

# ifdown eth1
# ip a
1: lo: [LOOPBACK,UP,LOWER_UP] mtu 65536 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: [BROADCAST,MULTICAST,UP,LOWER_UP] mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:50:56:23:2f:bc brd ff:ff:ff:ff:ff:ff
inet 192.168.43.104/24 brd 192.168.43.255 scope global dynamic eth0
valid_lft 2751sec preferred_lft 2751sec
inet6 2405:204:10a:6c1:250:56ff:fe23:2fbc/64 scope global
valid_lft forever preferred_lft forever
inet6 fe80::250:56ff:fe23:2fbc/64 scope link
valid_lft forever preferred_lft forever
3: eth1: [BROADCAST,MULTICAST,UP,LOWER_UP] mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:d5:6e:a6 brd ff:ff:ff:ff:ff:ff
Use the ifup command to start the interface again :

# ifup eth1
# ip addr
1: lo: [LOOPBACK,UP,LOWER_UP] mtu 65536 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: [BROADCAST,MULTICAST,UP,LOWER_UP] mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:50:56:23:2f:bc brd ff:ff:ff:ff:ff:ff
inet 192.168.43.104/24 brd 192.168.43.255 scope global dynamic eth0
valid_lft 2720sec preferred_lft 2720sec
inet6 2405:204:10a:6c1:250:56ff:fe23:2fbc/64 scope global
valid_lft forever preferred_lft forever
inet6 fe80::250:56ff:fe23:2fbc/64 scope link
valid_lft forever preferred_lft forever
3: eth1: [BROADCAST,MULTICAST,UP,LOWER_UP] mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:d5:6e:a6 brd ff:ff:ff:ff:ff:ff
inet 192.168.1.30/24 brd 192.168.1.255 scope global eth1
valid_lft forever preferred_lft forever
inet6 fe80::20c:29ff:fed5:6ea6/64 scope link
valid_lft forever preferred_lft forever

CentOS / RHEL 7 : How to Install GUI

For new installation of RHEL 7 ,GUI doesn’t come with default installation.
If you do not click on the “Software Selection” link and pick “server with GUI” then there will be no GUI after reboot, only “Base Environment ” will be installed.

To enable GUI after system installation, you can use following method.

Installing the environment group “Server with GUI”

1. Check the available environment groups :

]# yum grouplist
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
There is no installed groups file.
Maybe run: yum groups mark convert (see man yum)
Available Environment Groups:
Minimal Install
Infrastructure Server
File and Print Server
Basic Web Server
Virtualization Host
Server with GUI
Available Groups:
Compatibility Libraries
Console Internet Tools
Development Tools
Graphical Administration Tools
Legacy UNIX Compatibility
Scientific Support
Security Tools
Smart Card Support
System Administration Tools
System Management
Done
2. Execute the following to install the environments for GUI.

# yum groupinstall “Server with GUI”
…….
Transaction Summary
====================================================
Install 199 Packages (+464 Dependent packages)
Upgrade ( 8 Dependent packages)

Total download size: 523 M
Is this ok [y/d/N]:
The above will install the GUI in RHEL 7, which by default get installed to text mode.

3. Enable GUI on system start up. In RHEL 7, systemd uses ‘targets’ instead of runlevels. The file /etc/inittab is no more used to change run levels. Issue the following command to enable the GUI on system start.

To set a default target :

# systemctl set-default graphical.target
To change the current target to graphical without reboot :

# systemctl start graphical.target
Verify the default target :

# systemctl get-default
graphical.target
4. Reboot the machine to verify that it boots into GUI directly.

# systemctl reboot
Installing core GNOME packages

“Server with GUI” installs the default GUI which is GNOME. In case if you want to install only core GNOME packages use :

# yum groupinstall ‘X Window System’ ‘GNOME’
….
Transaction Summary
===========================================================
Install 104 Packages (+427 Dependent packages)
Upgrade ( 8 Dependent packages)

Total download size: 318 M
Is this ok [y/d/N]:y

CentOS / RHEL 7 : How to extract initramfs image and edit/view it

In some cases you may want to extract the initramfs image file to check built-in contents. This post provides steps to extract initramfs image files for RHEL 7. Unlike previous version, on RHEL 7 using cpio command for the initramfs image file will not extract all files (or will give some error). For example:

# ls -la /boot/initramfs-$(uname -r).img
-rw——- 1 root root 19602671 Feb 4 2016 /boot/initramfs-3.10.0-229.el7.x86_64.img
# file initramfs-3.10.0-229.el7.x86_64.img
initramfs-3.10.0-229.el7.x86_64.img: gzip compressed data, from Unix, last modified: Thu Feb 4 16:02:04 2016, max compression
# gzip -dc initramfs-3.10.0-229.el7.x86_64.img | cpio -id — will not extract all files or will give some error
To extract it on RHEL7, use skipcpio:
1. copy the initramfs image file to some directory.

# mkdir /tmp/initramfs
# cp /boot/initramfs-3.10.0-229.el7.x86_64.img
2. extract the contents using the /usr/lib/dracut/skipcpio command :

# cd /tmp/initramfs
# /usr/lib/dracut/skipcpio initramfs-3.10.0-229.el7.x86_64.img | zcat | cpio -ivd
.
var
var/lock
var/run
lib
where skipcpio is the built-in tool from dracut.

Listing the content of initramfs image

To only list the contents of an initramfs image file, you can run lsinitrd:

# lsinitrd /boot/initramfs-3.10.0-229.el7.x86_64.img | more
Image: /boot/initramfs-3.10.0-229.el7.x86_64.img: 19M
========================================================================
Version: dracut-033-359.el7

Arguments: -f

dracut modules:
bash
nss-softokn
i18n
network
ifcfg
drm
plymouth
dm
kernel-modules
lvm
resume
rootfs-block
terminfo
udev-rules
biosdevname
systemd
usrmount
base
fs-lib
shutdown
========================================================================
drwxr-xr-x 12 root root 0 May 23 10:27 .
crw-r–r– 1 root root 5, 1 May 23 10:27 dev/console
crw-r–r– 1 root root 1, 11 May 23 10:27 dev/kmsg
crw-r–r– 1 root root 1, 3 May 23 10:27 dev/null

CentOS / RHEL 7 : Beginners guide to systemd service units

Previous versions of Oracle Linux use init scripts located in the /etc/rc.d/init directory to start and stop services. In RHEL 7, these init scripts have been replaced with systemd service units. Service units have a .service extension. Use the systemctl command to list all loaded service units:

# systemctl list-units –type service –all
UNIT LOAD ACTIVE SUB DESCRIPTION
auditd.service loaded active running Security Auditing Service
avahi-daemon.service loaded active running Avahi mDNS/DNS-SD Stack
…..
Here,
LOAD – service load state
high-level (ACTIVE) and low-level (SUB) unit activation state
DESCRIPTION – description of the service unit.

Omit the –all option to list only the active service units. Use the list-unit-files option to see which service units are enabled:

# systemctl list-unit-files –type service

Displaying status of the services

systemd service units correspond to system services. Use the following command to display detailed information about a service unit. This example displays information about the sshd service unit.

# systemctl status sshd

The following information is available for the specified service unit:

Loaded: If the service is loaded, the absolute path to the service unit file, and if the
service unit is enabled
Active: If the service unit is running and a timestamp
Main PID: The Process ID of the corresponding system service and the service name
Status: Additional information about the corresponding system service
Process: Additional information about related processes
CGroup: Additional information about related Control Groups
To check whether a service is running (active) or not running (inactive):

# systemctl is-active sshd
active
To check whether a service is enabled:

# systemctl is-enabled sshd
enabled
Starting and Stopping Services

In previous versions of RHEL, the service utility is used to stop and start services. In RHEL 7, the systemctl utility provides an equivalent set of subcommands. The table below shows a comparison of the service utility with systemctl.

SERVICE UTILITY SYSTEMCTL UTILITY DESCRIPTION
service name start systemctl start name Starts a service
service name stop systemctl stop name Stops a service
service name restart systemctl restart name Restarts a service
service name condrestart systemctl try- restart name Restarts a service only if it is running
service name reload systemctl reload name Reloads a configuration
service name status systemctl status name Checks whether a service is running
service –status- all systemctl list-units –type service –all Displays the status of all services
Enabling and disabling services

In previous versions of RHEL, the chkconfig utility is used to enable and disable services. In RHEL 7, the systemctl utility provides an equivalent set of subcommands. The table below shows a comparison of the chkconfig utility with systemctl.

CHKCONFIG UTILITY SYSTEMCTL UTILITY DESCRIPTION
chkconfig name on systemctl enable name Enables a service
chkconfig name off systemctl disable name Disables a service
chkconfig –list name systemctl status name, systemctl is-enabled name Checks whether a service is enabled
chkconfig –list systemctl list-unit-files –type service Lists all services and checks whether they are enabled

RHEL 7 – RHCSA Notes : Configure a system to use time services

RHEL 7 has 3 command-line utilities to configure the system date and time:
1. date
2. hwclock
3. timedatectl

date command

Use the date command to display or set the system date and time. Run the date command with no arguments to display the current date and time:

# date
Mon Sep 12 19:41:40 IST 2016
The date command provides a variety of output formatting options. You can also time and date in future or past. Few examples are given below.
1. Display day of the week :

# date +%A
Monday
2. Display date one year from now :

# date -d “1 year”
Mon Sep 12 19:47:49 IST 2017
3. Display 1 month past date :

# date -d “1 month ago”
Mon Aug 12 19:49:07 IST 2016
Use the following syntax to change the current date. Replace YYYY with a four-digit year, MM with a two-digit month, and DD with a two-digit day of the month.

# date +%D -s [YYYY-MM-DD]
Use the following syntax to change the current time. Replace HH with a two-digit hour, MM with a two-digit minute, and SS with a two-digit second. Include either AM or PM. Include the –u option if your system clock is set to use UTC.

# date +%T%p -s [HH:MM:SS]AM|PM –u
hwclock command

Use the hwclock command to query and set the hardware clock, also known as the RTC (real-time clock). This clock runs independently of any control program running in the CPU and even when the machine is powered off. The hwclock command allows you to:

Display the current time
Set the hardware clock to a specified time
Set the system time from the hardware clock (hwclock –s)
Set the hardware clock to the current system time (hwclock –w)
timedatectl command

– The timedatectl utility is part of the systemd system and service manager.
– To display local, universal, and RTC time and time zone, NTP configuration, and DST information:

# timedatectl
Local time: Tue 2016-09-13 20:30:26 IST
Universal time: Tue 2016-09-13 15:00:26 UTC
RTC time: Tue 2016-09-13 15:00:26
Time zone: Asia/Kolkata (IST, +0530)
NTP enabled: yes
NTP synchronized: yes
RTC in local TZ: no
DST active: n/a
– Use the following syntax to change the date and time:

# timedatectl set-time [YYYY-MM-DD]
# timedatectl set-time [HH:MM:SS]
– Use the following syntax to change the time zone:

# timedatectl set-timezone [time_zone]
– To list available time zones :

# timedatectl list-timezones
Africa/Abidjan
Africa/Accra
Africa/Addis_Ababa
– To enable clock synchronization over NTP:

# timedatectl set-ntp yes
Using NTP

NTP provides a method of verifying and correcting your computer’s time by synchronizing it with another system.
To install NTP :

# yum install ntp
By default, there are four public server entries in the NTP configuration file, /etc/ntp.conf, which are specified by the server directive.

# grep server /etc/ntp.conf
server 0.rhel.pool.ntp.org
server 1.rhel.pool.ntp.org
server 2.rhel.pool.ntp.org
server 3.rhel.pool.ntp.org
Instead of using a predefined public server, you can specify a local reference server in the /etc/ntpd.conf file. For example:

# vi /etc/ntpd.conf
server 192.0.2.1
Another directive in the configuration file is driftfile. The default setting is as follows:

driftfile /var/lib/ntp/drift
This drift file contains one value used to adjust the system clock frequency after every system or service start.

NTP daemon

The ntpd program is the user space daemon that synchronizes the system clock with remote NTP time servers or local reference clocks. The daemon reads the configuration file at system start or when the service is restarted. You also need to open UDP port 123 in the firewall for NTP packets. After editing the /etc/ntp.conf file, use the systemctl command to start the NTP daemon:

# systemctl start ntpd
Use the following command to ensure the NTP daemon starts at boot time:

# systemctl enable ntpd
Other NTP utilities

Use the ntpq command to query the NTP daemon operations and to determine performance. Use the –p option (or peers command) to display a list of peers known to the server as well as a summary of their state. For example:

# ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
*10.10.0.2 192.168.2.11 2 u 911 1024 377 1.274 0.147 0.355
+10.10.0.3 192.168.2.11 2 u 1026 1024 377 1.161 0.073 0.852
The * indicates your system is synchronized with the 10.10.0.2 server. Use the ntpstat command to show network time synchronization status.

# ntpstat
synchronised to NTP server (10.10.0.2) at stratum 3
time correct to within 31 ms
polling server every 1024 s
Configuring NTP using chrony

Chrony is a suite of utilities that provides another implementation of NTP. Chrony is designed for mobile systems and virtual machines that are often powered down or disconnected from the network. Systems that are not permanently connected to a network take a relatively long time to adjust their system clocks with the NTP daemon, ntpd.

Chrony consists of chronyd, a daemon that runs in user space, and chronyc, a command- line program for making adjustments to chronyd. The chronyd daemon makes adjustments to the system clock that is running in the kernel. It uses NTP to synchronize with another system when network access is available. When network access is not available, chronyd uses the last calculated drift stored in the drift file to synchronize the system time.

For more information on chrony (installation, configuration, troubleshooting), refer the below posts :

RHEL 7 – RHCSA Notes : Create, delete, and modify local groups and group memberships.

Group administration

– Use the groupadd command to add a new group :

# groupadd [options] group_name
– Use the groupmod command to modify an existing group :

# groupmod [options] group_name
– Use groupdel to delete the group. You can remove a group even if there are users in the group. But you can not remove the primary group of an existing user. You must remove the user before removing the group.

# groupdel group_name
– Use the gpasswd command to administer the groups :

# gpasswd [options] group_name
For example : to add user test in group student –

# gpasswd -a test student
groups command

The groups command displays the group the user belongs to. For example the user oracle as shown below belongs to multiple groups which can be displayed using the groups command :

# groups oracle
oracle : oinstall dba asm asmdba oper
# grep oracle /etc/group
oinstall:x:5004:oracle
dba:x:5005:oracle
asm:x:5006:oracle
asmdba:x:5007:oracle
oper:x:5008:oracle
newgrp command

The newgroup command executes a new shell and changes a user’s real group information. For example,
Before executing newgrp command

$ id
uid=5004(oracle) gid=5004(oinstall) groups=5004(oinstall),5005(dba) …
$ ps
PID TTY TIME CMD
106591 pts/0 00:00:00 bash
106672 pts/0 00:00:00 ps
After executing newgrp command

$ newgrp dba
Note the gid for the user has changed to that of the student group :

$ id
uid=5004(oracle) gid=5005(dba) groups=5005(dba),5004(oinstall) …
Also note that a new shell has been executed.

$ ps
PID TTY TIME CMD
106591 pts/0 00:00:00 bash
106231 pts/0 00:00:00 bash
106672 pts/0 00:00:00 ps