Skip to content

Installing DietPi on a Raspberry Pi 4B's SD Card

If you're planning to set up a Raspberry Pi 4B with DietPi, you're in the right place. In this developer guide, I'll walk through the steps to install DietPi on an SD card, preparing your Raspberry Pi for your homelab.

Prerequisites

Before you get started, make sure you have the following:

  • A Raspberry Pi 4B (or later) board.
  • A compatible microSD card (16GB or larger is recommended).
  • A computer with an SD card reader.
  • An internet connection to download the necessary files.

Download DietPi Image

  1. Visit the DietPi website and navigate to the Downloads section.

  2. Choose the DietPi image for Raspberry Pi 4B. Ensure that you download the correct image for your board.

Flash the DietPi Image

To install DietPi on your Raspberry Pi's SD card, you'll need to flash the downloaded image. You can use a tool like Raspberry Pi Imager for this purpose. Here are the steps:

  1. Insert your microSD card into your computer's SD card reader.

  2. Open the Raspberry Pi Imager or your preferred SD card flashing tool.

  3. In the software, select the DietPi image you downloaded earlier.

  4. Choose the correct microSD card as the target for the image.

  5. Click the "Write" button to start the flashing process.

Great choice! Configuring a headless installation by adjusting the dietpi.txt file allows you to set up your Raspberry Pi without the need for a physical monitor, keyboard, or mouse. Here are the steps to perform a headless DietPi installation on your Raspberry Pi 4B:

Configure dietpi.txt

After flashing the DietPi image, remove the microSD card from your computer and insert it back into your computer's SD card reader.

You'll find a file named dietpi.txt at the root of the SD card. Open this file in a text editor.

Here is my setup to install headless

AUTO_SETUP_ACCEPT_LICENSE=1
AUTO_SETUP_LOCALE=C.UTF-8
AUTO_SETUP_KEYBOARD_LAYOUT=us
AUTO_SETUP_TIMEZONE=Europe/Amsterdam
AUTO_SETUP_NET_ETHERNET_ENABLED=1
AUTO_SETUP_NET_WIFI_ENABLED=0
AUTO_SETUP_NET_ETH_FORCE_SPEED=0
AUTO_SETUP_NET_WIFI_COUNTRY_CODE=SK

AUTO_SETUP_NET_USESTATIC=1
AUTO_SETUP_NET_STATIC_IP=192.168.86.101
AUTO_SETUP_NET_STATIC_MASK=255.255.255.0
AUTO_SETUP_NET_STATIC_GATEWAY=192.168.86.1
AUTO_SETUP_NET_STATIC_DNS=1.1.1.1 8.8.8.8

AUTO_SETUP_DHCP_TO_STATIC=0

AUTO_SETUP_NET_HOSTNAME=cluster_1

AUTO_SETUP_BOOT_WAIT_FOR_NETWORK=1
AUTO_SETUP_SWAPFILE_SIZE=1
AUTO_SETUP_SWAPFILE_LOCATION=/var/swap
AUTO_SETUP_HEADLESS=1
AUTO_UNMASK_LOGIND=0
AUTO_SETUP_CUSTOM_SCRIPT_EXEC=0
AUTO_SETUP_BACKUP_RESTORE=0
AUTO_SETUP_SSH_SERVER_INDEX=-2
AUTO_SETUP_LOGGING_INDEX=-1
AUTO_SETUP_RAMLOG_MAXSIZE=200

AUTO_SETUP_WEB_SERVER_INDEX=0
AUTO_SETUP_DESKTOP_INDEX=0
AUTO_SETUP_BROWSER_INDEX=0
AUTO_SETUP_AUTOSTART_TARGET_INDEX=7
AUTO_SETUP_AUTOSTART_LOGIN_USER=root
AUTO_SETUP_GLOBAL_PASSWORD=dietpi
AUTO_SETUP_AUTOMATED=1
SURVEY_OPTED_IN=0

#OpenSSH Client
AUTO_SETUP_INSTALL_SOFTWARE_ID=0
#Samba Client
AUTO_SETUP_INSTALL_SOFTWARE_ID=1
#vim
AUTO_SETUP_INSTALL_SOFTWARE_ID=20
#RPi.GPIO
AUTO_SETUP_INSTALL_SOFTWARE_ID=69
#OpenSSH Server
AUTO_SETUP_INSTALL_SOFTWARE_ID=105
#Python 3 pip
AUTO_SETUP_INSTALL_SOFTWARE_ID=130

CONFIG_CPU_GOVERNOR=schedutil
CONFIG_CPU_ONDEMAND_SAMPLE_RATE=25000
CONFIG_CPU_ONDEMAND_SAMPLE_DOWNFACTOR=40
CONFIG_CPU_USAGE_THROTTLE_UP=50

