Sunday 18 February 2024

Building SAMBA 4.20 for use on a Raspberry Pi

My notes for building SAMBA 4.20 on a Raspberry Pi 5 (or 4) with 8GB and a 2TB USB HDD.

  1. Use the Raspberry Pi Imager to install Raspberry Pi OS Lite (64-bit) on to the USB HDD with SSH enabled if configuration is going to be done headless.
  2. Configure the Raspberry Pi to boot from USB (Pi 4 only - the Pi 5 seems to be able to do it by default).
  3. Boot the Raspberry Pi from the HDD
  4. Configure Pi OS to include the en_us.utf8 locale using sudo raspi-config
  5. Setup some extra swap space because the SAMBA self tests require it.
    1. Disable swapping and edit the swapfile settings:
      sudo dphys-swapfile swapoff
      sudo nano /etc/dphys-swapfile
    2. Change CONF_SWAPSIZE to be 81920 and CONF_MAXSWAP to be at least 81920. This gives a /etc/dphys-swapfile which looks something like:
      # where we want the swapfile to be, this is the default
      #CONF_SWAPFILE=/var/swap

      # set size to absolute value, leaving empty (default) then uses computed value
      # you most likely don't want this, unless you have an special disk situation
      #CONF_SWAPSIZE=100
      #80GB Swap size
      CONF_SWAPSIZE=81920

      # set size to computed value, this times RAM size, dynamically adapts,
      # guarantees that there is enough swap without wasting disk space on excess
      #CONF_SWAPFACTOR=2

      # restrict size (computed and absolute!) to maximally this limit
      # can be set to empty for no limit, but beware of filled partitions!
      # this is/was a (outdated?) 32bit kernel limit (in MBytes), do not overrun it
      # but is also sensible on 64bit to prevent filling /var or even / partition
      #CONF_MAXSWAP=2048
      #100GB MAX
      CONF_MAXSWAP=102400
    3. Once that is saved enable swapping:
      sudo dphys-swapfile setup; sudo dphys-swapfile swapon
  6. Create some of the SAMBA folder structure because the self tests require it
    sudo mkdir -p /usr/local/samba/var
    sudo chmod o+w,g+w /usr/local/samba/var
    or maybe there are some environment variables we could set to make the self test fully self contained
  7. Install git and the build essentials
    sudo apt-get -y update
    sudo apt-get -y install git
  8. Clone the SAMBA git repo
    git clone https://git.samba.org/samba.git
  9. Check out the required branch
    cd samba
    git checkout samba-4.20.0rc2
  10. Install the prerequisites
    cd bootstrap/generated-dists/debian12
    sudo ./bootstrap.sh
    cd ../../..
  11. Configure the SAMBA build (include self tests) and to get the config from /etc/samba and to store the local state in /var/samba
    ./configure --enable-selftest --sysconfdir=/etc/samba --localstatedir=/var/samba --with-ads
  12. Build SAMBA (using 4 jobs which is OK if swap space has been added otherwise miss off the -j 4)
    make -j 4
  13. Run the self tests to ensure that the build was successful
    make quicktest
    which takes about half an hour to run on my Raspberry Pi 5.
  14. Install SAMBA
    sudo make install
  15. Add the SAMBA binaries directory to the path.
    export PATH=/usr/local/samba/bin/:/usr/local/samba/sbin/:$PATH
    Also remember to alter the system path definition in /etc/profile

See the SAMBA wiki website for more details on how to build SAMBA from source.

Configure Pi OS to use a static IPv4 Address

To configure Pi OS to use a static IPv4 address on the wired interface use the following commands:

sudo nmcli connection modify 'Wired connection 1' ipv4.address 192.168.200.20/24

This sets the (first) wired interface's IPv4 address to 192.168.200.20 with a net mask of 255.255.255.0.

sudo nmcli connection modify 'Wired connection 1' ipv4.method manual

This sets the (first) wired interface's IPv4 address to be manually set.

sudo nmcli connection modify 'Wired connection 1' ipv4.dns 192.168.200.10

This sets the (first) wired interface's IPv4 DNS server address to be 192.168.200.10.

sudo nmcli connection down 'Wired connection 1' ;sudo nmcli connection up 'Wired connection 1'

This resets the (first) wired interface by taking the connection down and the reestablishing it.