LPIC-101

From Training Material
Jump to navigation Jump to search

Nobleprog.svg

LPIC-101



title
LPIC-101
author


Tytus Kurek (NobleProg)

What does Linux mean?⌘

LPIC-102-01.png
http://upload.wikimedia.org/wikipedia/commons/thumb/3/35/Tux.svg/512px-Tux.svg.png


LINUX = LINUs' uniX


Outline⌘

  • First Day:
    • Session I:
      • Introduction to the course
    • Session II:
      • Topic 101: System Architecture
    • Session III:
      • Topic 102: Linux Installation and Package Management
    • Session IV:
      • Topic 102: Linux Installation and Package Management

Outline #2⌘

  • Second Day:
    • Session I:
      • Topic 103: GNU and Unix Commands
    • Session II:
      • Topic 103: GNU and Unix Commands
    • Session III:
      • Topic 104: Devices, Linux Filesystems, Filesystem Hierarchy Standard
    • Session IV:
      • Topic 104: Devices, Linux Filesystems, Filesystem Hierarchy Standard

First Day - Session I⌘


Introduction



LPIC-102-02.gif
http://shop.linuxnewmedia.com/media/catalog/product/cache/17/image/9df78eab33525d08d6e5fb8d27136e95/l/p/lpic1_large_6.gif

LPI certification path⌘

LPIC-101-1.png

LPIC-101 exam⌘

References⌘

  • Books:
    • R. Tracy. "LPIC-1/CompTIA Linux+ Certification All-in-One Exam Guide". McGraw-Hill Osborne Media, 1st edition
    • R. W. Smith. "CompTIA Linux+ Complete Study Guide (Exams LX0-101 and LX0-102)". Wiley Publishing, Inc., 2nd edition
    • A. Header, S. A. Schneiter, B. G. Pessanba and J. Stanger. "LPI Linux Certification in a Nutshell". O'Reilly, 3rd edition
  • Websites:
  • Internet
  • Man pages

Introduction to the lab⌘

Lab components:

  • Laptop with host OS
  • Virtual Machines with Linux on:
    • VMs: Ubuntu, CentOS
    • Credentials:
      • admin user: root / terminal
      • non-admin user: terminal / terminal
  • VirtualBox:
    • 64-bit version (click here to download)
    • Snapshots (top right corner)
    • Press right "Control" key to release

First Day - Session II⌘


Topic 101: System Architecture



LPIC-101-5.png
http://eng-cs.syr.edu/wp-content/uploads/2013/01/Computer-engineering01_Web.jpg

101.1 Determine and configure hardware
settings⌘



LPIC-101-6.png
https://www.lpi.org/linux-certifications/programs/lpic-1/exam-102/

Computer architecture⌘

LPIC-101-30.jpg
http://2.bp.blogspot.com/-3FMo-yBmdXo/TpDu9JvBuJI/AAAAAAAAADM/7d-lVx4XdQo/s1600/pcibusgeneric.jpg

Peripherals⌘

  • Peripheral - device that is used to put information into or get information out of the computer
  • Types of peripherals (by purpose):
    • input - interacts or sends data to the computer
    • output - provides output to the user from the computer
    • storage - stores data processed by the computer
  • Types of peripherals (by location):
    • integrated - peripherals located inside the computer
    • external - peripherals located outside the computer
  • HotPlug - function allowing replacing the device without a need to reboot the system

Linux kernel & kernel modules⌘

LPIC-101-29.png
http://haifux.org/lectures/86-sil/kernel-modules-drivers/kernel_draw.png

Mass storage devices⌘

  • Interfaces:
    • SATA (Serial ATA)
    • SCSI (Small Computer System Interface)
    • SAS (Serial Attached SCSI)
    • USB (Universal Serial Bus)
  • Naming convention:
    • starts with sd (for Scsi Device)
    • followed by a-ZZ representing an order in which the device is found
    • ends with 1-63 representing partition number
  • Partition types:
    • primary - 4 per disk
    • extended - 1 per disk
    • logical - 59 per disk

Hardware management⌘

  • Management tools:
    • lspci - displays devices connected to PCI bus
    • lsusb - displays devices connected to USB bus
    • lsmod - displays loaded kernel modules
    • modprobe - adds / removes kernel modules
  • Virtual filesystems:
    • /dev (devfs) - contains device files for all the devices
    • /proc (procfs) - contains files defining runtime kernel parameters
    • /sys (sysfs) - contains files representing kernel objects, their attributes and relations
    • /tmp (tmpfs) - contains temporary system files
  • Lab Exercise 101.1

101.2 Boot the system⌘

LPIC-101-7.png
https://www.lpi.org/linux-certifications/programs/lpic-1/exam-102/

