Tag: lpic1

  • LPIC-1 Lesson 101.1 Cheat Sheet

    I know this might be easy for most, but as I’ve learnt something new while reviewing this, I am sure someone else will too.

    BIOS vs UEFI

    • BIOS — Basic Input Output System
    • UEFI — Unified Extensible Firmware Interface
    • BIOS is older; UEFI is newer and improved

    Hardware discovery

    A kernel module is similar to a driver on Windows.

    lspci

    Shows all devices currently connected to the PCI (Peripheral Component Interconnect) bus.

    lspci                    # list all available pci devices
    lspci -s [hex_address] -v # verbose detail about a specific device
    lspci -s [hex_address] -k # verify which kernel module is in use

    lsusb

    Lists USB (Universal Serial Bus) devices currently connected to the machine.

    lsusb              # list usb devices
    lsusb -v -d [ID]   # detailed output for a specific device by ID
    lsusb -t           # show current usb device mapping as a tree
    lsusb -s bus:dev   # verify which device is using that module, e.g. lsusb -s 01:02

    Others

    • lshw — extracts detailed information about hardware
    • lsblk — lists block devices

    Kernel modules

    kmod is the preferable way to interact with kernel modules, and can also be called using:

    • modprobe — add and remove modules from the Linux kernel
    • lsmod — shows the status of modules in the Linux kernel
    • rmmod — simple program to remove a module from the kernel
    • insmod — simple program to insert a module into the kernel
    • modinfo — shows info about a kernel module
    • depmod — generates modules.dep and map files
    sudo modprobe module_name        # load a module
    sudo modprobe -r module_name     # remove a module
    sudo rmmod module_name           # remove a module
    sudo rmmod -f module_name        # force remove a module
    sudo insmod /path/to/module.ko   # load a module, does NOT handle dependencies
    modinfo module_name              # detailed information about a kernel module
    modinfo -p module_name           # list specific module parameters
    depmod -a kernel_version         # generate for a specific kernel version

    Important files

    • /etc/modules — add modules here to load at boot (deprecated)
    • /etc/modprobe.d/ — use instead of /etc/modules; add module config files here to load at boot

    Kernel module parameters can be changed while the kernel is at boot:

    • /etc/modprobe.conf — customise module parameters to make them persistent
    • /etc/modprobe.d/ — add individual .conf files to customise module parameters
    • /etc/modprobe.d/blacklist.conf — add a module name here to block it loading
    • /etc/modprobe.d/<module_name>.conf — preferred method for blocking a module, containing settings specific only to that module

    Pseudo-filesystems

    These only exist while the system is running, and are not intended for conventional file storage.

    /proc

    Contains files with information regarding running processes and hardware resources.

    • /proc/cpuinfo — detailed information about the CPU(s) found by the operating system
    • /proc/interrupts — numbers of interrupts per IO device for each CPU
    • /proc/ioports — currently registered Input/Output port regions in use
    • /proc/dma — registered DMA (direct memory access) channels in use

    sysfs

    A pseudo-filesystem providing an interface to kernel data structures. The files under sysfs provide information about devices, kernel modules, filesystems and other kernel components, all mounted in /sys.

    /sys has a similar role to /proc, but with the specific purpose of storing device information and kernel data related to hardware.

    udev subsystem

    Removable devices are handled by the udev subsystem, which creates the corresponding devices in /dev.

    • /dev/ — every file inside is associated with a system device, particularly storage devices
    • /etc/udev/rules.d/ — as new devices are detected, udev searches here for a matching rule
    • /dev/hdc — CD/DVD
    • /dev/fd0 — floppy disk
    • /dev/sda — IDE, SSD and USB
    • /dev/mmcblk0p1 — SD cards
    • /dev/nvme0n1p1 — NVMe

    Since Linux kernel version 2.4, most storage devices are identified as if they were SCSI devices, regardless of their hardware type.

    Linux distributions and package managers

    • Debian-based — uses dpkg, with apt (Advanced Packaging Tool) as package manager
    • RPM-based — uses rpm, with yum (Yellowdog Updater Modified) or DNF as package manager

    Debian-based common commands

    sudo dpkg -i [package.deb]   # install
    sudo dpkg -r [package]       # remove
    sudo dpkg -P [package]       # purge: remove config files
    sudo dpkg -c [package.deb]   # list contents
    dpkg -s [package]            # check status
    sudo dpkg -R -i [directory]  # install from directory
    dpkg -I [package.deb]        # show package info
    sudo dpkg --unpack [package.deb]  # unpack contents
    dpkg -l                      # list installed packages

    RPM-based common commands

    sudo rpm -ivh [package.rpm]  # install
    sudo rpm -e [package]        # remove
    sudo rpm -Uvh [package.rpm]  # upgrade
    
    rpm -Vp [package.rpm]        # verify (specific)
    rpm -Va                      # verify (all)
    
    # query
    rpm -qdf [package]           # documentation
    rpm -qi [package]            # installed info
    rpm -qip [package.rpm]       # package info from file