More efficiency for your Raspberry Pi easily with DietPi!

In this post I’m explaining how to install DietPI on a Raspberry Pi (a Raspberry Zero 2 W in this case) in a Headless mode so there is no need to have a display, mouse or even a keyboard. The initial configuration must be done by using a file called dietpi.txt (and dietpi-wifi.txt if you want a WIFI configuration).

Let’s start!

The first step is “baking” the SD card with the image downloaded in the official website of the project (, I will do it using Raspberry Imager, choosing the Choose OS – Use custom option but it can be done by using other tools like Balena Etcher or Win32 disk imager (in a Windows environment, obviously).

Raspberry imager
Raspberry imager

Once the image is written into the SD card, pull it off and plug it again, so it opens the flashed device and you can navigate to it, you must see the dietpi.txt and dietpi-wifi.txt files.

Diet Pi configuration file
The dietpi.txt file

Now, open the dietpi.txt and search for the fields we have to modify, in my case I modified the keyboard layout, which I set to “es” (Spanish).

Set the keyboard layout for Diet Pi
Setting the keyboard layout

Set the desired hostname which in my case is “DietPI”.

Set the hostname for Diet Pi
Setting the device hostname

I disabled the Ethernet interface (there is no ethernet interface in the Raspi Zero 2 W, so…) and enabled the WIFI interface.

Enable WIFI for Diet Pi
Enable or disable the interfaces

I disabled the HDMI port as this will be a headless server and it saves a little MB of memory.

Disable the HDMI port in Diet Pi
Disabling the HDMI port

The rest of configurations will be by default so they can be modified with the initial run of the script.

Setting up the WIFI interface

Now, to configure the WIFI interface, open the dietpi-wifi.txt and, in the first section we are going to enter the WIFI SSID and the password.

Set WIFI configuration for Diet Pi
Set the WIFI parameters

Connect via SSH and finish the configuration

Once done this, eject the SD card and plug it in the Raspi (or the device in your case, maybe an ODROID, banana pi, etc.) and plug the power cord. After a 3-5 minutes loading, you will have to find the IP address of the device, I searched it in the DHCP to find out the IP address. At this point you can connect to the device via SSH, I use the Windows terminal and connect it by using the command ssh user@ip, the default user/password, that is root/dietpi.

SSH connection string
SSH connection

Once connected, it Will launch the first launch script and will ask for the acceptance of the Terms & conditions

Terms and condifitons of Diet Pi
Terms and conditions of Diet Pi

Now it is going to launch several processes, as you can see in the following picture.

Initial configuration of Diet Pi
Initial configuration of Diet Pi

Now change the default passwords.

Changing default password in Diet Pi
Changing the passwords

The next thing I want is to disable the serial interface because I don’t have one, if you neither or don’t know what this is. It will save a memory (just a little bit).

Disable serial interface in Diet Pi
Disable serial interface

The next step will be asking for the default software to install because there is some software that will install by default if there is another application that demands it, for example, it will only install a Graphical Desktop Interface (LXDE, MATE or whatever you choose) if there is an application requiring it, Firefox for example. I will only change the SSH Server, as Dropbear do not offer SFTP support for secure file transfer, I’ll choose OpenSSH server.

Set default software in Diet Pi
Change default software

When you accept this menu, it will tell you that this can be modified at anytime by invoking the command dietpi-software.

invoke teh Diet Pi configuration defaults

In the last step it will ask if we want to participate in the DietPi survey to enhance the OS in the future.

Join Diet Pi survey
Diet Pi Survey

Check your efficiency!

Once done this, all the initial configurations will be done and it will show the initial menu, that will show some useful commands to configure the system and/or install software. In my case, by running the htop application will show the ridiculous memory usage in my Raspberry Pi Zero 2 W, that is around 54 MB.

Memory usage of Diet Pi
Memory usage of Diet Pi on a Raspberry Pi Zero 2 W

So let’s go! Try this new OS for the tiny Raspberry Pi and save some memory!

Remember to check the Azure Basics course starting at the creation of a brand new Virtual Machine or a SQL database!