Basic terms⌘

  • SMPS (Switching Mode Power Supply)
  • ROM (Read-Only Memory)
  • RAM (Random-Access Memory)
  • BIOS (Basic Input/Output System)
  • UEFI (Unified Extensible Firmware Interface)
  • POST (Power-On Self-Test)
  • MBR (Master Boot Record)
  • PBR (Partition Boot Record)
  • GPT (GUID Partition Table)
  • LILO (LInux LOader)
  • GRUB (GRand Unified Bootloader)
  • INITRD (INITial RamDisk)
  • INITRAMFS (INITial RAMFileSystem)
  • ROOTFS (ROOT FileSystem)

Boot sequence⌘

  1. SMPS is turned on.
  2. BIOS is loaded from ROM into RAM.
  3. BIOS performs POST.
  4. BIOS checks the boot order.
  5. BIOS loads MBR containing Stage 1 bootloader into RAM.
  6. Stage 1 bootloader loads Stage 1.5 bootloader into RAM.
  7. Stage 1.5 bootloader loads Stage 2 bootloader into RAM.
  8. Stage 2 bootloader loads kernel into RAM and passes parameters into it.
  9. Kernel loads INITRD or INITRAMFS into RAM.
  10. With a help of tools located in INITRD / INITRAMFS kernel attempts to mount the ROOTFS.
  11. Kernel executes the "init" script.
  12. Init forks and executes System V scripts.

Interaction with BIOS and GRUB⌘

  • F2 - enters BIOS menu
  • F12 - enters boot order menu
  • Esc - enters GRUB menu
  • c - enters GRUB CLI
  • e - modifies GRUB entry
  • Ctrl+x - saves changes and boots the system

Boot events⌘

  • Logging daemons:
    • klogd - logs Linux kernel messages
    • syslogd - logs Linux system messages
  • Log files:
    • /var/log/messages - contains messages logged by klogd
    • /var/log/syslog - contains messages logged by syslogd
  • Management tools:
    • dmesg - prints kernel ring buffer
  • Lab Exercise 101.2

101.3 Change runlevels / boot targets and shutdown or reboot system⌘



LPIC-101-8.png
https://www.lpi.org/linux-certifications/programs/lpic-1/exam-102/

Runlevels (boot targets)⌘

  • Runlevel (boot target) - defines mode of the operating system
  • Linux runlevels (boot targets):
Runlevel Boot target Meaning
0 poweroff.target Halt
1 rescue.target Single-user mode
2, 3, 4 multi-user.target Multi-user mode with network
5 graphical.target Multi-user mode with network and X11
6 reboot.target Reboot

Init, System V, Systemd and Upstart⌘

  • Init - main system process executed by kernel
  • System V - defines an order in which startup scripts are executed
  • Systemd - System V descendant (adopted by leading distributions)
  • Upstart - System V descendant (adopted by Ubuntu up to Wily release)
  • Both Systemd and Upstart fix the problem of fixed order in System V

