Skip to content
Tutorials Center
My learning

Topics

Lesson 19 of 37 ยท Linux on the Pi

The Pi Filesystem and Package Management with apt

Find your way around Raspberry Pi OS: the directory tree, boot and config files, and how apt installs, updates and removes software without breaking the system.

Raspberry Pi OS is Debian Linux with a few Pi-specific extras. Once you know where things live and how packages are installed, almost every online Linux answer works on your Pi. Two skills carry most of the weight: reading the directory tree, and using apt, the package manager that installs and updates software.

On a desktop PC the disk is a large SSD. On a Pi it is usually a microSD card, which is slower and wears out under heavy writing. That makes it worth understanding what writes where. This lesson covers the layout, the Pi's special boot partition, and a safe apt routine. None of the commands here can run on this website, so the shell snippets are read-only; the runnable blocks are small Python stand-ins that model the ideas.

The directory tree

Everything in Linux hangs off one root, /. The parts you will touch most:

Path What it holds
/home/pi (or your username) Your files, scripts and settings.
/etc System-wide configuration, plain text files.
/var/log Logs. Grows over time, so watch it on a small card.
/usr/bin, /usr/local/bin Programs. Use /usr/local/bin for your own tools.
/boot/firmware The FAT boot partition: kernel, config.txt, cmdline.txt.
/dev Device files such as /dev/ttyUSB0 and /dev/i2c-1.
/sys, /proc Live kernel information, including GPIO and temperatures.
/tmp Scratch space, cleared on reboot.
Terminal
ls /
df -h              # disk usage per mounted filesystem
du -sh ~/*         # size of each item in your home folder
lsblk              # block devices: the card, USB drives

df -h on a Pi usually shows two partitions from the card: /boot/firmware (a few hundred MB, FAT) and / (the rest, ext4). If / is over 90 percent full, services start failing in odd ways, so check it first when something misbehaves.

The boot partition and config.txt

The first partition is the only one Windows and macOS can read when you plug the card into a computer. It holds the files the firmware reads before Linux starts. On Bookworm-era images it is mounted at /boot/firmware; on older images it is /boot.

Terminal
sudo nano /boot/firmware/config.txt

Typical lines in config.txt are dtparam=i2c_arm=on (enable the I2C bus) and dtoverlay=disable-bt (free the serial port). You rarely edit it by hand: sudo raspi-config changes the same lines through a menu. A mistaken edit can stop the Pi booting, so copy the file first with sudo cp config.txt config.txt.bak.

Package management with apt

A package is a bundle of files plus metadata saying which other packages it needs. apt downloads packages from repositories listed in /etc/apt/sources.list.d/, resolves the dependencies, and records what it installed so it can remove or upgrade it cleanly.

Terminal
sudo apt update                 # refresh the list of available packages
sudo apt full-upgrade           # install all available upgrades
sudo apt install python3-gpiozero sqlite3
apt search temperature          # find packages by keyword
apt show sqlite3                # description, version, dependencies
sudo apt remove sqlite3         # remove the program, keep its config
sudo apt purge sqlite3          # remove program and config
sudo apt autoremove             # drop dependencies nobody needs now

apt update does not upgrade anything; it only downloads the catalogue. The normal routine is update, then full-upgrade. Run it before installing something big, and reboot if the kernel changed.

Prefer packages named python3-xyz over pip install xyz. Debian-packaged libraries are built for the Pi and updated with the system. Recent Pi OS releases block system-wide pip install (the "externally managed environment" error); use a virtual environment, which the next chapters show.

How dependencies work

When you install A, and A needs B, and B needs C, apt installs all three in the right order. The resolver is a graph walk. This stand-in model builds a tiny catalogue and prints the install order, the same idea apt uses on thousands of packages.

Python Stand-in: resolving package dependencies

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Dependencies come first, and anything already installed is skipped. This is a model, not apt itself: the real tool also handles versions, conflicts and alternatives.

Where the disk space goes

Because the card is small, it helps to know what uses space. The next stand-in sums a made-up directory listing and shows the biggest folders, like du -sh * | sort -h would.

Python Stand-in: which folder is biggest?

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Terminal
sudo apt clean                       # delete downloaded .deb files
sudo journalctl --vacuum-size=100M   # shrink the systemd journal

Safe habits

  • Never power the Pi off while apt is running. A half-written package leaves the system inconsistent; fix it with sudo dpkg --configure -a and sudo apt -f install.
  • Install one thing at a time when learning, so you know what changed.
  • Keep a list of what you installed (apt list --manual-installed), so a rebuilt card takes minutes, not an evening.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What does sudo apt update do?

    update refreshes the catalogue; full-upgrade installs the newer versions.
  2. 2. Where is config.txt on current Raspberry Pi OS images?

    The FAT boot partition is mounted at /boot/firmware (older images used /boot).
  3. 3. Which command removes a package together with its configuration files?

    remove keeps config files; purge deletes them as well.
  4. 4. Why is it risky to pull the power while apt is installing?

    Interrupted installs can leave dpkg in an inconsistent state.

Summary

  • Linux puts everything under /; your files live in /home, settings in /etc, logs in /var/log.
  • The FAT boot partition (/boot/firmware) holds config.txt and cmdline.txt; back it up before editing.
  • apt update refreshes the list, apt full-upgrade installs upgrades, apt install/remove/purge manage packages.
  • apt resolves dependencies for you; prefer python3-* packages over system-wide pip.
  • Watch card space with df -h and clean with apt clean and journal vacuuming.

Next: Users, Groups and Permissions on the Pi