Posts in Category: rhcsa

Creating Partitions on CentOS/RHEL 7

A block devices is usually a physical device that’s used for storing data, e.g. Hard drives and solid state drives. A partition is basically a way to organise a block device’s storage into smaller segments, that means creating partitions allows you to use a percentage of your block device’s storage space for a specific purpose and leave the rest available for other uses. If you want to use all the storage of a block device for a particular purpose, then you don’t need to create partitions.

A partition can be used in lots of different ways. One of the common ways is to use it as an ordinary filesystem. There are 3 steps you can do this:

  1. Create the partition – this is done using the “fdisk” tool. We’ll cover how to

Formatting storage devices on CentOS/RHEL 7

A storage device is a term used loosely to mean anything that’s used for storing data. Storage devices comes in various forms, but they most commonly in the form of a partition (e.g. /dev/sdb2), or an unpartitioned block device (e.g. /dev/sdc), or a logical volume (e.g. /dev/mapper/centos-home). Before you can start storing data in storage device, you first need to:

  1. Format the storage device – Aka install a filesystem.
  2. Mount the filesystem – Attach the filesystem to a folder on your system

File system types

There are several main filesystem types that are available:

  • XFS – This is now the default filesystem in RHEL 7.
  • Ext4 – This used to be the default file system up to and including RHEL 6
  • vfat – This is typically used for removable media, e.g. USB pens

To view a complete


How to mount a filesystem on CentOS/RHEL 7

To start storing data on a block device (e.g. a partition, logical volume, or antire storage device) you first need to install a filesystem on the block device. After that you then need to mount the filesystem. Mounting a filesystem is simply the act of associating a directory (aka a mount point) to a filesystem. Any files/folders that are then put inside this mountpoint folder will actually end up getting stored on the underlying block device that’s hosting the filesystem. You can view which filesystems are attached to which mountpoint using lsblk:

$ lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda               8:0   															

Linux Processes – Finding and Viewing Processes on CentOS/RHEL 7

In linux there are lots of processes running, there are a number of commands available to find and view these processes. To get a full list, we use the ps command:

The following command gives a complete list of all the processes that are currently running:

$ ps aux
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.0  0.4  59744  4848 ?        Ss   May01   0:05 /usr/lib/systemd/systemd --switched-root --system --deserialize 24
root         2  0.0  0.0     															

Processes – Finding/Killing processes on CentOS/RHEL 7

One thing you may want to do is to find and stop a process. There are a few ways to do this, but they all involve sending a process a “signal”. A signal is an instruction that can be sent to a process. Processes aren’t allowed to ignore an incoming signal.

There’s a standard set of signals you can send to a process. The kill command let’s you view the full list of available signals:

$ kill -l
 1) SIGHUP       2) SIGINT       3) SIGQUIT      4) SIGILL       5) SIGTRAP
 6) SIGABRT      7) SIGBUS       8) SIGFPE    															

Linux Processes – Setting process priorities by setting nice values on CentOS/RHEL 7

Changing a process’s priority is a good way to make your machine run more efficiently. Changing process priorities is to do with increasing/decreasing how much CPU time a process can have while the machine is running. For example if you are setting up a machine to primarily run as a web server, then it is a good idea to elevate the web-server related processes so that they get more access to the CPU.

modifying the priority is to do with changing a process’s “nice” settings. The nice setting takes a value from -20 to +19, where -20 is the highest priority…and…+19 is the lowest priority. Hence the higher the nice value, the more “nice” a process is in allowing other processes to spend more time with the cpu.

You can view the


GRUB2 – Resetting the root password on CentOS/RHEL 7

If you have forgotten what your CentOS/RHEL system’s root password is, then you need to reset your machine’s root password. Resetting the root password requires rebooting your CentOS 7 machine, and then edit the GRUB parameters during boot time.

During machine boot, you might think that you would need to edit the grub parameters just so to enter the rescue/emergency targets. However that approach doesn’t work because you still need to enter the root password as part of entering the rescue/emergency targets.

That’s why we take a different approach to reset the root password. When you machine is booting up:

  1. Press down then up arrow keys as soon as the kernel selection menu appears. This will pause the boot process
  2. press “e” in order to edit your grub parameter settings.
  3. Scroll down

Systemd – The anatomy of a unit file

A unit is a resource that systemd can manage. There are different types of units:

$ systemctl -t help
Available unit types:
service
socket
busname
target
snapshot
device
mount
automount
swap
timer
path
slice
scope   

These units are represented in the form of files, referred ‘unit files’. These files are located in /usr/lib/systemd/system directory. These files are named after the type of unit they represent.The structure of a unit file varies slightly from one unit file to another, but in general it looks something like this:

cat /usr/lib/systemd/system/sshd.service
[Unit]
Description=OpenSSH server daemon
After=network.target sshd-keygen.service    # these units must be activated before this unit
Wants=sshd-keygen.service                 # systemd will attempt to start this at the same time as this unit. 
          															

Linux Process – Managing Shell Jobs on CentOS/RHEL 7

In Linux, there are a lot of services that starts when your machine boots up. These services in turn launch lots of processes that the service requires. To view a full list of all these services you do:

$  ps -ef | wc -l
158
$  ps aux | wc -l       # alternative command. Not used that much anymore. 
158

In my case, I piped the output to wc command to do a line count instead. Hence in my case I have 158 processes that are currently running.

However some of the processes in the above list are not started by a service, instead they are triggered by you, when you run various commands in your current bash/putty terminal. These are a special type of processes, and


Systemd – Using Journald on CentOS/RHEL 7

Journald is a service that systemd uses for capturing logs:

$ systemctl status systemd-journald
systemd-journald.service - Journal Service
   Loaded: loaded (/usr/lib/systemd/system/systemd-journald.service; static)
   Active: active (running) since Sat 2015-09-26 16:35:29 BST; 42min ago
     Docs: man:systemd-journald.service(8)
           man:journald.conf(5)
 Main PID: 468 (systemd-journal)
   Status: "Processing requests..."
   CGroup: /system.slice/systemd-journald.service
           └─468 /usr/lib/systemd/systemd-journald

Sep 26 16:35:29 puppetmaster.local systemd-journal[468]: Runtime journal is using 6.2M (max 49.6M,...).
Sep 26 16:35:29 puppetmaster.local systemd-journal[468]: Runtime journal is using 6.2M (max 49.6M,...).
Sep 26 16:35:29 puppetmaster.local systemd-journal[468]: Journal started
Sep 26 16:35:38 puppetmaster.local systemd-journal[468]: Runtime journal is using 6.2M (max 49.6M,...).
Hint: Some lines were ellipsized, use -l to show in full.

Journald logs everything that it receives