Discover millions of ebooks, audiobooks, and so much more with a free trial

Only $11.99/month after trial. Cancel anytime.

CompTIA Linux+ XK0-005 Reference Guide: Get the knowledge and skills you need to become a Linux certified professional (English Edition)
CompTIA Linux+ XK0-005 Reference Guide: Get the knowledge and skills you need to become a Linux certified professional (English Edition)
CompTIA Linux+ XK0-005 Reference Guide: Get the knowledge and skills you need to become a Linux certified professional (English Edition)
Ebook756 pages4 hours

CompTIA Linux+ XK0-005 Reference Guide: Get the knowledge and skills you need to become a Linux certified professional (English Edition)

Rating: 0 out of 5 stars

()

Read preview

About this ebook

The CompTIA Linux+ certification is a valuable credential for anyone who wants to work with Linux systems. It demonstrates your skills and knowledge of Linux administration, which is essential for getting a job or advancing your career.

This comprehensive guide is designed to help you prepare for and pass the CompTIA Linux+ XK0-005 certification exam. It covers all the essential topics you need to know, including how to configure, manage, operate, and troubleshoot Linux server environments. It also includes practice test questions to help you assess your knowledge and readiness for the exam.

By the end of this book, you will be confident and prepared to take the CompTIA Linux+ certification exam.
LanguageEnglish
Release dateSep 6, 2023
ISBN9789355515742
CompTIA Linux+ XK0-005 Reference Guide: Get the knowledge and skills you need to become a Linux certified professional (English Edition)

Related to CompTIA Linux+ XK0-005 Reference Guide

Related ebooks

Certification Guides For You

View More

Related articles

Reviews for CompTIA Linux+ XK0-005 Reference Guide

Rating: 0 out of 5 stars
0 ratings

0 ratings0 reviews

What did you think?

Tap to rate