Runlevels management⌘

  • Management tools:
    • runlevel - displays current runlevel
    • init - changes current runlevel once
    • telinit - changes current runlevel once
    • shutdown - brings the system down and powers the computer off
    • halt - brings the system down
    • poweroff - stops the system (symlink to halt)
    • reboot - reboots the system
    • wall - sends notification to logged in users
  • Configuration files:
    • /etc/inittab - contains information regarding default runlevel
    • /etc/init.d/* - system processes start-stop scripts

Boot targets management⌘

  • Management tools:
    • systemctl isolate <boot.target> - changes "runlevel" temporarily
    • systemctl <enable / disable> <boot.target> - enables / disables "runlevel"
    • systemctl set-default <boot.target> - changes "runlevel" permanently
  • Configuration files:
    • /etc/systemd - systemd configuration
    • /usr/lib/systemd - units configuration
  • Lab Exercise 101.3

First Day - Sessions III and IV⌘


Topic 102: Linux Installation and Package Management



LPIC-101-4.png
http://4.bp.blogspot.com/-5KVKyErsMGM/UVd6ULXS26I/AAAAAAAAHdk/anhTsMDFDgE/s1600/package-managers.png

102.1 Design hard disk layout⌘

LPIC-101-9.png
https://www.lpi.org/linux-certifications/programs/lpic-1/exam-102/

Disk partitioning⌘

  • Basic terms:
    • Partition - logical storage unit on the hard disk
    • Mount point - directory in the filesystem on which an additional filesystem is mounted
    • Boot flag - 1-bit value in partition table used by Windows-type boot loader to elect bootable partition
    • Swap - storage space used when the systems runs out of RAM space
    • LVM (Logical Volume Manager) - high-end disks and partitions manager
  • Designing disk layout:
    1. Should I partition my disk or install the system on the entire disk without partitioning?
    2. Should I use the default settings when partitioning the disk or should I do it manually?
    3. Should I use high-end disks and partitions manager like LVM or not?
    4. How much Swap space should I allocate for the system?
    5. Which directories in the filesystem should I place on separate partitions?
    6. What should be the size of each partition?

CHS (Cylinder-Head-Sector)⌘

  • HDD is a block device with a block size of 512 bytes (aka sector).
LPIC-101-31.JPG
http://www.datadoctor.biz/images/chap2-page16-img1.JPG
  • Lab Exercise 102.1

102.2 Install a boot manager⌘

LPIC-101-10.png
https://www.lpi.org/linux-certifications/programs/lpic-1/exam-102/

GRUB configuration⌘

  • GRUB 1:
    • /boot/grub/menu.lst - main configuration file
  • GRUB 2:
    • /boot/grub/grub.cfg - main configuration file
    • /etc/grub.d/* - GRUB 2 templates
    • /etc/default/grub - GRUB settings
    • update-grub - generates /boot/grub/grub.cfg file
    • grub-mkconfig - generates GRUB 2 configuration file
    • Full documentation available at GNU GRUB Manual 2.00

GRUB installation⌘

  • GRUB 1:
# grub                         # runs GRUB CLI
> root (hdX,Y)                 # specifies rootfs location
> setup (hdX)                  # installs GRUB into the first sector of specified disk
  • GRUB 2:
# grub-install /dev/sdX        # installs GRUB into the first sector of specified disk

Superblocks⌘

  • Basic terms:
    • Filesystem - controls how the data is stored and retrieved from the mass storage
    • Metadata - stores structural information about the filesystem
    • Superblock - metadata structure used to store information about:
      • filesystem type
      • filesystem size
      • filesystem status
      • other metadata structures
  • Basic commands:
    • dumpe2fs [filesystem] | grep -i superblock - displays location of primary and backup superblocks
    • fsck -b [location] [filesystem] - attempts to repair the filesystem using the alternative superblock
  • Lab Exercise 102.2

102.3 Manage shared libraries⌘

LPIC-101-11.png
https://www.lpi.org/linux-certifications/programs/lpic-1/exam-102/

Shared libraries⌘

  • Shared library - libraries loaded by the program during its startup
  • Naming convention:
lib[library name].so.[version]
  • Shared libraries location:
    • /lib - primary hierarchy
    • /lib64 - primary hierarchy (64-bit libraries)
    • /usr/lib - secondary hierarchy
    • /usr/lib64 - secondary hierarchy (64-bit libraries)
    • /usr/local/lib - tertiary hierarchy
    • /usr/local/lib64 - tertiary hierarchy (64-bit libraries)
    • /*/lib - other locations
    • /*/lib64 - other locations (64-bit libraries)

Shared libraries management⌘

  • Configuration files:
    • /etc/ld.so.conf - contains new-line separated list of directories in which to look for shared libraries
    • /etc/ld.so.cache - contains an ordered list of candidate libraries
  • Management tools:
    • ldd - lists shared library dependencies for the binary
    • ldconfig - creates /etc/ld.so.cache file based on the /etc/ld.so.conf file
  • Environmental variables:
    • LD_LIBRARY_PATH - contains colon-separated list of directories in which to temporarily look for additional shared libraries
  • Lab Exercise 102.3

102.4 Use Debian package management⌘

LPIC-101-12.png
https://www.lpi.org/linux-certifications/programs/lpic-1/exam-102/

Debian package management system⌘

  • Debian package managers:
    • .deb - standard Debian packages extension
    • DPKG (Debian PacKaGe) - low-end Debian package manager
    • APT (Advanced Packaging Tool) - high-end Debian package manager
  • Configuration files:
    • /etc/dpkg/dpkg.conf - contains DPKG configuration
    • /etc/apt/apt.conf - contains APT configuration
    • /etc/apt/sources.list - contains list of Debian repositories
  • Management tools:
    • dpkg - interface to DPKG
    • dpkg-reconfigure - reconfigures options of already installed packages
    • apt / apt-get - interfaces to APT
    • apt-cache - interface to APT cache
    • aptitude - alternative to APT

Debian repositories configuration⌘

  • /etc/apt/sources.list:
deb [URL] [release(-[pocket])] [components]
deb-src [URL] [release(-[pocket])] [components]
  • deb - repository of pre-compiled binary packages
  • deb-src - repository of source packages
  • URL - URL of the repository
  • distribution - release name
  • components:
    • main - packages compliant with DFSG
    • contrib - packages depending on packages non-compliant with DFSG
    • non-free - packages non-compliant with DFSG
  • Debian repository list generator: http://debgen.simplylinux.ch/

Debian packages management⌘

  • Install package:
    • dpkg -i [deb package]
    • apt-get install [package name]
  • Uninstall package:
    • dpkg -r [package name]
    • apt-get remove [package name]
  • Upgrade package:
    • dpkg -i [deb package]
    • apt-get update; apt-get install [package name]
  • Upgrade all packages:
    • apt-get update; apt-get upgrade

Debian packages management #2⌘

  • Display package using specific file:
    • dpkg -S [file]
  • Display files installed by the package:
    • dpkg -L [package name]
  • Display package dependencies:
    • dpkg -I [deb package]
    • apt-cache showpkg [package name]
  • Display package version:
    • dpkg -l [package name]
  • Lab Exercise 102.4

102.5 Use RPM and YUM package management⌘

LPIC-101-13.png
https://www.lpi.org/linux-certifications/programs/lpic-1/exam-102/

RedHat package management system⌘

  • RedHat package managers:
    • .rpm - standard RedHat packages extension
    • RPM (RPM Package Manager) - low-end RedHat package manager
    • YUM (Yellowdog Updater, Modified) - high-end RedHat package manager
  • Configuration files:
    • /etc/rpmrc - contains RPM configuration
    • /etc/yum.conf - contains YUM configuration
    • /etc/yum.repos.d - contains list of RedHat repositories
  • Management tools:
    • rpm - interface to RPM
    • yum - interface to YUM
    • rpm2cpio - converts rpm package to cpio archive
    • yumdownloader - downloads rpm package from yum repository

RedHat repositories configuration⌘

  • /etc/yum.repos.d:
[section]
name=[name]
baseurl=[URL]
enabled=[0-1]
gpgcheck=[0-1]
gpgkey=[URL]
  • section - specifies repository ID
  • name - specifies human-readable repository name
  • baseurl - URL of the repository
  • enabled - disables / enables the repository
  • gpgcheck - disables / enables GPG signature-checking during packages installation
  • gpgkey - specifies location of repository public key

RedHat packages management⌘

  • Install package:
    • rpm -i [rpm package]
    • yum install [package name]
  • Uninstall package:
    • rpm -e [package name]
    • yum remove [package name]
  • Upgrade package:
    • rpm -U [rpm package]
    • yum update [package name]
  • Upgrade all packages:
    • yum update

RedHat packages management #2⌘

  • Display package using specific file:
    • rpm -qf [file]
  • Display files installed by the package:
    • rpm -ql [package name]
  • Display package dependencies:
    • rpm -qR [rpm package]
  • Display package version:
    • rpm -qa [package name]
  • Lab Exercise 102.5

Second Day - Sessions I and II⌘


Topic 103: GNU and Unix Commands



LPIC-101-3.jpg
http://www.pihomeserver.fr/wp-content/uploads/2013/08/rm2.jpg

103.1 Work on the command line⌘

LPIC-101-14.png
https://www.lpi.org/linux-certifications/programs/lpic-1/exam-102/

Linux shell⌘

  • Shell - command-line interpreter that provides traditional user interface to Unix-like systems
  • Virtual terminal - conceptual combination of the keyboard and display for a computer user interface
  • Bash (Bourne Again Shell)
  • Basic shell commands:
    • bash - executes new bash process
    • man - displays man page for the command
    • uname - displays system information
    • pwd - displays current working directory
    • echo - prints into the standard output device

Environmental variables⌘

  • Environmental variable - variable defining a behavior of the environment
  • Management tools:
    • env - displays set environmental variables
    • export - causes the environmental variable to be inherited by child processes
    • set - sets a value of the environmental variable
    • unset - unsets the environmental variable
  • The most common environmental variables:
    • HOSTNAME - system hostname
    • USERNAME - username
    • PATH - paths in which to search for executables
    • PWD - current working directory
    • LANG - locale category

Shell I/O streams⌘

  • stdin:
    • standard input
    • file descriptor 0
    • example: keyboard
  • stdout:
    • standard output
    • file descriptor 1
    • example: display
  • stderr:
    • standard errors output
    • file descriptor 2
    • example: log file

Bash history⌘

  • Bash history management:
    • ~/.bash_history - contains history of commands executed in bash
    • history - displays history of commands executed in bash
  • Re-executing commands:
    • !! - executes the most recent command
    • !n - executes n-th command from the history
    • !-n - executes the command that is n-th from the end in the history
    • ![string] - executes the most recent command which starts with the string
    • !?[string]? - executes the most recent command which contains the string

Linux paths⌘

  • Absolute vs relative paths:
    • absolute path - full path (the same regardless of the working directory)
    • relative path - a path relative to the working directory
  • Path shortcuts:
    • . - current directory
    • .. - parent directory
    • ~ - user home directory
  • Programs execution:
    • using absolute path: i.e. /usr/local/bin/program
    • using relative path: i.e. ./program
  • Lab Exercise 103.1

103.2 Process text streams using filters⌘

LPIC-101-15.png
https://www.lpi.org/linux-certifications/programs/lpic-1/exam-102/

Filter commands⌘

  • cat - concatenates files and prints on the standard output
  • head - outputs the first part of files
  • tail - outputs the last part of files
  • nl - numbers lines of files
  • wc - prints newline, word, and byte counts for each file
  • sort - sorts lines of text files
  • uniq - reports or omits repeated lines
  • expand - converts tabs to spaces
  • unexpand - converts spaces to tabs

Filter commands #2⌘

  • fmt - simple optimal text formatter
  • cut - remove sections from each line of files
  • join - joins lines of two files on a common field
  • paste - merges lines of the file
  • pr - converts text files for printing
  • od - dumps files in octal and other formats
  • split splits a file into pieces
  • tr - translates or deletes characters
  • sed - stream editor for filtering and transforming text
  • Lab Exercise 103.2

103.3 Perform basic file management⌘

LPIC-101-16.png
https://www.lpi.org/linux-certifications/programs/lpic-1/exam-102/

File management commands⌘

  • touch - makes files / changes file timestamps
  • mkdir - makes directories
  • rm - removes files or directories
  • rmdir - removes empty directories
  • ls - lists directory contents
  • file - determines file type
  • cp - copies files and directories
  • mv - moves files and directories
  • dd - converts and copies a file

Archives⌘

  • Archive types:
    • TAR (Tape ARchive) - base UNIX archiving format, no compression
    • CPIO (CoPy In/Out) - base UNIX archiving format, no compression
    • GZIP (Gnu ZIP) - base GNU compression utility
    • BZIP2 (Burrows ZIP 2) - open-source compression utility
  • Management tools:
    • tar - tar archive management tool
    • cpio - cpio archive management tool
    • gzip / gunzip - compresses or expands files (GZIP)
    • bzip2 / bunzip2 - compresses or expands files (BZIP2)

Globbing⌘

  • ? - matches any single character
  • * - matches any string including an empty string
  • [character1character2] - matches any single character from character class
  • ![character1character2] - matches any single character out of character class
  • [character1-character2] - maches any single character from character range
  • ![character1-character2] - maches any single character out of character range
  • Lab Exercise 103.3

103.4 Use streams, pipes and redirects⌘

LPIC-101-17.png
https://www.lpi.org/linux-certifications/programs/lpic-1/exam-102/

Streams⌘

  • > - redirects output from stdout to the file and overwrites it
  • >> - redirects output from stdout to the file and appends it
  • &> - redirects output from stdout and stderr to the file and overwrites it
  • &>> - redirects output from stdout and stderr to the file and appends it
  • descriptor1>&descriptor2 - redirects output from descriptor1 to descriptor2
  • < - redirects the output from the file to stdin
  • << - redirects the output from "here document" to stdin

Pipes and redirects⌘

  • Pipe - redirects output of one command to the input of another command:
command1 | command2
  • Redirect - redirects output of one command to argument of another command:
command2 `command1`
command2 $(command1)
command2 -exec command1
  • Writing to standard output and file simultaneously:
echo test | tee /tmp/test_output
  • Executing command on multiple files:
find ~/ | xargs echo
  • Lab Exercise 103.4

103.5 Create, monitor and kill processes⌘

LPIC-101-18.png
https://www.lpi.org/linux-certifications/programs/lpic-1/exam-102/

Processes and jobs⌘

  • Process - any running program with its own address space
  • Daemon - process which runs in the background
  • Job - process started from the shell interactively
  • Foreground - process state in which terminal input is directed to process input
  • Background - process state in which terminal input is directed to shell input
  • Signal - allows interaction with processes

Linux signals⌘

  • Common signals:
    • SIGHUP (1) - hangup detected on controlling terminal or death of controlling process
    • SIGINT (2) - interrupt from keyboard
    • SIGKILL (9) - kill signal
    • SIGTERM (15) - termination signal
    • SIGSTP (18) - stop typed at terminal

Processes management⌘

  • ps - displays a snapshot of the current processes
  • top - displays dynamically updated list of the current processes
  • jobs - displays a snapshot of the current jobs
  • kill - sends a signal to the process
  • fg - restarts the job in the foreground
  • bg - restarts the job in the background
  • nohup - runs a command immune to hangups
  • & - runs the process in the background
  • Lab Exercise 103.5

103.6 Modify process execution priorities⌘

LPIC-101-19.png
https://www.lpi.org/linux-certifications/programs/lpic-1/exam-102/

Process execution priorities⌘

  • Priorities:
    • there are 40 priorities in range from -20 to 19
    • the smaller number, the higher priority
    • processes started by regular users have priority equal to 0 by default
  • Management tools:
    • nice - runs the program with specified priority
    • renice - changes priority of the running process
  • Lab Exercise 103.6

103.7 Search text files using regular expressions⌘

LPIC-101-20.png
https://www.lpi.org/linux-certifications/programs/lpic-1/exam-102/

Regular expressions⌘

  • Regular expression - sequence of characters which form a search pattern
  • Regular expression types:
    • basic - Unix-like regular expressions
    • extended - enhanced regular expressions
  • Linux search tools:
    • grep - prints lines matching pattern defined by basic regular expressions
    • egrep - prints lines matching pattern defined by extended regular expressions
    • fgrep - prints lines matching pattern defined by fixed strings

Extended regular expressions - metacharacters⌘

  • ^ - beginning of the line
  • $ - end of the line
  • \b - end of the word
  • . - any single character
  • \w - alphanumeric character
  • \W - non-alphanumeric character
  • \d - digit character
  • \D - non-digit character
  • \s - whitespace character
  • \S - non-whitespace character
  • [character1character2] - any character from the class of characters
  • [^character1character2] - any character out of the class of characters
  • () - subexpression for further reference

Extended regular expressions - alternations
and quantifiers⌘



  • Alternations:
    • expression1 | expression2 - expression1 or expression2
  • Quantifiers:
    • ? - zero or one occurance
    • * - zero or more occurrences
    • + - one or more occurrences
    • {ammount1,ammount2} - amount1 to amount2 occurrences
    • {,ammount} - amount or less occurrences
    • {ammount,} - amount or more occurrences
  • Lab Exercise 103.7

103.8 Perform basic file editing operations
using vi⌘



LPIC-101-21.png
https://www.lpi.org/linux-certifications/programs/lpic-1/exam-102/

Vi basis⌘

  • Why vi?:
    • It is installed by default in most of the Unix-like systems
    • It can be used to edit files very quickly once learnt properly
    • It is a ninja tool :)
  • Vi modes:
    • command mode - commands are accepted and text is not created
    • text mode - text is created and command are not accepted
    • Esc - switches from text mode to command mode
  • Vim (Vi IMproved) - enhanced vi program

Cursor movement⌘

  • h - moves left
  • j - moves down
  • k - moves up
  • l - moves right
  • w - moves to the beginning of the next word on the current line
  • e - moves to the end of the next word on the current line
  • b - moves to the previous word on the current line
  • Ctrl+f - scrolls forward one page
  • Ctrl+b - scrolls backward one page
  • number G - moves to the line number number
  • H - moves to the top line on the screen
  • L - moves to the bottom line on the screen

Vi commands⌘

  • i - enters insert mode before the cursor
  • a - enters insert mode after the cursor
  • x - deletes the character
  • r - replaces one character
  • R - enters replace mode before the cursor
  • dd - deletes the line
  • dnd - deletes n lines
  • o - opens a new line below the current one and enters insert mode
  • O - opens a new line above the current one and enters insert mode
  • yy - copies the line
  • yny - copies n lines
  • p - puts text after cursor deleted or copied by the last command
  • P - puts text before cursor deleted or copied by the last command

Searching for pattern and closing the file⌘

  • Searching for pattern:
    • /pattern - searches for the pattern forward
    • n - finds next pattern in the forward search
    • ?pattern - searches for the pattern backward
    • n - finds next pattern in the backward search
  • Closing the file:
    • ZZ - saves the file and exits from vi
    • :wq! - saves the file and exits from vi
    • :q! - exits from vi
    • :e! - re-opens the file

Second Day - Sessions III and IV⌘


Topic 104: Devices, Linux Filesystems, Filesystem Hierarchy Standard



LPIC-101-2.jpg
http://www.techsling.com/wp-content/uploads/2013/06/computer-repair.jpg

104.1 Create partitions and filesystems⌘

LPIC-101-22.png
https://www.lpi.org/linux-certifications/programs/lpic-1/exam-102/

Linux filesystems⌘

Filesystem Maximum file size Maximum partition size Journaling
EXT2 2TB 32TB No
EXT3 2TB 32TB Yes
EXT4 16TB 1EB Yes
XFS 8EB 8EB Yes
ReiserFS 8TB 16TB Yes
FAT32 4GB 8TB No

Partitioning disk⌘

  • fdisk (Fixed DISK) - basic partition editor:
    • m - displays help menu
    • p - prints the partition table
    • n - adds a new partition
    • d - deletes a partition
    • t - changes a partition's system id
    • w - writes table to disk and exits
  • cfdisk (C Fixed DISK) - curses-based version of fdisk
  • parted (PARTition EDitor) - advanced partition editor
  • GParted (Graphical PARTition EDitor) - graphical version of parted

Creating and mounting filesystems⌘

  • Regular filesystems:
    • mkfs - creates the filesystem
    • mkfs.filesystem - creates the filesystem of specified type
    • mount - mounts the filesystem
    • umount - unmounts the filesystem
  • Swap space:
    • mkswap - creates Swap space
    • swapon - enables Swap space
    • swapoff - disables Swap space
  • Lab Exercise 104.1

104.2 Maintain the integrity of filesystems⌘

LPIC-101-23.png
https://www.lpi.org/linux-certifications/programs/lpic-1/exam-102/

Journal and inodes⌘

  • Journal:
    • a log of recent changes made to the filesystem metadata
    • is inspected by the filesystem driver after the filesystem crash
    • contains information about recently changed parts of the filesystem
    • speeds up filesystem recovery after the crash
  • Inode:
    • metadata structure used to represent the filesystem object (file or directory)
    • stores object's attributes and its disk block locations
    • object's attributes include ownership, permissions, timestamps, etc.
    • on most of the Linux filesystems the number of inodes is fixed and pre-defined

Filesystem integrity management⌘

  • df - reports filesystem disk space usage
  • du - estimates file space usage
  • fsck - checks and repairs a Linux filesystem
  • e2fsck - checks a Linux EXT filesystems
  • debugfs - EXT filesystems debugger
  • dumpe2fs - dumps EXT filesystem information
  • make2fs - creates EXT filesystems
  • tune2fs - adjusts tunable EXT filesystem parameters
  • resize2fs - resizes EXT filesystems
  • packages for XFS filesystems management:
    • xfs_tools - for Debian-based systems
    • xfsprogs - for RedHat-based systems
  • Lab Exercise 104.2

104.3 Control mounting and unmounting of
filesystems⌘



LPIC-101-24.png
https://www.lpi.org/linux-certifications/programs/lpic-1/exam-102/

Mounting filesystems permanently⌘

  • /media - mount point for filesystems on removable devices
  • /etc/mtab - contains a list of currently mounted filesystems
  • /etc/fstab - contains associations between devices and their mount points
[device] [mount point] [type] [options] [dump] [pass]
  • device - specifes the device on which the filesystem resides
  • mount point - specifies the directory on which to mount the filesystem
  • type - specifies filesystem type
  • options - specifies mount options
  • dump - specifies whether the dump command should consider the filesystem for backup
  • pass - specifies the order of checking the filesystems at a boot time

Fstab - options⌘

  • defaults - default mount options (rw,auto,user,exec,suid,async,dev)
  • ro - mounts the filesystem in RO (Read-Only) mode
  • rw - mounts the filesystem in RW (Read-Write) mode
  • auto - the filesystem should be mounted automatically at the boot time
  • noauto - the filesystem should not be mounted automatically at the boot time
  • user - non-root user allowed to mount and unmount the filesystem
  • nouser - non-root user is not allowed to mount and unmount the filesystem
  • exec - allows execution of programs on the filesystem
  • noexec - disallows execution of programs on the filesystem

Fstab - options #2⌘

  • suid - allows execution of programs with SUID and SGID flags on the filesystem
  • nosuid - disallows execution of programs with SUID and SGID flags on the filesystem
  • sync - I/O operations are performed synchronously on the filesystem
  • async - I/O operations are performed asynchronously on the filesystem
  • dev - interprets block special devices on the filesystem
  • nodev - does not interpret block special devices on the filesystem
  • noatime - disables recording of access time timestamps
  • Lab Exercise 104.3

104.4 Manage disk quotas⌘

LPIC-101-25.png
https://www.lpi.org/linux-certifications/programs/lpic-1/exam-102/

Quotas⌘

  • Quotas:
    • define maximum allowable disk space to be used by particular user or group
    • on the XFS filesystems quotas are part of the filesystem metadata
    • on other filesystems quotas are stored in aquota.user and aquota.group files
    • quota files need to be stored in the root directory of the filesystem
    • limits in quota files are measured in 1KB blocks
  • Limit types:
    • soft - can be exceeded, warning generated
    • hard - cannot be exceeded
  • Grace period - defines for how long the soft limit can be exceeded

Quota files⌘

  • aquota.user / aquota.group:
[filesystem] [blocks] [soft] [hard] [inodes] [soft] [hard]
  • filesystem - device with the concerned filesystem
  • blocks - number of blocks used by the user
  • first soft - user's soft limit of the blocks
  • first hard - user's hard limit of the blocks
  • inodes - number of inodes used by the user
  • second soft - user's soft limit of the inodes
  • second hard - user's hard limit of the inodes

Quota management⌘

  • Quota installation:
    • Debian: apt-get install quota quotatool
    • RedHat: yum install quota
  • Management tools:
    • quota - displays disk usage and limits
    • repquota - summarizes quotas for the filesystem
    • quotacheck - scans the filesystem for disk usage and creates, checks, and repairs quota files
    • warnquota - sends e-mail to the user which is over the quota
    • edquota - edits user quotas
    • quotatool - tool to edit disk quotas from the command line
    • quotaon - turns filesystem quotas on
    • quotaoff - turns filesystem quota off
  • Lab Exercise 104.4

104.5 Manage file permissions and ownership⌘

LPIC-101-26.png
https://www.lpi.org/linux-certifications/programs/lpic-1/exam-102/

Linux permissions⌘

  • Linux permissions are stored in four bitarrays with a size of 3 bits:
    • bitarray 1 - defines special permissions (SUID, SGID and Sticky bits)
    • bitarray 2 - defines owner permissions
    • bitarray 3 - defines group permissions
    • bitarray 4 - defines others permissions
  • Linux permissions are written in one chararray with a size od 9 bits:
    • character 1-3 - defines owner permissions and SUID bit
    • character 4-6 - defines group permissions and SGID bit
    • character 7-9 - defines others permissions and Sticky bit

Owner, group and others permissions⌘

  • read:
    • displaying files and displaying directories' content
    • set on the first bit in bitarrays 2-4 for owner, group and others respectively
    • r character on chararray's 1st, 4th and 7th elements for owner, group and others respectively
  • write:
    • modifying files and modifying directories' content
    • set on the second bit in bitarrays 2-4 for owner, group and others respectively
    • w character on chararray's 2nd, 5th and 8th elements for owner, group and others respectively
  • execute:
    • executing files and entering directories
    • set on the third bit in bitarrays 2-4 for owner, group and others respectively
    • x character on chararray's 3rd, 6th and 9th elements for owner, group and others respectively

SUID, SGID and Sticky bits⌘

  • SUID (Set User ID):
    • causes that users executing the program will inherit owner's permissions, UID and GID
    • set on the first bit in bitarray 1
    • s (s + x) or S (s - x) character on chararray's 3rd element
  • SGID (Set Group ID):
    • causes that newly created files and subdirectories in the directory will inherit GID
    • set on the second bit in bitarray 1
    • s (s + x) or S (s - x) character on chararray's 6th element
  • Sticky:
    • causes that items can be removed by item's owner, directory's owner or root user
    • set on the third bit in bitarray 1
    • t (t + x) or T (t - x) character on chararray's 9th element

Setting permissions⌘

  • Permissions can be set by:
    • providing decimal representation of bitarrays followed one by one (bitarray 1 optional; 0 by default)
    • providing a principal, operation and characters of permissions
  • Principals:
    • u - item owner
    • g - item group
    • o - others
  • Operations:
    • = - sets following permissions
    • + - adds following permissions
    • - - removes following permissions

Permissions management⌘

  • chmod - changes item permissions
  • chown - changes item owner
  • chgrp - changes item group
  • umask - manages default permissions of newly created items
    • sets permissions that we want to restrict
    • default system permissions for files: 0666
    • default system permissions for directories: 0777
  • Lab Exercise 104.5

104.6 Create and change hard and symbolic
links⌘



LPIC-101-27.png
https://www.lpi.org/linux-certifications/programs/lpic-1/exam-102/

Linux links⌘

  • Link - defines a referral to another item in the filesystem
  • Link types:
    • hard links - associate multiple items with the single inode
    • soft links - point to another item in the filesystem
  • Links creation:
    • hard links:
ln linked linking
    • soft links:
ln -s linked linking
  • ls -l command

Hard links vs soft links⌘

  • Comparison:
Feature Hard links Soft links
Inode creation Do not create new inode Create new inode
Can link directories No Yes
Can cross filesystem boundaries No Yes
Linked item post-removal behaviour Does not change Stop working
Notation - l
  • Lab Exercise 104.6

104.7 Find system files and place files in the
correct location⌘



LPIC-101-28.png
https://www.lpi.org/linux-certifications/programs/lpic-1/exam-102/

FHS⌘

  • FHS (Filesystem Hirearchy Standard) - defines directory structure:
    • / - primary hierarchy root and root directory of the entire file system hierarchy
    • /bin - essential command binaries that need to be available in single user mode
    • /boot - boot loader files
    • /dev - essential devices
    • /etc - host-specific system-wide configuration files
    • /home - users' home directories containing saved files, personal settings, etc.
    • /lib - 32-bit libraries essential for the binaries in /bin and /sbin
    • /lib64 - 64-bit libraries essential for the binaries in /bin and /sbin
    • /media - mount points for removable media
    • /mnt - temporarily mounted filesystems

FHS #2⌘

    • /opt - optional application software packages
    • /proc - virtual filesystem providing information about kernel parameters
    • /root - home directory for the root user
    • /run - information about the running system since last boot
    • /sbin - essential system binaries
    • /srv - site-specific data which are served by the system
    • /sys - devices files
    • /tmp - temporary files
    • /usr - secondary hierarchy root
    • /var - variable files — files whose content is expected to continually change

Localization tools⌘

  • find - searches for files in a directory hierarchy
  • locate - used to index and quickly search for files in the system
  • updatedb - updates the database for slocate
  • whereis - locates the binary, source, and manual page files for a command
  • which - shows the full path of shell commands
  • type - shows whether the command is shell built-in or an external binary
  • Lab Exercise 104.7

Certification and Surveys⌘

Questions⌘


Thank you very much for your attention