CONFIG_CPU_MAX_FREQ=Disabled
CONFIG_CPU_MIN_FREQ=Disabled

CONFIG_CPU_DISABLE_TURBO=0

CONFIG_PROXY_ADDRESS=MyProxyServer.com
CONFIG_PROXY_PORT=8080
CONFIG_PROXY_USERNAME=
CONFIG_PROXY_PASSWORD=

CONFIG_G_CHECK_URL_TIMEOUT=10
CONFIG_G_CHECK_URL_ATTEMPTS=5
CONFIG_CHECK_CONNECTION_IP=8.8.8.8
CONFIG_CHECK_DNS_DOMAIN=google.com

CONFIG_CHECK_DIETPI_UPDATES=1
CONFIG_CHECK_APT_UPDATES=1
CONFIG_NTP_MODE=2
CONFIG_SERIAL_CONSOLE_ENABLE=0
CONFIG_SOUNDCARD=none
CONFIG_LCDPANEL=none
CONFIG_ENABLE_IPV6=0

CONFIG_APT_RASPBIAN_MIRROR=http://raspbian.raspberrypi.org/raspbian/
CONFIG_APT_DEBIAN_MIRROR=https://deb.debian.org/debian/
CONFIG_NTP_MIRROR=debian.pool.ntp.org

#------------------------------------------------------------------------------------------------------
##### DietPi-Software settings #####
#------------------------------------------------------------------------------------------------------
SOFTWARE_DISABLE_SSH_PASSWORD_LOGINS=0

#------------------------------------------------------------------------------------------------------
##### Dev settings #####
#------------------------------------------------------------------------------------------------------
DEV_GITBRANCH=master
DEV_GITOWNER=MichaIng

#------------------------------------------------------------------------------------------------------
##### Settings, automatically added by dietpi-update #####
#------------------------------------------------------------------------------------------------------
  • Locale and Keyboard Layout: AUTO_SETUP_LOCALE: Configured as C.UTF-8. Adjust the locale if needed for other language settings.

  • Timezone: AUTO_SETUP_TIMEZONE: Set to Europe/Amsterdam. Change the timezone to match your location.

  • Network Configuration: IP Address, Subnet Mask, Gateway, and DNS settings are specified. These settings should be reviewed and adjusted according to your network configuration, especially if you're setting up multiple Raspberry Pi devices.

  • Hostname: AUTO_SETUP_NET_HOSTNAME: Currently set to cluster_master. Customize the hostname as required for each Raspberry Pi.

  • Global Password: AUTO_SETUP_GLOBAL_PASSWORD is set to dietpi. Change the global password to enhance security.

  • Installed Software: Software packages to be installed are specified under AUTO_SETUP_INSTALL_SOFTWARE_ID. Review and adjust the list according to your requirements.

  • DietPi-Software Settings: SOFTWARE_DISABLE_SSH_PASSWORD_LOGINS is set to 0, allowing SSH password logins. Adjust if you prefer SSH key-based authentication.

These settings should be reviewed and customized according to your specific requirements for each Raspberry Pi device in your setup. Make sure they match your network, security, and performance preferences.

Explenation on all values can be found here.

Configure cmdline.txt

Open the file and append to the only line in the file:

group_enable=cpuset cgroup_enable=memory cgroup_memory=1

Warning

Do not replace the whole line just append the group_enable=cpuset cgroup_enable=memory cgroup_memory=1 to the end.

It should look something like this

root=PARTUUID=92b3e04f-02 rootfstype=ext4 rootwait fsck.repair=yes net.ifnames=0 logo.nologo console=serial0,115200 console=tty1 group_enable=cpuset cgroup_enable=memory cgroup_memory=1

Eject SD Card

Once you have adjusted the dietpi.txt and cmdline.txt you can safely eject the microSD card from your computer.

Boot Your Raspberry Pi

  • Insert the microSD card into your Raspberry Pi's microSD card slot.

  • Power on your Raspberry Pi.

Find Raspberry Pi's IP Address

  • You can find your Raspberry Pi's IP address on your local network through your router's interface, or you can use an IP scanner tool on your computer. Look for a device with the hostname "dietpi."

SSH Access

Once you have the IP address, you can access your Raspberry Pi via SSH. Use a terminal on your computer and the following command, replacing YOUR_RASPBERRY_PI_IP with your Raspberry Pi's IP address:

ssh root@YOUR_RASPBERRY_PI_IP
Info

When prompted, use the password you specified in the dietpi.txt in the initial DietPi setup.