Linux Academy Notes

101.1 Determine and configure Hardware settings

Pseudo (fake) File System:

Everything in Linux is seen as a file and it is stored in the RAM.

Once the session is powered off the and the RAM gets cleared, this file system disappears.

Once the machine is reopened it creates a new file System for the new session which is kept in RAM.

/proc - Contains information about the processes running on a system.

Processes are listed by PID with hardware and process data both in the same directory structure.

/sys - Contains information about the system’s hardware and kernel modules. No process information is listed here.

man proc - shows local documentation on the /proc pseudo file system.

Working with Kernel Modules:

Kernel is the core framework of the OS

GNU/Linux OS - Contains Bash commands, shells, what the system needs to function.

Linux kernel is monolithic: meaning that it handles all memory management and hardware device interactions

Has the ability to dynamically load and unload drivers.

uname - Displays information about the currently running Kernel.

lsmod - Displays a listing of all currently loaded kernel modules.

modinfo - Displays information about a specified Kernel module.

modprobe - command used to dynamically load and unload kernel modules at runtime.

modprobe -r <kernel module name> - to unload module

modprobe <kernel module name> - to load module 

Example: Kernel module Floppy

Investigating Hardware:

/dev- contains information on all of the connected hardware on a system

udev - the device manager for the Linux Kernel, links information on system hardware to /dev

D-Bus - Sends data messages between applications, a conduit of information about what’s going on the system

udev utilizes dbus to notify users and the system when new hardware is attached.

101.2 Boot the System

The Linux boot Sequence:

INIT: Short for initialization

When machine starts the Kernel looks for the program in /sbin/init. Once this starts init is in control.

First thing init does is it looks for the configuration tab in /etc/inittab

This also holds the Runlevels of the OS

Predefined configuration that the computer will operate within. Applies to system as a whole.

Traditional Scripts for Stop/Start for the system to function are in:

/etc/init.d - contains the scripts for the services on the system

/etc/init.d/rc. - scripts that orchestrate how the runlevel scripts run and what occurs when a runlevel changes.

Upstart: - Boot Sequence

Upstart allows for multiple processes to run simultaneously rather than the old init system where it has to wait for a sequence to finish before it can start.

Init is static; it does not natively respond to changes on a system (manual config)

Upstart is dynamic, it can respond to changes on the system.

Ex: Plugging in a monitor, init will not recognize this and will have to be set up manually, where upstart will do this automatically.

When something on a Linux system changes it is known as an event. When an event is triggered it will start and upstart job.

Jobs are split in 2 categories: Tasks & Services

Task: will do what it is required of it and then it will return to a waiting state once it is finished. (one time use)

Service: will not stop by itself and will only kill a service if an event calls for it, or if an admin does so.

Job flow:

Initial State: waiting (to do something)

Starting where the job is required.

Running: the job is actually processing what it is supposed to do If it fails it will enter respawn state, where the system tries to run the task up to 10 times before it drops it as failed.

Stopping: where the job has finished what it is supposed to do, but it is not stopped just yet.

Killed: request for the job to be terminated as it is finished

Post-stop: where the job is actually finished.

After that the status becomes waiting again.

systemd:

init and parts of upstart rely on Bash shell scripts which require the bash interpreter to run, systemd has removed this.

Systemd is backwards compatible, but not guaranteed 100% with all functions.

Unit File Locations:

Provided by package installation: /usr/lib/systemd/system

These should not be modified as they might be susceptible to change by an update.

Unit file location for system administrators: /etc/systemd/system

These take precedence over those in /usr

Runtime unit files: /run/systemd/system

View all unit files on system: systemctl list-unit-files

FULL DOC for the Unit File: man 5 systemd.unit

systemctl cat <something>.unit will print out content of unit file specified.

Systemd boot system:

Kernel still looks for /sbin/init

Systemd just took the place of /sbin/init

Developers have created a symbolic link for /sbin/init to redirect to /lib/systemd/systemd which actually boots systemd.

101.3 Change Runlevels/Boot Targets and Shutdown or Reboot the System:

runlevel - view current runlevel which applies on the system as a whole

telinit - change to another runlevel (alternative command: init )

In order to change runlevel you have to be the root user

Changing runlevels at boot:

Interrupt the GRUB boot process by pressing any key during startup, then at the GRUB selection menu highlight a kernel to modify.

