Explore System Configuration Files and Kernel Tunables on Oracle Linux

9
1
Send lab feedback

Explore System Configuration Files and Kernel Tunables on Oracle Linux

Introduction

Oracle Linux provides many ways to customize your system's configuration. A system's configuration includes arguments for various services in config files found in the /etc/sysconfig directory and runtime kernel tuning parameters under the /proc/sys file system. Whether you set the configuration changes as transient or persistent, each parameter and value impacts how your system runs and behaves.

Objectives

In this tutorial, you'll learn to:

  • View system configuration files
  • Modify kernel settings
  • View hardware device and device driver attributes

Prerequisites

  • Minimum of a single Oracle Linux system

  • Each system should have Oracle Linux installed and configured with:

    • A non-root user account with sudo access
    • Access to the Internet

Deploy Oracle Linux

Note: If running in your own tenancy, read the linux-virt-labs GitHub project README.md and complete the prerequisites before deploying the lab environment.

  1. Open a terminal on the Luna Desktop.

  2. Clone the linux-virt-labs GitHub project.

    git clone https://github.com/oracle-devrel/linux-virt-labs.git
  3. Change into the working directory.

    cd linux-virt-labs/ol
  4. Install the required collections.

    ansible-galaxy collection install -r requirements.yml
  5. Deploy the lab environment.

    ansible-playbook create_instance.yml -e localhost_python_interpreter="/usr/bin/python3.6"

    The free lab environment requires the extra variable local_python_interpreter, which sets ansible_python_interpreter for plays running on localhost. This variable is needed because the environment installs the RPM package for the Oracle Cloud Infrastructure SDK for Python, located under the python3.6 modules.

    The default deployment shape uses the AMD CPU and Oracle Linux 8. To use an Intel CPU or Oracle Linux 9, add -e instance_shape="VM.Standard3.Flex" or -e os_version="9" to the deployment command.

    Important: Wait for the playbook to run successfully and reach the pause task. At this stage of the playbook, the installation of Oracle Linux is complete, and the instances are ready. Take note of the previous play, which prints the public and private IP addresses of the nodes it deploys and any other deployment information needed while running the lab.

Explore the Sysconfig Files

The /etc/sysconfig directory contains directories and files that control the different areas of your system's configuration. The content and function of these files depend on the packages you install on your system.

  1. Open a terminal and connect via SSH to the ol-node-01 instance.

    ssh oracle@<ip_address_of_instance>
  2. List the files in the /etc/sysconfig directory.

    ls /etc/sysconfig

    These files may contain configuration settings and command-line arguments for a specific service; others might be symbolic links to another location, for example the grub and selinux directories.

  3. View the firewalld file.

    cat /etc/sysconfig/firewalld

    The /etc/sysconfig/firewalld file describes the usage of the file, which provides additional command-line arguments when starting the firewalld process.

  4. View the network file.

    cat /etc/sysconfig/network

    This file contains a value that globally enables or disables networking. Similarly, you may see a /etc/sysconfig/network-scripts directory. This directory contains the legacy network configuration files.

    Note: Instead of using these scripts, you should use NetworkManager. The NetworkManager configuration is found in the /etc/NetworkManager/system-connections/ directory.

Explore the Procfs File System

