Skip to content
Tutorials Center
My learning

Topics

Lesson 7 of 37 ยท Setup and OS

raspi-config, config.txt and Updates

Configure your Pi with raspi-config, edit config.txt and cmdline.txt safely, enable interfaces like I2C and SPI, and keep the system updated with apt.

Your Pi is running. Before you build anything, take ten minutes to configure it properly and bring it up to date. Two tools do most of the work: raspi-config, a text menu for common settings, and apt, the Debian package manager that installs software and security fixes. You will also meet the two hardware settings files, config.txt and cmdline.txt, which control what the firmware does before Linux starts.

raspi-config

Open a terminal (over SSH or on the desktop) and run:

Terminal
sudo raspi-config

sudo runs the command with administrator rights. The menu is keyboard driven: arrow keys move, Enter selects, Tab jumps to Select/Finish. The most useful areas:

  • System Options. Hostname, password, Wi-Fi, boot behavior (desktop or console, login or auto-login).
  • Display Options. Resolution and screen blanking.
  • Interface Options. Enable or disable SSH, I2C, SPI, Serial Port, Camera, 1-Wire and Remote GPIO. Most sensors in this course need one of these turned on.
  • Performance Options. Fan control, overclocking on older models, and GPU memory.
  • Localisation Options. Locale, time zone, keyboard layout, Wi-Fi country.
  • Advanced Options. Expand the file system and update the tool.

You can also use it without the menu, which is great for scripts. A value of 0 means enable in this tool:

Terminal
sudo raspi-config nonint do_i2c 0     # enable I2C
sudo raspi-config nonint do_spi 0     # enable SPI
sudo raspi-config nonint do_ssh 0     # enable SSH
sudo raspi-config nonint get_i2c      # prints 0 if enabled, 1 if disabled

In raspi-config scripting, 0 means "yes" (the Unix success code), which surprises people. do_i2c 0 enables I2C and do_i2c 1 disables it.

config.txt and cmdline.txt

Behind the menus, two text files hold the settings. On current Raspberry Pi OS they are /boot/firmware/config.txt (older systems used /boot/config.txt) and /boot/firmware/cmdline.txt. The first sets hardware options as key=value lines or dtparam and dtoverlay entries:

TEXT
# config.txt (read-only excerpt)
dtparam=i2c_arm=on
dtparam=spi=on
dtoverlay=disable-bt
gpu_mem=128

dtparam switches built-in features and dtoverlay loads a device tree overlay, a small description that tells the kernel about extra hardware such as a sensor, a display or a HAT. cmdline.txt is different: it is a single line of kernel options. Never insert a line break in it or the system will not boot.

Always back up before editing:

Terminal
sudo cp /boot/firmware/config.txt /boot/firmware/config.txt.bak
sudo nano /boot/firmware/config.txt

Updating the system

A fresh image may be weeks or months old. Update right away and then regularly:

Terminal
sudo apt update          # refresh the list of available packages
sudo apt full-upgrade    # install newer versions, handling dependencies
sudo reboot              # needed after kernel or firmware updates

To add software, use apt install (read-only examples):

Terminal
sudo apt install -y git python3-gpiozero python3-pip
apt list --upgradable      # what is waiting
sudo apt autoremove        # clean unused dependencies

Firmware is part of the package system on current releases, so full-upgrade updates it too. For Python libraries you may meet a message about an "externally managed environment": system Python is protected so pip cannot break it. Use apt for system-wide packages or create a virtual environment for your own, which Python on the Pi touches on.

Try it: a config.txt editor

Editing a settings file by hand is error-prone. This stand-in parses a small config.txt text, enables an option safely and prints the result, similar to what raspi-config does.

Python Stand-in: toggle a config.txt option

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.

Try it: pending updates report

A script can summarize apt output. The stand-in below reads a pretend apt list --upgradable result and counts the pending updates by source.

Python Stand-in: summarize pending updates

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.

A good first-day checklist

  1. sudo apt update && sudo apt full-upgrade -y, then reboot.
  2. Run sudo raspi-config: set the Wi-Fi country, time zone and locale.
  3. Enable the interfaces you will need (I2C, SPI, camera) and leave the rest off.
  4. Change the default password if you did not set a strong one.
  5. Take a note of the board's IP address with hostname -I.

Turning off interfaces you do not use is a good habit: fewer open features means fewer surprises and less attack surface.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which tool provides a text menu to enable I2C, SPI and SSH?

    raspi-config has an Interface Options menu for these features.
  2. 2. What is special about cmdline.txt?

    The kernel reads it as one line of options; a line break can stop the Pi from booting.
  3. 3. Which command installs newer versions of all installed packages?

    update only refreshes the package list; full-upgrade installs the new versions.
  4. 4. What does a dtoverlay line in config.txt do?

    Overlays tell the kernel about HATs, sensors and other hardware.

Summary

  • sudo raspi-config configures the system; its nonint mode is scriptable and uses 0 for enable.
  • config.txt holds hardware options and overlays; cmdline.txt is one line of kernel options. Back up before editing.
  • Run apt update and apt full-upgrade regularly and reboot after kernel updates.
  • Enable only the interfaces you need.

Next: Storage: SD Cards, SSDs and Booting