Review must be at least 10 words

    Book preview

    CompTIA Linux+ XK0-005 Reference Guide - Philip Inshanally

    C

    HAPTER

    1

    Introduction to Linux Environment

    Introduction

    In this chapter, we will learn about the Linux Filesystem Hierarchy Standard (FHS) directories. Next, we will look for ways to obtain hardware information from the terminal environment. Finally, we will wrap this chapter with GRUB2.

    Structure

    This chapter will discuss the following topics:

    Filesystem hierarchy standard

    Finding hardware information

    Grand Unified Bootloader 2

    Objectives

    By the end of this chapter, you will be able to understand filesystem structure. You will become accustomed to directories and how they are used. It will be easier for you to locate hardware. Grand Unified Bootloader 2 will also be introduced to you through this chapter.

    Filesystem hierarchy standard

    When the term FHS is referenced, think of directory structure. You will find on almost all the Linux distributions, the FHS is identical. It defines the directory structure and content in UNIX-like operating systems such as Linux distros.

    The need for a standardized filesystem hierarchy arose from the diverse nature of early Unix systems, where file organization varied significantly across different implementations. The FHS project was initiated in the early 1990s by the Free Standards Group (now the Linux Foundation) to address this issue. Its primary objective was to establish a typical structure simplifying software development, administration, and package management across Linux distributions.

    Key principles of the FHS

    The FHS is guided by several fundamental principles that shape its design and implementation. These principles include:

    Filesystem hierarchy: The FHS defines a consistent structure for organizing files and directories. It categorizes them based on purpose, ensuring each component has a specific role within the hierarchy.

    Compatibility: The FHS aims to maintain compatibility across different Linux distributions. By adhering to the standard, software developers and administrators can create and manage applications that work seamlessly across various systems.

    Compliance: Linux distributions seeking FHS compliance must adhere to specific guidelines to ensure consistent placement of files and directories. This promotes portability and simplifies the packaging and installation of software.

    Across the various Linux Distros, the configuration files will usually be in the exact location regardless of Linux distribution (the /etc directory). This makes developing software for Linux much more accessible since software developers do not have to write different versions of applications for each distribution.

    In the FHS environment, the files and directories appear under the root directory (/); this root directory is the parent of all other directories and sits at the top of the FHS.

    A list of the commonly used directories across Linux distros is as follows:

    /: The root directory, this is the top-level directory. It is the parent for all other directories.

    /root/: The home directory of the root user.

    /boot: It contains files relating to system boot, such as the bootloader configurations, kernel images, and initial RAM disk (initram) files.

    /bin: The critical executable files that are necessary for system operations.

    /dev: It contains device files like hard disks or CD-ROMs.

    /sbin: It is similar to /bin but contains programs generally run by the root user.

    /etc: It contains configuration files.

    /home: This is the user’s home directory.

    /lib: It contains libraries on 32-bit systems.

    /lib64: It contains libraries on 64-bit systems.

    /media: It is the mount point for removable media, usually used for auto-mounting external media.

    /mnt: It isthe mount point for removable media manually.

    /usr: It contains most user utilities (/usr/bin/, /usr/lib/, etc.).

    /var: This contains the various files such as logs (auth, syslog), web server content, and package cache.

    /tmp: This contains temporary files created by programs.

    /proc: A virtual filesystem containing various runtime information suchasdevices, bus, interrupts,CPU, RAM, etc.

    Now, let us look at the directories at the terminal using Ubuntu and Centos distributions.

    The root (/) directory resides at the top of the directory structure. Using Ubuntu, let us check out our current working directory using the pwd command. Consider Figure 1.1:

    Figure 1.1: Present working directory

    Now, let us check the content of the root (/) directory using the ls command.

    Consider Figure 1.2:

    Figure 1.2: Output of the ls command

    We can see that the root (/) directory contains a range of other directories. For a hierarchical view, let us leverage the tree with the -d option (directory) command.

    Consider Figure 1.3:

    Figure 1.3: Output of the tree command with -d option

    Switch to our Centos system and check the root (/) directory.

    Consider Figure 1.4:

    Figure 1.4: Output of the ls command with a similar structure

    As shown above, the structure is similar. Let us use the tree command with the -d option for a hierarchical view. Consider Figure 1.5:

    Figure 1.5: Output of the tree command with the -d option for a hierarchical view

    Now, look at the content of the /bin directory using the ls command. We will see a variety of commands which are a part of the operating system. Consider Figure 1.6:

    Figure 1.6: Output of ls command with the bin directory

    In contrast, in the /usr directory, you will notice some similarities inside the /usr/bin directory. However, the /bin is part of the core operating system and must be accessible before the /usr directory gets mounted. Consider Figure 1.7:

    Figure 1.7: Contents of the /usr/bin directory

    Another commonly used directory for configuration files is the /etc directory. To change between directories, we would use the cd command, as illustrated in Figure 1.8:

    Figure 1.8: Contents of the /etc directory

    We can leverage the cat command and look at the /etc/resolv.conf to view any of these files containing configurations relating to DNS settings. Consider Figure 1.9:

    Figure 1.9: Content of the /etc/resolv.conf

    Now, look at the /var directory. Here, we are going to see the various log files as shown in Figure 1.10:

    Figure 1.10: Content of the /var/log/auth.log

    The /var/log/auth.log contains system authorization information, user logins, and authentication mechanisms.

    Another popular log file is the /var/log/syslog, and we will use the head command as the output of the file that will usually run off the screen. Consider Figure 1.11:

    Figure 1.11: Output of the /var/syslog

    Over on our Centos machine, there is no log file named syslog, but instead, it is called messages, as shown in Figure 1.12:

    Figure 1.12: Content of the /var/log directory

    The contents of the /var/log/messages in the Centos machine are like that of the /var/log/syslog. Consider Figure 1.13:

    Figure 1.13: Content of the /var/log/messages

    To view the contents of the /var/log/messages on the Centos machine, you will require administrative privileges or be the root user. We will discuss more on this in Chapter 6, Firewall remote access and SELinux.

    When we are looking for kernel messages, there is /var/log/kern.log file; like the syslog file, the output of this file is lengthy, so we will use the head command once again for illustration, as shown in Figure 1.14:

    Figure 1.14: Content of the /var/log/kern.log

    Another commonly used directory is the /lib directory which holds essential libraries, as shown in Figure 1.15:

    Figure 1.15: Content of the /lib directory

    Each user also has their home directory; in our case, only one user exists. Let us check out the /home directory for our existing users. Consider Figure 1.16:

    Figure 1.16: Content of the /home/philip directory

    We can also leverage the tree command by itself to view all the directories and files in a hierarchical structure, as shown in Figure 1.17:

    Figure 1.17: Directory displayed using the tree command

    We will look at user creation in Chapter 5, User and password management.

    We can also view hidden files within a directory by using the ls command with the -a option, as shown in Figure 1.18:

    Figure 1.18: Viewing hidden file(s) using the ls command with -a option

    Note: The hidden files are prepended with a period (.).

    Finding hardware information

    In Linux, you can use various command-line tools to obtain hardware information from the terminal. Here are some commonly used commands:

    lscpu: This command displays detailed information about the CPU (processor) on your system, including the number of cores, architecture, clock speed, and more.

    lsblk: It lists information about block devices attached to your system, such as hard drives and SSDs. It shows details like device names, sizes, and mount points.

    blkid: It provides block device attributes.

    lspci: It provides information about Peripheral Component Interconnect (PCI) devices connected to your system, including graphics cards, network adapters, and sound cards.

    lsusb: This command lists USB devices attached to your system, such as keyboards, mice, printers, and USB storage devices.

    Lsmod: View modules that are in use for free-view RAM information.

    Hwinfo: It is a comprehensive hardware tool that provides detailed information about various hardware components, including CPU, memory, storage, network adapters, and more.

    dmidecode: This command retrieves information from the system's Desktop Management Interface (DMI) table, which contains details about the hardware components, BIOS, and system manufacturer.

    Inxi: It is a versatile command that provides detailed information about various hardware components and system configurations in a user-friendly format. It can display details about the CPU, memory, storage, graphics, and more.

    df: Displays the disk space usage of file systems.

    du: This command retrieves the disk usage of directories and files.

    Note. You can also leverage the /proc/ directory to obtain various information about hardware, such as the CPU, RAM, interrupts, etc.

    Let us look at the lscpu command in our Centos system. Consider Figure 1.19:

    Figure 1.19: Output of the lscpu command

    From the above output, information regarding the CPU is displayed such as the architecture, vendor, core(s) per socket, etc.

    Now, let us look at the lsblk command in our Ubuntu system, as shown in Figure 1.20:

    Figure 1.20: Output of the lsblk command

    We can see various block devices' respective mount points, sizes, and types.

    Continuing our journey with block devices, we will use the blkid command to view attributes as shown on our CentOS system in Figure 1.21:

    Figure 1.21: Output of the blkid command

    The UUID and the label are exposed for the block device(s).

    Now, let us look at our PCI information, such as host, PCI, ISA, etc. using the lspci command as shown in Figure 1.22:

    Figure 1.22: Output of the lspci command

    To view information about USB devices, we can leverage the lsusb command, as shown in Figure 1.23:

    Figure 1.23: Output of the lsusb command

    When we would like to view the currently loaded modules, we can take advantage of the lsmod command, as shown in Figure 1.24:

    Figure 1.24: Output of the lsmod command

    The free command can be used to view RAM in the system. The default will be displayed in Kibibytes (in Linux and most operating systems) if used without any option. A kibibyte is equal to 1024, or 2^10, bytes. A kilobyte is also 1024 bytes, but there are exceptions. As defined by the International System of Units, the prefix kilo refers to 1000 or 10^3. Most storage manufacturers measure and label capacity in base 10 (1 kilobyte = 1000 bytes; 1 megabyte = 1000 kilobytes; 1 gigabyte = 1000 megabytes; 1 terabyte = 1000 gigabytes). However, RAM vendors and most operating systems use base 2 (1 kilobyte = 1024 bytes; 1 megabyte = 1024 kilobytes; 1 gigabyte = 1024 megabytes; 1 terabyte = 1024 gigabytes). We can use the -g option to consider in Gibibytes or the -m option, which will display the RAM in Mebibytes as shown in Figure 1.25:

    Figure 1.25: Output of the free command

    To get more information regarding the hardware in the system, there is yet another helpful command, the hwinfo command, as shown in Figure 1.26:

    Figure 1.26: Output of the hwinfo command with the --short option

    As shown above, the output will run off the screen. Using the --short option displays an overview of the hardware.

    We can view specific hardware using keywords like disk, memory, network, etc.

    This example displays hard disk information as shown in Figure 1.27:

    Figure 1.27: Output of the hwinfo command with the --disk option

    The following figure shows memory-specific hardware information:

    Figure 1.28: Output of the hwinfo command with the --memory option

    We can utilize the df command to view the disk space usage of the filesystem. Using the -h displays in a human-readable format as shown in Figure 1.29:

    Figure 1.29: Output of the df command with the -h option

    If we would like to see disk usage for a directory, we can utilize the du command; adding the -h option will display the values in the human-readable format, as shown in Figure 1.30:

    Figure 1.30: Output of the du command with the -h option

    Grand Unified Bootloader 2

    Grand Unified Bootloader 2 (GRUB2) is an open-source bootloader widely used in Linux-based operating systems. It plays a crucial role in the boot process, allowing users to select and launch their preferred computer operating systems.

    The primary purpose of GRUB2 is to load the operating system kernel into memory and transfer control to it. The boot menu provides a user-friendly interface where users can choose from multiple installed operating systems or different boot options. GRUB2 supports various operating systems, including Linux distributions, BSD, and Windows.

    One of the critical improvements of GRUB2 over its predecessor, GRUB Legacy, is its enhanced flexibility and compatibility. GRUB2 supports Basic Input/Output System (BIOS) and Unified Extensible Firmware Interface (UEFI) boot modes, making it compatible with various hardware platforms. It also supports multiple filesystems, such as ext4, Btrfs, XFS, and NTFS, allowing it to handle different storage configurations.

    GRUB2 has a modular architecture consisting of a core image and dynamically loadable modules. The core image contains the essential functionality required for bootings, such as disk access, filesystem drivers, and menu handling. Additional modules can be loaded at runtime to provide extra features and support for specific filesystems or hardware devices. This modular design allows it to be flexible and easily extensible.

    The installation and configuration of GRUB2 may vary slightly depending on the Linux distribution. Typically, the installation process involves installing the GRUB2 package and configuring it as the default boot loader. During installation, it copies the core image and necessary modules to the boot partition or the EFI system partition in the case of UEFI systems.

    GRUB2's main configuration file is grub.cfg, located in the /boot/grub directory. This file contains the boot menu entries, which specify the location of the kernel, initial RAM disk, and other boot parameters for each operating system. Users can modify this file manually to customize the boot menu, change default options, set timeout values, and implement advanced features like password protection.

    Customization options in GRUB2 go beyond the configuration file. Users can customize the appearance of the boot menu by modifying themes and adding background images. It also supports scripting, allowing users to automate boot tasks, create conditional statements, and perform advanced configurations. In addition, users can add/remove other Linux kernels and Operating Systems, such as Microsoft Windows, to the GRUB2 boot menu.

    In addition to the basic functionality, GRUB2 offers advanced features and functionality. It provides a command-line interface allowing users to interact directly with the boot loader. This interface can help troubleshoot boot issues, modify boot options on the fly, and perform system maintenance tasks.

    It also supports secure boot, a feature in UEFI systems that verifies the boot process's integrity to protect against unauthorized code execution. GRUB2 can be configured to work seamlessly with secure boot, ensuring the safe and trustworthy booting of the system.

    Troubleshooting GRUB2-related issues is facilitated by features such as rescue mode and recovery options. In case of misconfigurations or boot failures, users can enter the rescue mode to access a command-line interface and attempt to fix the issues manually. GRUB2 also provides tools for reinstalling or restoring the bootloader in case of critical failures.

    Furthermore, GRUB2 supports advanced topics like network booting, which allows booting an operating system over the network, and virtualization, enabling the launch of virtual machines directly from the boot menu.

    GRUB2 continues to evolve with ongoing development and enhancements. The GNU Project maintains it and benefits from contributions from the open-source community. New features, bug fixes, and improvements are regularly introduced to address emerging technologies, hardware advancements, and user requirements.

    We can look at the GRUB2 configuration file on our Ubuntu system. Consider Figure 1.31:

    Figure 1.31: Contents of the /boot/grub/grub.cfg

    Some of the above output has been omitted for brevity. Each entry has BEGIN and END comments. The menu entry represents the boot options (kernel, Windows OS version) which are displayed on the boot screen upon system boot, as shown in Figure 1.32:

    Figure 1.32: Contents of the /boot/grub/grub.cfg

    Over on our CentOS system, the grub configuration file resides in the /boot/grub2/grub.cfg as shown in Figure 1.33:

    Figure 1.33: Contents of the /boot/grub2/grub.cfg

    Working with GRUB2

    We can add our custom boot entry, and we will first create a custom boot file and save it in the /etc/grub.d/40_custom configuration file. We will use the Ubuntu system for this demo, as shown in Figure 1.34:

    Figure 1.34: Contents of the /etc/grub.d/40_custom configuration file

    We will edit this file using a text editor, add our entry at the bottom and save the changes.

    Consider Figure 1.35:

    Figure 1.35: Editing /etc/grub.d/40_custom configuration file

    Based on the above output, the entry defines the boot entry parameters. The next step is to run the grub-mkconfig command, which will write the changes so that the /boot/grub/grub.cfg knows of the existence of our custom entry. Refer to Figure 1.36:

    Figure 1.36: Output of the grub-mkconfig command

    Some output was omitted for brevity. Finally, we will increase the timer value inside the /etc/default/grub configuration file to see the boot screen upon reboot. The GRUB_TIMEOUT is currently set to 0, as shown in Figure 1.37:

    Figure 1.37: Contents of the /etc/default/grub configuration file

    We will change the GRUB_TIMEOUT=0 to GRUB_TIMEOUT=10 and change the value of GRUB_TIMEOUT_STYLE=hidden to GRUB_TIMEOUT_STYLE=menu as shown in Figure 1.38:

    Figure 1.38: Contents of the /etc/default/grub configuration file with changed values

    Now let us run the update-grub command as shown in Figure 1.39:

    Figure 1.39: Output of the update-grub command

    Upon reboot, we can see our new boot entry listed as shown in Figure 1.40:

    Figure 1.40: Output of the GRUB2 boot menu

    In conclusion, GRUB2 is a powerful and versatile boot loader critical to the boot process in Linux-based operating systems. Its flexible architecture, compatibility with various hardware platforms, extensive customization options, and advanced features make it the preferred choice for boot management in the Linux ecosystem.

    Conclusion

    In this chapter, we covered the Linux filesystem hierarchy standard, locating hardware information, and we finished off this chapter by working with GRUB2.

    In the next chapter, we will cover files, directories, and storage.

    Join our book’s Discord space

    Join the book's Discord Workspace for Latest updates, Offers, Tech happenings around the world, New Release and Sessions with the Authors:

    https://discord.bpbonline.com

    C

    HAPTER

    2

    Files, Directories, and Storage

    Introduction

    In the previous chapter, we covered various directories that comprise the Linux Filesystem Hierarchy Standard (FHS). After that, we looked at ways to obtain hardware information from the terminal environment. Finally, we wrapped it with GRUB2.

    In this chapter, we will focus on Files, Directories, and Storage. First, we will look at file compression and then cover file and directory operations. Following this, we will cover filesystem management. Finally, we will wrap this chapter with Logical Volume Management (LVM).

    Structure

    We will discuss the following topics in this chapter:

    File compression

    File and directory operations

    Pipes and redirects

    Filesystem management

    Using the parted utility

    Steps to format a hard disk

    Mounting and unmounting a partition

    Logical volume management

    Objectives

    This chapter will teach us to manipulate and manage files and directories. We will learn about file compression and files and directory operations in detail. We will also focus on configuring the storage.

    File compression

    File compression is the process of reducing the size of files and directories to save storage space, enhance transfer speed, and simplify file management. In Linux, there are various compression algorithms and tools available to accomplish this task.

    Compression algorithms

    Linux offers several compression algorithms, each with its own characteristics and trade-offs. Here are some commonly used ones:

    Gzip: It uses the DEFLATE algorithm and is widely supported on Linux. It compresses files into a single archive with the .gz extension. To compress a file using gzip, use the following command:

    gzip file.txt

    This creates a compressed file named file.txt.gz.

    Bzip2: It utilizes the Burrows-Wheeler Transform and Run-Length Encoding algorithms. It provides higher compression ratios than gzip but requires more processing time. To compress a file using bzip2, use the command:

    bzip2 file.txt

    This creates a compressed file named file.txt.bz2.

    Xz: It employs the LZMA/LZMA2 algorithm and offers better compression ratios than bzip2. It is particularly suitable for compressing large files. To compress a file using xz, use the command:

    xz file.txt

    This creates a compressed file named file.txt.xz.

    Zip: It is a popular compression format compatible with various operating systems. It supports compressing multiple files and directories into a single archive. To create a zip archive, use the command:

    zip archive.zip file1.txt file2.txt

    This creates an archive named archive.zip containing file1.txt and file2.txt.

    Compressing files

    To compress files using Linux compression tools, you need to use specific commands. Here are some examples:

    gzip

    gzip file.txt: compresses file.txt using gzip and creates file.txt.gz.

    bzip2

    bzip2 file.txt: compresses file.txt using bzip2 and creates file.txt.bz2.

    xz

    xz file.txt: compresses file.txt using xz and creates file.txt.xz.

    zip

    zip archive.zip file1.txt file2.txt: creates a zip archive named archive.zip containing file1.txt and file2.txt.

    Compressing directories

    Linux allows you to compress entire directories while preserving their structure. Here are examples of compressing directories:

    gzip

    tar -czf archive.tar.gz directory/: creates (-c) a tarball called archive.tar.gz by compressing the directory (-f) using (-z) gzip.

    bzip2

    tar -cjf archive.tar.bz2 directory/: creates a tarball called archive.tar.bz2 by compressing the directory using (-j) bzip2.

    xz

    tar -cJf archive.tar.xz directory/: creates a tarball called archive.tar.xz by compressing the directory using (-J) xz.

    zip

    zip -r archive.zip directory/: creates a zip archive named archive.zip by recursively (-r) compressing the directory and its contents.

    Decompressing files and directories

    Once files or directories are compressed, they can be decompressed to their original state. Here are examples of decompression:

    gzip

    gunzip file.txt.gz decompresses file.txt.gz using gzip.

    bzip2

    bunzip2 file.txt.bz2 decompresses file.txt.bz2 using bzip2.

    xz

    unxz file.txt.xz decompresses file.txt.xz using xz.

    zip

    unzip archive.zip decompresses archive.zip and extracts its contents.

    Advanced compression techniques

    Linux provides additional options and techniques for file compression. Some notable ones include:

    Archive: Combining compression and archiving in one step, you can create compressed tarballs directly.

    For example, tar -czf archive.tar.gz file1.txt file2.txt.

    Compression levels: Compression tools often offer different levels of compression, allowing you to prioritize either compression ratio or processing speed.

    For example, gzip -9 file.txt sets the maximum compression level for gzip.

    Parallel compression: Some compression tools support parallel compression, utilizing multiple processor cores to speed up compression and decompression.

    For example, pigz file.txt is a parallel implementation of gzip.

    Stream compression: Linux allows compressing data streams on-the-fly, which is useful for efficient transfer or backup scenarios.

    For example, tar cf - directory/ | gzip > archive.tar.gz creates a compressed tarball

    Enjoying the preview?
    Page 1 of 1