Skip to main content

Your submission was sent successfully! Close

Thank you for signing up for our newsletter!
In these regular emails you will find the latest updates from Canonical and upcoming events where you can meet our team.Close

Thank you for contacting our team. We will be in touch shortly.Close

  1. Blog
  2. Article

Oliver Smith
on 11 January 2022

How low can you go? Running Ubuntu Desktop on a 2GB Raspberry Pi 4


The little engine that could.

At Canonical we’re proud to be able to offer a full Ubuntu Desktop experience on the Raspberry Pi 4. Ubuntu Desktop provides everything you need to develop software and even deploy it to Ubuntu Server on devices like the Raspberry Pi Zero 2 W.

However the full desktop environment is quite a lot for the Pi to handle. Up until now, we’ve recommended users stick to models with either 4GB or 8GB of RAM to be confident that it will perform well. One of our goals for the upcoming Ubuntu 22.04 LTS release is to lower that barrier to entry. This means targeting a viable Desktop experience on Raspberry Pi 4 2GB models.

The secret to this optimisation is a Linux kernel feature called zswap. In this blog, we’ll show you how to enable this functionality today and benefit from the upcoming performance boost that will come as standard in 22.04.

What is zswap?

To answer that we need to talk about swap files in general.

If you’re running any kind of Linux system, it’s highly likely (and recommended) that you have a swap file allocated on your hard drive or SD card. Swap files act as a kind of overflow for your RAM, caching pages that are rarely used to free up RAM for more active processes. This enables you to keep working even when your system is using almost all of your RAM.  However, using swap is less performant than using RAM since accessing your hard drive (or SD card) is slower.

You can read more about swap in the Ubuntu Documentation.

Okay, so where does zswap come in? Zswap is essentially a compression tool. When a process is about to be moved to the swap file, zswap compresses it and checks whether the new, smaller size still needs to be moved or if it can stay in your RAM. It is much quicker to decompress a ‘zswapped’ page than it is to access the swap file so this is a great way of getting more bang for your buck from systems with smaller amounts of RAM.

Sounds great, how do I enable it?

Since zswap is supported by default, you can enable it with a simple command.

Enter the following into your terminal:

$ sudo sed -i -e 's/$/ zswap.enabled=1/' /boot/firmware/cmdline.txt

For newer Linux users, this command is basically a shortcut to edit the cmdline.txt file in your boot folder and set the zswap.enabled parameter to ‘True’ (1).

Once you’ve done this you can restart your device and benefit from an increased performance boost!

Going further…

If you’re not a confident Linux user then you can stop there. The above should already improve performance on your existing 4GB or 8GB Raspberry Pi. But this won’t yet give the smoothest performance on a 2GB device.

For more advanced users, Dave Jones, who leads the Ubuntu Raspberry Pi work at Canonical, has a few additional improvements to share.  He’s written a more detailed blog post on how he configured things on his personal blog, but we’ll paraphrase them below.

Switching to z3fold & lz4

The two additional improvements we want to implement are:

  • To increase the number of objects being compressed, using an allocator called z3fold.
  • To use a different compression algorithm called lz4 that provides a better balance of speed and compression.

Enter the following command into your terminal:

$ sudo -i

This will prompt you for your password and put you into root mode where you can enter the following commands:

# echo lz4 >> /etc/initramfs-tools/modules
# echo z3fold >> /etc/initramfs-tools/modules
# update-initramfs -u

This adds lz4 and z3fold modules to your initramfs so that they can be accessed on initialisation. Wait for the update-initramfs process to complete and then type:

# exit

To return to your normal user mode.

Finally we need to add the following commands to your cmdline.txt file similar to before:

$ sudo sed -i -e 's/$/ zswap.compressor=lz4/' /boot/firmware/cmdline.txt
$ sudo sed -i -e 's/$/ zswap.zpool=z3fold/' /boot/firmware/cmdline.txt

Then reboot (you can just type reboot in the terminal).

You can check that the changes have been made correctly by searching for the parameters using grep:

$ grep -R . /sys/module/zswap/parameters

If you’ve configured things correctly then the output should look like this:

/sys/module/zswap/parameters/same_filled_pages_enabled:Y
/sys/module/zswap/parameters/enabled:Y
/sys/module/zswap/parameters/max_pool_percent:20
/sys/module/zswap/parameters/compressor:lz4
/sys/module/zswap/parameters/zpool:z3fold
/sys/module/zswap/parameters/accept_threshold_percent:90

A speed boost for Ubuntu Desktop on Raspberry Pi!

If the above tutorial seemed a little complicated, don’t worry. When Ubuntu 22.04 releases in April, these optimisations will be included by default for all Raspberry Pi 4 devices, including the 400!

However, if you do make these changes and try them out on a 2GB Raspberry Pi 4 we’d love to hear about how much it has improved your performance. Let us know if you feel it delivers a quality Ubuntu Desktop experience for 2GB users.

You can reach out to us on the Raspberry Pi category of the Ubuntu Discourse.

Read more about Ubuntu Desktop on Raspberry Pi

Related posts


Oliver Smith
11 December 2023

End of year review: Ubuntu Desktop in 2023

Desktop Article

As 2023 draws to a close, it’s time to look back on the evolution of Ubuntu Desktop over the last twelve months. ...


Canonical
13 October 2023

Canonical, 우분투 23.10 맨틱 미노타우르스 출시

Canonical announcements Canonical News

강화된 보안, 향상된 데스크톱 앱 검색 및 새로운 하드웨어 지원이 최신 우분투 출시를 주도합니다. 2023년 10월 12일: 오늘 Canonical은 코드명 “맨틱 미노타우르스”인 우분투 23.10의 출시를 발표하였으며, https://ubuntu.com/download에서 다운로드하여 설치할 수 있습니다. Canonical의 우분투 수석 제품 관리자인 올리버 스미스(Oliver Smith)는 “이번 출시에서는 기본적으로 우분투의 보안의 의미에 대한 기준을 높이고 다음 장기 지원 출시를 위한 발판을 마련했습니다. ...


Canonical
12 October 2023

Canonical releases Ubuntu 23.10 Mantic Minotaur

Canonical announcements Article

Fortified security, enhanced desktop app discovery and new hardware support lead the latest release of Ubuntu 23.10 Mantic Minotaur. ...