Linux Basics

Linux Basics — Introduction

Linux is the foundation of almost every embedded system, server, cloud platform, and AI workstation in existence. Understanding it is not optional for anyone working in embedded systems or machine learning.


What is Linux?

Linux is an open-source operating system kernel — the core software that manages the hardware of a computer. It was created in 1991 by Linus Torvalds, a Finnish computer science student who posted the first version on the internet for free.

The kernel is responsible for:

  • CPU scheduling — deciding which program runs on which core and for how long
  • Memory management — allocating RAM to programs, preventing one from corrupting another
  • Device drivers — translating between hardware signals and software calls
  • File system — organizing files on disks, SD cards, USB drives
  • Network stack — handling Ethernet, Wi-Fi, Bluetooth at the lowest level

The Kernel vs. The Distribution

When people say "Linux" in conversation, they almost always mean a Linux Distribution, not the kernel itself.

WhatWhat It Is
Linux KernelJust the core — no desktop, no apps, no shell by default
Distribution (Distro)Kernel + shell + package manager + desktop + apps, bundled together
DistributionBased OnBest For
UbuntuDebianDesktops, laptops, embedded dev workstations
DebianItselfServers, Raspberry Pi OS base
Raspberry Pi OSDebianRaspberry Pi SBCs
Arch LinuxItselfAdvanced users, rolling releases
Alpine LinuxItselfMinimal Docker containers, IoT gateways
FedoraRed HatDevelopers, newer kernel features
CentOS / RHELRed HatEnterprise servers

For embedded and AI development, Ubuntu LTS (Long Term Support) and Raspberry Pi OS are the two you will encounter most frequently.


Why Linux for Embedded and AI Development?

1. Native Toolchain Support

Every major embedded toolchain — GCC for ARM, RISC-V, ESP32 Xtensa, OpenOCD, GDB, CMake, Ninja — was written for Linux first. On Linux, they install in one line. On Windows, they require workarounds.

2. Everything is a File

This is the core Unix philosophy. In Linux:

  • Your serial port (ESP32 UART) → /dev/ttyUSB0
  • Your I2C bus → /dev/i2c-1
  • Your SPI device → /dev/spidev0.0
  • Your GPU → /dev/nvidia0
  • Even running processes → /proc/1234/

This makes writing code that talks to hardware dramatically simpler than Windows COM ports and registry entries.

3. Package Management

Installing a tool takes one command, not a download wizard:

bash
sudo apt install python3 git cmake ninja-build openocd

4. Process and Service Management

Running your ML inference service or embedded gateway as a background service, with automatic restart on crash, is built into Linux via systemd.

5. Deployment Reality

Any production embedded gateway, cloud server, or Raspberry Pi you deploy to runs Linux. You must understand the environment you ship code to.


The Linux Boot Process (Simplified)

Understanding the boot sequence is useful for embedded engineers who work on custom BSPs (Board Support Packages).

text
Power On

BIOS / UEFI (firmware)

Bootloader (GRUB on x86, U-Boot on ARM/embedded)

Linux Kernel loads (decompresses into RAM, initializes CPU, MMU, drivers)

initramfs (temporary root filesystem for early hardware init)

init system (systemd) — starts all services and user sessions

Login Prompt / Desktop

On embedded targets (Raspberry Pi, BeagleBone), the bootloader is U-Boot and the first thing it loads is the kernel image plus the Device Tree Blob (DTB) — a binary file describing which hardware peripherals exist on the board.


The Terminal (CLI)

The Terminal is the most powerful tool in Linux. It is a text-based interface where you type commands and read their output. Professional embedded and ML engineers spend the majority of their working time here.

Reasons professionals prefer the terminal over the GUI:

  • Speed — one command to install, compile, flash, and monitor
  • Scripting — automate repetitive tasks completely
  • Remote access — SSH into a Raspberry Pi from 10,000 km away
  • Reproducibility — document the exact steps to set up an environment in a script

Opening a Terminal

OSHow
UbuntuCtrl + Alt + T
macOSCmd + Space → type "Terminal"
WSL (Windows)Search "WSL" or "Ubuntu" in Start menu
SSH to remote Linuxssh username@hostname

Processes and the Process Tree

Every program running on Linux is a process. Each process has a unique PID (Process ID). The very first process is always systemd or init with PID 1. Every other process is a child of it.

bash
ps aux          # List all running processes
ps aux | grep python   # Filter for Python processes
top             # Live CPU and memory usage dashboard
htop            # Improved version of top (install with: sudo apt install htop)
kill 1234       # Send SIGTERM to process 1234 (graceful stop)
kill -9 1234    # Send SIGKILL (force stop, no cleanup)

Users and Groups

Linux is a multi-user operating system. Every file, process, and resource is owned by a user and belongs to a group.

bash
whoami          # Print your current username
id              # Show your user ID (UID) and group memberships
who             # Show who is logged into the system
last            # Show recent logins

The Root User

root is the superuser — it can do anything on the system. You should never log in as root directly. Instead, use sudo to temporarily elevate privileges for a single command.

bash
sudo apt update         # Run as root for just this one command
sudo -i                 # Open a root shell (use sparingly)

System Information Commands

bash
uname -a          # Kernel version and architecture
lsb_release -a    # Distribution name and version
hostname          # Machine hostname
uptime            # How long the system has been running
df -h             # Disk space usage (human-readable)
free -h           # RAM and swap usage
lscpu             # CPU information (cores, architecture, MHz)
lsusb             # List USB devices (important for ESP32 and ST-LINK)
lspci             # List PCI devices (GPU, Ethernet card, etc.)
dmesg | tail -20  # Last kernel log messages (useful for hardware debugging)

Environment Variables

Environment variables are key-value pairs that the shell passes to every process it starts. They configure the runtime environment.

bash
echo $HOME        # Your home directory
echo $PATH        # Directories searched for executables
echo $USER        # Your username
echo $SHELL       # Your current shell (bash, zsh, etc.)

# Set a temporary variable (only for this session)
export MY_VAR="hello"
echo $MY_VAR

# Make it permanent — add to ~/.bashrc
echo 'export MY_VAR="hello"' >> ~/.bashrc
source ~/.bashrc       # Reload .bashrc without logging out

Why PATH Matters for Embedded Dev

When you install ESP-IDF or a cross-compiler, you must add its bin/ directory to $PATH so the shell can find commands like idf.py, arm-none-eabi-gcc, or riscv32-esp-elf-gcc.

bash
# Add ESP-IDF tools to PATH
export PATH="$HOME/esp/esp-idf/tools:$PATH"

Quick Command Reference

CommandWhat It Does
man <cmd>Open the manual page for any command
<cmd> --helpQuick help / flag list
which <cmd>Show the full path of a command
type <cmd>Show whether it's a built-in, alias, or binary
historyShow recent command history
!!Re-run the last command
Ctrl + CKill the current running command
Ctrl + ZSuspend the current command to background
bgResume a suspended command in the background
fgBring a background command back to foreground
clearClear the terminal screen
exitClose the terminal session
Previous
Before You Begin