NVMe 256GB SDD on the RPi5 & ramping up the swapfile size (as you do)

I purchased a couple of the great Pimoroni NVMe Base boards, one I bought with the supplied 256Gb SSD (fitted it to the RPi5 8Gb machine), where I promptly broke the connector on the board for plugging it into the RPi5... so I ordered another base unit without the SSD drive - then purchased a cheap FikWot FN501 Pro 256Gb from Amazon and took a gamble.  I set that board up on the RPi5 4Gb machine.  Just to be clear, it was a faff & was a bit hit & miss.  why?


Well, I believe I had to install the Bookworm Raspberry Pi OS onto an SD-Card, go through all of that, then make the tweaks to the /boot/firmware/config.txt file, upgrade the RPi5 eeprom to the latest version, etc.. and then run Raspi Imager to flash the SSD drive once it was detected.  This would have been simple had the SDCard I used not been a little "unstable" :-)

It did work for the 8Gb RPi5 and all was good - after completion, the machine boots from the SSD into the latest UBuntu.  awesome, exactly what I wanted.

However, attempting to repeat the exercise on the 4Gb RPi5 was met with "challenges".  Now, with hindsight, this may have been due to the FikWot SSD not being formatted? therefore not partitioned, therefore not detected, I don't know.  Will have to repeat the exercise again at some point in the future to find out.  anyway, the previous SDCard was not playing ball in this RPi5 machine.  sigh.

So, I opted to use the existing UBuntu SDCard that I was booting the machine with - and see if I could use gparted to make partition table, format the drive - make the previous tweaks, set the BOOT_ORDER value, was still not having it.  looking at the drive in gparted, it said "lba" but not "boot" as well, so added that flag, restarted, no dice.  So I installed rpi-imager into UBuntu and flashed UBuntu to the SSD (yes, it picked it up as storage), waiting for a bit.... then rebooted... took the SDCard out & wouldn't you know, it works fine!  It's super fast and "does what it says on the tin" - awesome!

Right, now it's time to remember why I wanted to use the NVMe SSDs in the first place?!?!!

Before moving onto that, I stumbled over this great little tool:

https://github.com/smxi/inxi

$ sudo apt install inxi

So what does it do? well, it outputs lots of lovely information about your linux system all from the CLI.

Here is the output for my newly rebuilt Raspberry Pi 5 with 4GB RAM and the new 256GB NVMe SSD:


As you can see, it does output a LOT of interesting (if you're a geek) information.

A key interesting one for me is the [Swap] file size.  It is set to 1GB.... hmmmm.... I have 200+GB of super fast SSD (400Mb / Sec READ and 300Mb / Sec WRITE), well those numbers are meant to be higher, but y'know... reality.


The geek in me is thinking.... "can I up that swapfile to be 4Gb"? thereby increasing the RPi5 4Gb to a "fake" 8Gb.  I have a true 8Gb RPi5, so I can always set that to have a swapfile of 8Gb - but for now, I can at least performance compare test.

So, what's involved to make this happen?

There is more info HERE about setting the swapfile, simple rule is that you can match the "real" RAM with the size of the "swapfile", so for me with the RPi5 4Gb I'll make the swapfile 4Gb and for the 8Gb version I'll change it to 8Gb.

# Turn swap off
# This moves stuff in swap to the main memory and might take several minutes
sudo swapoff -a

# Create an empty swapfile
# Note that "1024" is basically just the unit and count is an integer.
# Together, they define the size. In this case 4GB
sudo dd if=/dev/zero of=/swapfile bs=1G count=4
#see below for output
# Set the correct permissions
sudo chmod 0600 /swapfile

sudo mkswap /swapfile  # Set up a Linux swap area
sudo swapon /swapfile  # Turn the swap on

tony@tony-rpi54gb:~$ sudo dd if=/dev/zero of=/swapfile bs=1G count=4

4+0 records in

4+0 records out

4294967296 bytes (4.3 GB, 4.0 GiB) copied, 10.3307 s, 416 MB/s

Check to see if it worked with the following command:

grep Swap /proc/meminfo
tony@tony-rpi54gb:/$ sudo mkswap /swapfile
Setting up swapspace version 1, size = 4 GiB (4294963200 bytes)
no label, UUID=9ed1bec2-d718-4414-bac3-2b11eec3eef1
tony@tony-rpi54gb:/$ sudo swapon /swapfile
tony@tony-rpi54gb:/$ grep Swap /proc/meminfo
SwapCached:            0 kB
SwapTotal:       4194300 kB
SwapFree:        4194300 kB
once happy, make it permanent:

Add this line to the end of your /etc/fstab:

/swapfile none swap sw 0 0


and here's proof of that showing up with the inxi tool showing the updated info:


There we have it - increased swapfile to 4Gb RAM (running from very fast SSD) so the RPi5 4Gb shouldn't now hit any real issues if I run, oh, I don't know, something like ollama with a larger model...

UPDATE: Will just do a reboot, then check the Ubuntu Desktop GUI to make sure the swapfile changes are shown there via [System Monitor] and [bpytop].....


 There we go!  Proof in the pudding.

Now, one lesson learnt, in the fstab file DO NOT put a LABEL=swapfile at the start of the new line, as this will cause a start up error, put it in like it is shown above.

UPDATE UPDATE: I repeated the above on the RPi5 8Gb machine and was complete with that in minutes.  sweet.

Comments