Press the ā€œaā€ key to add arguments to the end of a kernel line, enter in a runlevel number.

Change your Working Environment: targets:

A target unit is a unit that syncs up to other units when the computer boots or changes states.

Often used to bring system to a new state.

Types of Targets:

multi-user.target - multi-user system similar to what runlevel 3 provide

graphical.target - multi-user system with desktop environment, similar to what runlevel 5 provides

rescue.target - pulls in a basic system and file system mounts and provides a rescue shell

basic.target - basic system, used during the boot process before another target takes over

sysinit.target - system initialization

Target Units:

Reboot and Shutdown your System:

Reboot Commands:

Shutdown Commands:

Configuration file is under /etc/acpid

102.1 Design Hard Disk Layout:

Main File System Location:

Sizing: Older rule of thumb ranged from 1.5x to 2.0x the size of available RAM RAM is cheaper and it’s up to admin to set up SWAP space, but usually not less than 50% of RAM

Partitions and Mount Points:

/dev/sda - sda is full partition, usually that will divided in multiple sections assigned as /dev/sda1 ; /dev/sda2 ; /dev/sda3, etc.

Mount point: is when you take a partition or disk and mount it to a directory, for example /home - meaning it will house all the home directories.

Introduction to LVM: (Logical Volume Manager)

Allows the creation of ā€œgroupsā€ of disks or partitions that can be assembled into a single (or multiple) filesystems:

  • Can be used for nearly any mount point EXCEPT /boot

  • Flexibility, allows for resizing of volumes

  • Snapshots - allows a point in time ā€œphotoā€ to be taken of the volume itself and is used as a backup

PV - Physical Volumes; VG - Volume Group; LV - Logical Files;

102.2 Install a Boot Manager:

Legacy Grub (Grand Unified Boot Loader)

BIOS → The first 512 bytes is a boot image searched → which searches for the core image file → which loads the /boot/grub partition and allows for the system to actually load.

Grub configuration file: grub.conf/menu.1st device.map

How to install GRUB:

Device can be /dev/sda or /dev/hd0 …. ETC

GRUB2

MBR (Master Boot Record)

Supported only 26 total partition (4 partitions with one partition extended to 23 partitions)

Partition size limited to 2TB

GPT (GUID Partition Table)

Supports 128 Partitions

Partition size up in the ZB range

Needs UEFI (Unified Extensible Firmware Interface) to boot:

Replacement for traditional BIOS cand act in legacy BIOS mode

Requires a 64bit OS

Prevents unauthorized OS from booting on the System

Interacting with the BOOT LOADER:

GRUB Legacy:

On SystemD you will have to use system.unit=rescue.target to boot in runlevel 1

102.3 Manage Shared Libraries:

Files that contain functionality that other applications can use.

These files end in a ā€œ.soā€ extension for shared object

Found under the following locations:

Two types of library files:

Dynamic (ends in .so) Statically Linked (ends in .a)

102.5 Use RPM and YUM Package Management

YUM: Yellowdog Updater modified

  • Handles RPM package Dependencies

  • Installs, upgrades and removes packages

  • Users on RHEL, CENTOS, Scientific Linux, older versions of Fedora

YUM setup:

  • Global yum configuration options are set in /etc/yum.conf

  • Reads repository information from /etc/yum.repos.d

  • Cache latest repository information in /var/cache/yum

Other RPM Package Managers:

Zypper:

Used on SUSE Linux Distributions

Ex: zypper repos; zypper install vim

DNF - Dandified yum:

  • Used on Fedora Linux distributions

  • Future replacement for yum in RHEL

Uses same command syntax as yum

RPM (Redhat Package Manager):

The .rpm package contains:

  • Application or utility

  • Default configuration file

  • How and where to install the files that come with the package

  • Listing of dependencies that the package requires.

The rpm database: located in /var/lib/rpm

Dependencies need to already be installed or installed with the package

yum handles dependencies for you, rpm does not.

ex: rpm2cpio some.rpm | cpio -idmv

102.6 Linux as a Virtualization Guest:

Virtualization and Containers:

Emulations of a specific computer type

Operate based on the architecture and functions of a real computer and its implementation, can involve specialized hardware, software or both.

