With the hardware build complete the next step is to install an Operating System to the NVMe drive so the Pi can boot without needing to use a microSD. Once the OS is installed there's a few configuration tasks to complete before we can install Bacula itself.

Contents:

  1. OS Selection
  2. Prepare PiOS Installation
  3. Boot with PiOS
  4. EEProm Update
  5. Ubuntu Installation
  6. Ubuntu Preparation
  7. Install PostgreSQL
  8. Bootnote: Convert to btrfs

OS Selection

While there are several Linux distributions optimised for the Raspberry Pi and even builds of Windows 11 if you're into self-inflicted technical pain, for this project there is only one realistic choice and that is Ubuntu server 24.04 LTS.

This isn't because it's faster, smaller or technically better than any of the other choices (it isn't) but purely because this is going to be a Bacula server and Ubuntu 24.04 has Bacula 13 available for arm-based machines in its standard repositories and the others either don't offer Bacula at all or they have an earlier version which won't be able to use the agents included with Ubuntu 24.04 and I really don't want to be trying to compile it from source or have to muck about downgrading clients on other hosts.

I'm also using Ubuntu and Rocky for most of my GeekLab virtual machines and there's a lot to be said for not having too many different operating systems in use.

But as I found out through practical experience, getting Ubuntu 24.04 installed on the NVMe SSD and actually booting has some interesting and very annoying quirks and the approach I used on my Pi 2B to install Ubuntu 20.04 didn't work for some reason. The Pi would boot quite happily and locate the Linux initial ramdisk which means it was using the SSD, but would then fail to load the root filesystem and would just hang.

So to get Ubuntu 24.04 installed, the first thing you need to do is create a Raspberry Pi OS bootable microSD card, boot from it and then write an Ubuntu installation image to the SSD. And annoyingly I still cannot see what that did differently to my own attempt to do it directly. But anyways...

Prepare a Pi OS Installation

Note: I use Linux Mint as a desktop so these are naturally linux-oriented steps. For Windows users 7zip can handle .xz format files and there are several tools for writing images via your favourite search engine.

Another Note: A compromise of xz-utils, which provides the unxz uncompression program for many Linux distributions has been reported (see CVE-2024-3094). At time of writing no Ubuntu distributions were affected, but it's worth checking if that's still true and making sure you don't have an afflicted version.

So taking the advice from Raspberry Pi and also from Pimoroni on their NVMe Base documentation, I downloaded the latest version of Raspberry Pi OS from the Raspberry Pi website and found a spare microSD card to write it to.

Raspberry Pi provide the Raspberry Pi Imager for Ubuntu, Windows and macOS to create installation microSDs, but this turns out to have a couple of dependency issues when attempted on Mint 19 so wasn't any use for me. But Mint has it's own USB Image Write tool that does exactly the same job. And yes, I will be updating to Mint 21 in the next few months.

The Pi OS image is compressed in the xz format so while it's downloading install something like xz-utils.

#> sudo apt install xz-utils

Or use the package manager of your choice. Once downloaded it's also worth confirming the file is correct by comparing the checksums with the one published on the Raspberry Pi website.

#> sha256sum 2024-07-04-raspios-bookworm-arm64.img.xz

5b2c3203d9e32b5c816badc41eb3d9d3f25fb90cb0d11b7eeb59c26f6e90aeec  2024-07-04-raspios-bookworm-arm64.img.xz

PiOS Checkum

Once the Pi OS image is downloaded either copy it to a temporary directory or use the -k option to keep the original as the default is to delete the original file once it's been uncompressed. I prefer to keep original installs for at least a few months in case a rebuild becomes necessary.

#> unxz -k 2027-07-04-raspios-bookworm-arm64.img.xz

The uncompressed 2024-07-04-raspios-bookworm-arm64.img file is approx 6.1 GB in size and you'll need at least an 8GB microSD card to write it to. Using the Mint USB Image writer create a bootable microSD for Raspberry Pi OS, which will prompt for an admin user before writing the image since it will wipe the microSD card in the process.

Writing image to microSD

 

Boot with Pi OS

Simply insert the microSD card into the Pi and turn it on. Pi OS setup will ask a few initial questions and claim the rest of the microSD card for itself.

Pi OS Welcome

Click Next on the welcome screen.

Select country and language

Select your preferred country, language and timezone settings and click Next.

Create an initial user

Create an initial user with a suitably complex password for this Pi OS installation. You can add more users later if you wish.

The next screen asks is you want to configure WiFi. Since I'm using Ethernet I skipped it and somehow lost the photo.

Chose your preferred browser

Choose your preferred browser and then remove the other if you don't want to keep it. Click Next when you made your choice.

Skip enabling Pi Connect

Since this is only being used to install Ubuntu and as an offline recovery tool there's no need to enable Pi Connect so just click Next.

Apply Pi OS updates

Even though the Pi OS image is only a few weeks old it's worth applying updates so click Next to start the update process and then OK when done and finally Next one more time. It doesn't take long so be quick getting a coffee.

Pi OS config complete

Click Restart and it will automatically log in as the user created. On an 8GB card and after the July updates I have the following filesystem layout:

Device Mounted To Filesystem Size Used Remaining
/dev/mmcblk0p1 /boot/firmware vfat 512 MB 75 MB 436 MB
/dev/mmcblk0p2 / ext4 6.7 GB 4.7 GB 1.7 GB

 

I will keep this microSD as a recovery tool just in case anything interesting happens so will install some extras on here such as gparted and filesystems tools for btrfs and XFS so I can reconfigure the Pi offline if needed.

EEProm Update

Pimoroni recommend the EEPROM is updated to later than December 2023 and at least at time of writing Ubuntu doesn't have any later updates so this is a task to perform from Pi OS. Start a command prompt to run the update.

#> sudo rpi-eeprom-update -a

This will need a reboot using the microSD card to take effect.

 

Ubuntu Installation

With the Pi firmware updated and booted from the microSD card and running Pi OS, using the Raspberry Pi Imager is the easiest way to get Ubuntu installed. Navigate to Pi > Accessories > Imager.

Click on the Device field to pick which kind of Pi to install on.

Select Pi 5

I would have thought it could detect what it's currently running on and set that as a default. In this case we want Raspberry Pi 5 so just click on the appropriate row.

Select Ubuntu

Click the Operating System box and chose Other general-purpose OS > Ubuntu > Ubuntu Server 24.04 LTS (64bit).

Choose SSD

And then finally click Storage and choose the NVMe SSD which is the only choice available.

Install target set

Check the choices are correct and then click Next.

Create initial ubuntu user

The General options are, well, optional. Create an initial user for Ubuntu with a username and password of your choice otherwise it'll create a default user "ubuntu" with a password of ubuntu - which it will force you to change on first login.

I am a bit surprised the hostname option sets a .local domain. I left it alone so it uses ubuntu as the hostname in the default domain as set by the DHCP server and change that during initial config. And again I've no need to configure WiFi since I'll be using Ethernet.

And you also want to tick the box for Set local settings even if you're in the UK otherwise it defaults to GMT. Obviously if you're in another timezone then pick that now to save having to adjust later.

Click on the Services tab.

Enable SSH passwords

Tick the Enable SSH box and set it to use password authentication otherwise you will need to login on the Pi and edit the SSH configuration later to do so. You could also provide an existing SSH key but since I will be configuring signed keys later there's really no point. Click Save.

Apply customisations

Click Yes to apply the customisations and then click Next to proceed.

Confirm image writing

Carefully read and understand the warning that all the data you don't have on your brand new and unused SSD will be deleted and click Yes. It will then start writing the Ubuntu image to the SSD and apply the chosen customisations.

Write the SSD

It takes a little while to write the image so a chance to go and grab a couple of biscuits to go with the coffee from earlier.

Image completed

Having let you write the image it will then prompt you to eject the SSD. This is of course a logical operation within Pi OS and it's not about to spit parts of itself across your desk. Provide the pasword and click Authenticate then click Continue. Don't reboot just yet though.

If you start GParted - you will need to install this if you've not done so earlier -  you should should now find the NVMe drive has two partitions, a fat32 firmware partition that contains the initial bootloader and config for the Pi itself, and an ext4 root partition for Ubuntu. Since this is a Raspberry Pi there is no EFI or GRUB installation needed.

Partition Mount File System Label Size Used Free Flags
/dev/nvme0n1p1 /boot/firmware fat32 system-boot 512 MB 92 MB 419 MB boot, lba
/dev/nvme0n1p2 / ext4 writable 2.85 2.82 38.79  

Note: the Ubuntu 24.04.01 image is slightly larger than shown here.

Rather than let it claim the rest of the disk for the "writable" partition during the boot process and then have to reclaim it later I'm going to set things how I want them now, using GParted since it's a nice easy to use graphical tool. Only the changes are shown here:

  • Changing the size of /dev/nvme0n1p2
  • Create partition /dev/nvme0n1p3
  • Create partition /dev/nvme0n1p4.
Partition Mount File System Label Size Used Free Flags
/dev/nvme0n1p1             msftdata
/dev/nvme0n1p2       16384 MiB      
/dev/nvme0n1p3   unformatted postgresql 65536 MiB      
/dev/nvme0n1p4   linux-swap swap 2048 MiB     swap

 

Disks partitioned with the Master Boot Record (MBR) layout are limited to 4 partitions and I've already reached that and there's a good chance I'll want more in future - in fact I'll need an extra one for the btrfs conversion later. There is an alternative, the GUID Partition Table (GPT) layout that allows upto 256 partitions per disk under Linux.

While the partition table structure is supposed to be decided when a disk is first formatted, the gdisk utility can change a disk from MBR to GPT and back again without loss of data. It will also change the flags on /dev/nvme0n1p1 from boot, lba to msftdata and add the swap flag to /dev/nvme0n1p4

#> sudo apt install gdisk#> sudo gdisk /dev/nvme0n1
GPT fdisk (gdisk) version 1.0.9

Partition table scan:
  MBR: MBR only
  BSD: not present
  APM: not present
  GPT: not present

***************************************************************
Found invalid GPT and valid MBR; converting MBR to GPT format
in memory. THIS OPERATION IS POTENTIALLY DESTRUCTIVE! Exit by
typing 'q' if you don't want to convert your MBR partitions
to GPT format!
***************************************************************

Command (? for help): w

Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!

Do you want to proceed? (Y/N): y
OK; writing new GUID partition table (GPT) to /dev/nvme0n1.
The operation has completed successfully.
localadmin@raspberrypi:~ $ 

Launch gdisk with the device you want to update, not the partitions and then use the w command to write out the updated partition table and confirm with a y. It can also convert back to MBR format by running it again.

Gparted partition layout

Shut down and when the disk/power LED turns red carefully remove the microSD card being mindful of the PCIe ribbon cable then press the power button to start it up again and wait a few seconds until after the login screen appears for cloud-init to generate its keys and announce it has finished

The Pi should now be running from the NVMe drive with a hostname of ubuntu and you should be able to login using SSH and and the username and password you defined in Imager.

Ubuntu Preparation

Before installing Bacula I need to complete a some preparation steps. These all require root access, so either become root with  sudo -i or prefix every command with sudo. It's your choice - best practice versus convenience. Command input is shown here with #> as the prompt.

Hostname

During preparation I'm assigning a temporary hostname of mavis until it's ready to take over from the existing Bacula host.

Edit /etc/hostname and change the name from ubuntu to mavis

Edit /etc/hosts and add the following entry, edited for your own domain of course.

127.0.1.1   mavis.subdomain.example.com   mavis

Reboot so the new host name takes effect.

And already it's clear this is a huge step up in performance as a reboot takes just under 28 seconds.

Ubuntu Patches

Before going any further it's worth updating Ubuntu to make sure we only have the freshest bugs to deal with.

#> sudo apt update
#> sudo apt upgrade

And reboot again so they also take effect

Configure SSHd

I normally configure hosts with a signed SSH host certificate which adds a layer of security by providing a known identity from the SSH server itself and also stops the annoying warning when it picks up a new IP address from DHCP. I also configure a trusted CA for user certificates so I don't need to use password authentication once configuration is complete.

This is entirely optional, although if you didn't enable the SSH password option during Ubuntu you'll need to login via the console and fix the SSH server config or configure your own SSH keys.

Prepare PostgreSQL partition

I created a separate partition for the PostgreSQL earlier, now we need to format it and add to fstab so it gets mounted at boot time.

#> mkfs.xfs /dev/nvme0n1p3

meta-data=/dev/nvme0n1p3 isize=512 agcount=4, agsize=4194304 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=1, sparse=1, rmapbt=1
= reflink=1 bigtime=1 inobtcount=1 nrext64=0
data = bsize=4096 blocks=16777216, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0, ftype=1
log =internal log bsize=4096 blocks=16384, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
Discarding blocks...Done.

Next I want to identify the partition by its UUID in case future changes affect its device name

#> blkid
...
/dev/nvme0n1p3: UUID="aabbccdd-1111-2222-3333-1234abcd1234" BLOCK_SIZE="512" TYPE="xfs" ...

This will be mounted to /var/lib/postgresql so next step is to create a directory to mount it to

#> mkdir /var/lib/postgresql

And then edit /etc/fstab and add the line below so it is automatically mounted at boot, using your actual UUID of course.

# Postgresql
UUID=aabbccdd-1111-2222-3333-1234abcd1234   /var/lib/postgresql   xfs  defaults   0 0

Enable swap

While we're updating fstab we should also enable the swap partition too. In practice this should never be used as I expect Bacula and PostgreSQL to run entirely in physical memory. Any use of swap is an indicator something needs tuning, but also gives a bit of leeway rather than letting the OS start killing processes should it briefly need a few extra kB.

#> mkswap /dev/nvme0n1p4
mkswap: /dev/nvme0n1p4: warning: wiping old swap signature.
Setting up swapspace version 1, size = 2 GiB (2147479552 bytes)
no label, UUID=ddccbbaa-1111-2222-3333-abcd1234abcd

This also changes the UUID of the swap partition too. Edit /etc/fstab again and add the following line, using the UUID generated for your system which will of course be different to mine.

UUID=ddccbbaa-1111-2222-3333-abcd1234abcd   none                 swap   sw         0 0

And then enable with swapon -a

Disable Unwanted Hardware

As this Pi will be running headless (i.e. no keyboard, monitor or mouse) on an Ethernet connection I can disable wifi and bluetooth to reduce power consumption and hopefully let it run a little cooler too. And of course it makes it little more secure and reduces interference with other WiFi users.

Edit /boot/firmware/config.txt and add the following after the final [all] section

dtoverlay=disable-wifi
dtoverlay=disable-bt

You can also disable HDMI audio by amending dtoverlay-vc4-kms-v3d in the first [all] section

dtoverlay=vc4-kms-v3d,noaudio

This reduced power demands by about 0.5 W, which might not seem much but given it was consuming about 4.3 W while idle that's approximately 12.5% or an eighth in old maths. I'll probably return to this topic later and disable more unused features just to see the effect it has on power consumption.

And reboot again for the changes to take effect. When it comes back up check using df -hT that all filesystems have mounted correctly and that top show you have 2GB of swap available.

Firewall

Ubuntu comes with the UFW firewall which is inactive by default. Once I've finished installation I will enable this to only permit SSH from my admin PCs and of course to allow connections from Bacula clients. If I was being really strict I'd enable this now and only permit local SSH connections.

PostgreSQL

Bacula needs a database to store the catalog of which files were backed up from which host and where they are. Three different database applications are supported: PostgreSQL, MySQL and SQLite3. I'm going to use PostgreSQL for the simple reason that I've used for the previous incarnation of Bacula Pi and don't have any reason to change.

Since I created a dedicated XFS filesystem for PostgreSQL earlier and mounted it at /var/lib/postgresql all I need to do now is install the server and client packages from the Ubuntu repository. I will create the Bacula catalog database during Bacula installation.

#> sudo apt install postgresql postgresql-client

Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
libcommon-sense-perl libjson-perl libjson-xs-perl libllvm17t64 libpq5 libtypes-serialiser-perl postgresql-16 postgresql-client-16
postgresql-client-common postgresql-common ssl-cert
Suggested packages:
postgresql-doc postgresql-doc-16
The following NEW packages will be installed:
libcommon-sense-perl libjson-perl libjson-xs-perl libllvm17t64 libpq5 libtypes-serialiser-perl postgresql postgresql-16
postgresql-client postgresql-client-16 postgresql-client-common postgresql-common ssl-cert
0 upgraded, 13 newly installed, 0 to remove and 0 not upgraded.
Need to get 42.1 MB of archives.
After this operation, 175 MB of additional disk space will be used.
Do you want to continue? [Y/n]
...
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.

The database cluster will be initialized with locale "C.UTF-8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".
...
fixing permissions on existing directory /var/lib/postgresql/16/main ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... posix
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default time zone ... Etc/UTC
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
...
Done

A quick check shows that /var/lib/postgresql/16/main exists and systemctl status postgresql reports the service is running so that's a win.

Bootnote: Convert root to btrfs

Unlike Windows, Linux offers a choice of different file systems. The two most common are ext4 and xfs which have been around for decades and certainly do the job well, but there are other choices too.

I've got to quite like btrfs, which has also been around for several years and among other advantages it has the nice ability of being to create a disk snapshot which you can then backup at leisure and also use to quickly roll back an unsuccessful change. Unfortunately the copy-on-write feature that gives it this capability also means it performs badly for database applications where files have frequent random writes.

There is a btrfs-convert utility that can change an ext4 filesystem into a btrfs filesystem, but unfortunately it doesn't like the kernel page size settings on the Ubuntu image for Raspberry Pi and leaves the file system unusable. Thankfully it also has a convert-back feature that still works even if the file system doesn't.

So we're left with the traditional approach of creating a new partition, formatting it under Ubuntu with additional options on the Pi itself and then copying the data over.

To start with we need a new partition /dev/nvme0n1p5 which you can either create from Ubuntu using parted or quickly reboot to Pi OS from the microSD and create in GParted instead.

From within Ubuntu the next step is to format the new partition with btrfs and to explicitly set the sector size to match the kernel page size of 4096

#> mkfs.btrfs -s 4096 -f /dev/nvme0n1p5

btrfs-progs v6.6.3
See https://btrfs.readthedocs.io for more information.

Performing full device TRIM /dev/nvme0n1p5 (16.00GiB) ...
NOTE: several default settings have changed in version 5.15, please make sure
this does not affect your deployments:
- DUP for metadata (-m dup)
- enabled no-holes (-O no-holes)
- enabled free-space-tree (-R free-space-tree)

Label: (null)
UUID: aabbccdd-abcd-dcba-123-ab12cd34ef56
Node size: 16384
Sector size: 4096
Filesystem size: 16.00GiB
Block group profiles:
Data: single 8.00MiB
Metadata: DUP 256.00MiB
System: DUP 8.00MiB
SSD detected: yes
Zoned device: no
Incompat features: extref, skinny-metadata, no-holes, free-space-tree
Runtime features: free-space-tree
Checksum: crc32c
Number of devices: 1
Devices:
ID SIZE PATH
1 16.00GiB /dev/nvme0n1p5

For the next two steps we want to switch back to Pi OS as this is much easier to do with outside of Ubuntu with the root filesystem not in use

As root, the first thing we need to do is mount our firmware, source and destination filesystems. If you haven't already done so install support for btrfs before attempting this

#> apt install btrfs-progs

#> cd /mnt
#> mkdir p1
#> mkdir p2
#> mkdir p5
#> mount /dev/nvme0n1p1 p1
#> mount /dev/nvme0n1p2 p2
#> mount /dev/nvme0n1p5 p5

The next step is to create two btrfs subvolumes using the Ubuntu convention of @ for the root directory and @home for the home directory

#> cd /mnt/p5
#> btrfs subvol create @
#> btrfs subvol create @home

We should also create a filesystem label for our btrfs partition. I'm going to use root.

#> btrfs filesystem label /mnt/p5 root

We can now copy all of our original root filesystem to our new btrfs one, including permissions, which should only take a few minutes.

#> cd /mnt/p5/@
#> cp -a /mnt/p2/* .

Interestingly the same amount of files now consumes less disk space. We also need to move the home directory for any users to the @home subvolume

#> cd /mnt/p5/@home
#> mv /mnt/p5/@/home/* .

Having copied the original root filesystem to our new subvolumes we must reconfigure the /etc/fstab of our new btrfs root filesystem so it can mount itself. Using the device ID is not a good idea as these will change. Either use the filesystem label we defined or the UUID.

vi /mnt/p5/@/etc/fstab

We need to change the line for / and add a line for /home so it end up looking something like this. The original line for root with the label writable is commented out.

#LABEL=writable     /                auto    defaults                0 1
LABEL=system-boot   /boot/firmware   vfat    defaults                0 1
LABEL=root          /                btrfs   defaults,subvol=@       0 1
LABEL=root          /home            btrfs   defaults,subvol=@home   0 0

The final step is to modify the kernel start command in /mnt/p1/cmdline.txt to also look for the file system labeled root, with a type of btrfs and also to use the @ subvolume within that filesystem

console=serial0,115200 multipath=off dwc_otg.lpm_enable=0 console=tty1 root=LABEL=root rootfstype=btrfs rootflags=subvol=@ rootwait fixrtc

And then finally shut down Pi OS and remove the microSD card. Restart the Pi 5 and it should now load Ubuntu with our new btrfs root file system.

If it doesn't complete the boot process then the most likely errors are:

  1. Not set the filesystem label correctly on the btrfs filesystem, /boot/firmware/cmdline.txt and /etc/fstab - this is case sensitive
  2. If using UUIDs then carefully check it exactly matches the UUID of the btrfs partition in both /boot/firmware/cmdline.txt and /etc/fstab

And of course you'll need to boot back into Pi OS and mount the firmware and new partition to change them unless you have more expertise than me in using the recovery shell.

When you're happy it's all working and feeling suitably brave you can then delete the old writable partition (/dev/nvme0n1p2), just make sure you're not using /dev/nvme0n1p* device names anywhere as they will probably change.

Bootnote 2: Shrink /boot/firmware

I have no idea why the firmware partition /dev/nvme0n1p1 is sized at 505 MB when it only contains 169 MB of files, 256 MB would still be more than sufficient. While GParted can shrink vfat filesystems it cannot shrink them down to 256 MB or less so it's easiest to just leave it alone. We're not exactly short of space right now.