The /proc file system in Oracle Linux is a pseudo-filesystem that provides a way to access and interact with kernel data structures and system information. It's a virtual file system that the kernel dynamically generates and reflects the system's current state.

  1. List the contents of the /proc directory.

    ls /proc

    The output shows a hierarchical directory structure, with directories and files representing different aspects of the system. The numbered directories provide information about running processes. Each process has a directory under /proc containing files with details about the process, like its command line, memory usage, open files, and more.

  2. View information about system memory.

    cat /proc/meminfo
  3. View information about the processors in your system.

    cat /proc/cpuinfo

    You can use grep to narrow the results to information about the CPU, including its model, speed, and number of cores.

  4. View the devices file to display information about the various characters and block devices currently configured.

    less /proc/devices

    Press q to exit the less command.

  5. List the number of processes running on the system.

    ls -d /proc/[0-9]* | wc -l

    This command grabs a listing of only directories that begin with a numeric value and then gets a line count.

  6. List the available details of the systemd process.

    ls -l /proc/1
  7. View the status of the systemd process.

    head -n 10 /proc/1/status

    The head command will show the first 10 lines about the process, including its name, umask, and state.

  8. Check the status of IP forwarding.

    cat /proc/sys/net/ipv4/ip_forward

    IP forwarding lets you set up Oracle Linux as a router or gateway. This setting defaults to disabled and a value of 0.

  9. Enable IP forwarding.

    echo 1 | sudo tee /proc/sys/net/ipv4/ip_forward

    Using this approach to change kernel attributes is temporary and will revert to the previous setting after a system reboot.

Explore the Sysfs File System

The sysfs file system in Oracle Linux is a virtual file system that exists entirely in memory and doesn't reside on a physical storage device like a hard drive. It allows the Linux kernel to expose information about its internal data structures, hardware devices, and drivers to user space, which consists of applications and processes running outside the kernel.

  1. List the contents of the sysfs file system.

    ls -l /sys
  2. Get a list of your system's available virtual disk block devices.

    ls -l /sys/block | grep sd

    The output shows devices such as sda. If you run the same command without the grep, you will see a list of dm- directories. These contain information about device-mapper (DM) devices. DM devices are block devices mapped through the Linux Device Mapper.

  3. Display information about the ens3 device.

    ls -lH /sys/bus/virtio/devices/virtio0/net/ens3

    The ls command allows traversing symlinks using the -H option.

  4. Display the operational state, MAC address, and MTU of ens3.

    for i in operstate address mtu; do echo "$i: $(cat /sys/bus/virtio/devices/virtio0/net/ens3/$i)"; done

Use the Sysctl Utility

Sysctl is a tool that allows users to read and change the kernel parameters of the Oracle Linux operating system. With it, you can modify the system's kernel attributes, such as version number, security settings, and maximum limits.

  1. Get the current state of IP forwarding.

    sysctl -n net.ipv4.ip_forward

    This command is the same as running cat /proc/sys/net/ipv4/ip_forward. The value of 1 indicates that IP forwarding is enabled.

  2. Disable IP forwarding.

    sudo sysctl -w net.ipv4.ip_forward=0

    The -w option writes out the value of 0 to the variable net.ipv4.ip_forward, but it is still temporary.

  3. Display all of the current kernel settings.

    The -a option displays all the tunable kernel parameters and their current value. You can pipe the output to the less command to paginate the information or pipe to grep to limit the results.

    sudo sysctl -a | grep -i ip_forward

    With less, you can scroll through the output using navigation keys such as Page Up and Page Down. Enter "q" to return to exit.

  4. Review the persistent custom kernel parameters.

    The /etc/sysctl.d directory is a way to persistently set specific kernel parameters without modifying the main /etc/sysctl.conf file or manually adjust them every time the system starts. Add them to a /etc/sysctl.d/<name>.conf file to preserve custom settings. The operating system processes these files in numeric and then alphabetical order. To override a setting, add a file with a lexical later name.

    cat /etc/sysctl.d/99-sysctl.conf
  5. Persist the IP forwarding setting.

    echo "net.ipv4.ip_forward=1" | sudo tee -a /etc/sysctl.d/my-sysctl.conf
  6. Enable the changes immediately without a reboot.

    sudo sysctl -p /etc/sysctl.d/my-sysctl.conf
  7. Verify the change applied.

    sysctl -n net.ipv4.ip_forward

Next Steps

By completing this tutorial, you've demonstrated your skills and ability to view, edit, and tune system configurations and kernel attributes on Oracle Linux. There are many more flags and features of the commands shown. Review the links below to increase your knowledge and skills.

SSR