Virtualization Software allows you to set up on OS within another.

  • They both share the same physical hardware

  • The virtual machine is isolated from that hardware and has to communicate with in through a Hypervisor

Examples: KVM; QEMU; VMWare; Xen; VritualBox

2 Main types of Virtualization:

  • Full Virtualization - guest system is not aware that it is a virtual machine

  • Paravirtualization - guest system is aware that it is a virtual machine, uses guest drivers Virtual machines typically perform better with guest drivers

Virtual machines can be ā€œclonedā€ or turned into templates to rapidly deploy new systems

NOTE: When working with Linux VMs you may need to change the system’s D-Bus Machine ID - done with dbus-uuidgen - ensures that each running Kernel interacts with system that has a unique ID

Virtual servers can be provisioned from cloud providers:

If you are using a cloned virtual machine, cloud-init is typically used to insure that user data is completely new

  • Creates new SSH Keys

  • Sets the system’s default locale

  • Sets the system’s hostname

  • Sets up mount points

Example: AWS, Azure

What is container:

An entirely isolated set of packages, libraries, and/or applications that are completely independent from their surroundings

2 Types of Containers:

  • Machine container: Shares a kernel and file system with the host computer

  • Application Container: Shares everything but the application files and library files that the application needs

Why is the difference important?

Virtualization: Invented to allow the sharing yet segregation of server instances from each other.

Protect one operating system from anther on the same system

Prevention of letting spare CPU cycles, memory, or disk space go to waste.

They are based on emulating virtual hardware through a hypervisor; heavy in terms of a system requirements

Containers: Uses shared OS - Each application gets isolated from other applications

More efficient in system resource terms - Can run multiple versions of the same app

More granular management of system resources

103.1 Work on the Command Line:

Your Bash Shell Environment:

Linux Shells: Is the command line environment that you work in on a Linux System

  • bash (bourne again shell) - the default

  • csh - C programming style syntax

  • ksh - Korn Shell, based on the Bourne Shell, with some features of the cshell added

  • zsh - Z Shell included elements of the Bash Shell and Korn Shell

Environment Variable: Setting that dedicate common functionality and locations for various purposes

Syntax: VARIABLE=path,command,alias

Example: CWD=/home/user/Documents

Bash functions: Users can create their own custom functions within Bash

Example:

function yo() { echo ā€œyoā€

}

When using echo you can place $ followed by the variable name in order to see the exact value of the variable, all variable names are upper case

Example: echo $PWD

export - command used to export a variable to the current shell and any new shells started from the current shell

pwd - displays the full path to the current working directory

which - used to locate an application file that is located within the user’s PATH

type - Used to determine if something is a function, file, alias, built-in, or keyword

Typing bash within a bash shell, it opens a new shell for use.

Left Child Shell - Right new login shell

Bash Quoting:

ā€œweakā€ quotes - weak quotes, or double quotes, will expand variable, but characters used for path substitution or for pattern matching will not expand

Example: echo ā€œ$PATHā€ will print the PATH

ls ā€œ*ā€ will not work as the ls command would be looking for a file named *

ā€˜strong’ quotes - inside strong or single quotes, nothing is interpreted

Example: echo ā€˜$PATH’ will print $PATH to the screen

Bash History and the Manual Pages:

history - Command that shows the most recently ran commands

.bash_history - File located in the user’s home Directory that contains the previously run commands

HISTFILESIZE - Environment variable that determines how many lines the .bash_history file will contain

Manual Pages:

Built-in manual pages for commands, configuration files, and system administrator tasks

Invoke with man

Man pages are broken out into ā€˜sectionsā€

  • Section 1: Executable programs or shell commands

  • Section 2: System calls - functions provided by the Kernel

  • Section 3: Library calls - functions within program libraries

  • Section 4: Special files - typically those found in /dev

  • Section 5: File formats and conventions - for example /etc/passwd & other configuration files

  • Section 6: Games

  • Section 7: Miscellaneous items and conventions

  • Section 8: System administration commands, usually only for root

  • Section 9: Non-standard Kernel routines

103.2 Use Streams, Pipes and Redirects:

Basics of Viewing Text Files:

Message Digest:

To check for this run command and use ā€œ-cā€ Ex: sha512sum -c

Text Manipulation:

LPIC1 - search and replace only for sed - big command

This does not modify the file itself, in order to do that you will have to use the following command.

Last updated