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.
| What | What It Is |
|---|---|
| Linux Kernel | Just the core — no desktop, no apps, no shell by default |
| Distribution (Distro) | Kernel + shell + package manager + desktop + apps, bundled together |
Popular Distributions
| Distribution | Based On | Best For |
|---|---|---|
| Ubuntu | Debian | Desktops, laptops, embedded dev workstations |
| Debian | Itself | Servers, Raspberry Pi OS base |
| Raspberry Pi OS | Debian | Raspberry Pi SBCs |
| Arch Linux | Itself | Advanced users, rolling releases |
| Alpine Linux | Itself | Minimal Docker containers, IoT gateways |
| Fedora | Red Hat | Developers, newer kernel features |
| CentOS / RHEL | Red Hat | Enterprise 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:
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).
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
| OS | How |
|---|---|
| Ubuntu | Ctrl + Alt + T |
| macOS | Cmd + Space → type "Terminal" |
| WSL (Windows) | Search "WSL" or "Ubuntu" in Start menu |
| SSH to remote Linux | ssh 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.
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.
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.
sudo apt update # Run as root for just this one command
sudo -i # Open a root shell (use sparingly)
System Information Commands
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.
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.
# Add ESP-IDF tools to PATH
export PATH="$HOME/esp/esp-idf/tools:$PATH"
Quick Command Reference
| Command | What It Does |
|---|---|
man <cmd> | Open the manual page for any command |
<cmd> --help | Quick help / flag list |
which <cmd> | Show the full path of a command |
type <cmd> | Show whether it's a built-in, alias, or binary |
history | Show recent command history |
!! | Re-run the last command |
Ctrl + C | Kill the current running command |
Ctrl + Z | Suspend the current command to background |
bg | Resume a suspended command in the background |
fg | Bring a background command back to foreground |
clear | Clear the terminal screen |
exit | Close the terminal session |

