Provisioning Raspberry under MAAS (Metal as a service): Difference between revisions
Line 141: | Line 141: | ||
initramfs initrd.img followkernel</pre> | initramfs initrd.img followkernel</pre> | ||
The script to setup cluster | |||
<pre> | <pre> | ||
#!/bin/sh | #!/bin/sh |
Revision as of 10:54, 20 September 2021
Clients setup
Prepare RPI UEFI firmware files
- Download the UEFI firmware from https://github.com/pftf/RPi4/releases/download/v1.30/RPi4_UEFI_Firmware_v1.30.zip
- Extract it into the fat32 formatted SD Card or boot partition of RPI SD card.
- Let RPI boot from it, and change setting to disable 3GB ram limitation by:
- Going to: Device Manager → Raspberry Pi Configuration → Advanced Settings
- Disabled 3GB ram limitation and save.
- The firmware files are ready to be copied into the netboot server. To easily copy it into the server, we can zip all the files (make sure to include RPI_EFI.fd, it saves the configuration changed that we have made) before transfer into the server.
Prepare Raspbian root and boot files (For Raspbian netboot)
We will copy root and boot files from RPI into our NFS server.
- Create tar files from root and boot directory of RPI.
cd /
tar -cvpzf root.tar.gz --exclude=/root.tar.gz --one-file-system /
tar -cvpzf boot.tar.gz /boot
- Copy the tar files into the NFS server
Server setup
Install MAAS
- Install MAAS with snap
sudo snap install --channel=3.0/stable maas
- Install maas-test-db (it is a preconfigured Pogresql for MAAS)
sudo snap install maas-test-db
- Initialize MAAS as region+rack controller
sudo maas init region+rack --database-uri maas-test-db:///
- Create an admin account with
sudo maas createadmin
Configure netboot image
- Login to MAAS with a previously created account.
- Go to Image and select Ubuntu 20.04LTS and ARM64 Architecture.
- Click saves and waits for images to finish sync into the controller.
- Then toggle automatically image sync to disable it (because MAAS will change tftp root directory after images synced).
Set minimum kernel for commission
- Go to Settings -> Configuration -> Commissioning, and select:
- focal(hwe-20.04-edge) as default minimum kernel verion.
Notes: If there is no option to select kernel, it means the images are not yet synced.
Configure DHCP server to provide TFTP IP to client
- Go to settings -> DHCP Snippets, and add a new snippet with this option:
option tftp-server-name "192.168.1.2";
Serve UEFI firmware with TFTP server
Because MAAS already provides a TFTP server, we just need to copy the UEFI boot files onto the TFTP root directory.
- Create rpi-uefi directory in /var/snap/maas/common/maas/boot-resources
mkdir /var/snap/maas/common/maas/boot-resources/rpi-uefi
- Unzip our UEFI boot files into the directory.
unzip uefi-1.3.zip -d /var/snap/maas/common/maas/boot-resources/rpi-uefi
- Because we want to serve different RPI clients with different boot files, we will create a dir symlink with RPI serial number to the boot directory.
ln -s /var/snap/maas/common/maas/boot-resources/rpi-uefi /var/snap/maas/common/maas/boot-resources/current/${SERIAL}
Notes: The default TFTP_PREFIX bootloader configuration option in RPI is to use the serial number as a prefix.
Netboot the RPI
Netboot the RPI, it will be shown as a new machine on MAAS. We can then select the device and commission it.
For Raspbian netboot
Install NFS Server
apt install nfs-kernel-server
Setup NSF root and boot directory
mkdir -p /srv/nfs/${SERIAL}
tar xvzf root.tar.gz --directory /srv/nfs/${SERIAL}
tar xvzf boot.tar.gz --directory /srv/nfs/${SERIAL}
Note: we will have the following directory:
- /srv/nfs/${SERIAL}: root directory for RPI with ${SERIAL} number
- /srv/nfs/${SERIAL}/boot: boot directory for RPI with ${SERIAL} number
And we get root.tar.gz and boot.tar.gz from the RPI SD card
Change cmdline.txt so that RPI will mount its root directory from NFS server after netboot
echo "console=serial0,115200 console=tty root=/dev/nfs nfsroot=${NFS_SERVERIP}:/srv/nfs/${SERIAL},vers=4.1,proto=tcp rw ip=dhcp rootwait elevator=deadline cgroup_enable=cpuset cgroup_memory=1 cgroup_enable=memory" > /srv/nfs/${SERIAL}/boot/cmdline.txt
Change fstab file so that RPI won't mount the SD card
echo "proc /proc proc defaults 0 0" > /srv/nfs/${SERIAL}/etc/fstab
Update NFS rules
We edit the /etc/exports configuration file to add NFS directory and run "exportfs -ra" to reload the configuration
echo "/srv/nfs/${SERIAL} *(rw,sync,no_root_squash,no_subtree_check)" >> /etc/exports
exportfs -ra
Mount client boot directory onto TFTP root directory
mkdir -p /var/snap/maas/common/maas/boot-resources/current/${SERIAL}
echo "/srv/nfs/${SERIAL}/boot /var/snap/maas/common/maas/boot-resources/current/${SERIAL} none defaults,bind 0 0" >> /etc/fstab
mount -a
Now the server is ready for netboot.
Setup scripts
Raspbian netboot for 4 RPI devices
#!/bin/sh var1="82824dee 4b3be06c 3b045773 fd09fc29" #serial var2="red yellow black green" #hostname SERVERIP=192.168.1.2 set -- $var2 for SERIAL in $var1 do HOSTNAME=$1 mkdir -p /srv/nfs/${SERIAL} tar xvzf root.tar.gz --directory /srv/nfs/${SERIAL} tar xvzf boot.tar.gz --directory /srv/nfs/${SERIAL} echo "/srv/nfs/${SERIAL} *(rw,sync,no_root_squash,no_subtree_check)" \ >> /etc/exports exportfs -ra mkdir -p /var/snap/maas/common/maas/boot-resources/current/${SERIAL} echo "/srv/nfs/${SERIAL}/boot /var/snap/maas/common/maas/boot-resources/current/${SERIAL} none defaults,bind 0 0" >> /etc/fstab mount -a sudo tee /srv/nfs/${SERIAL}/etc/fstab > /dev/null <<EOT proc /proc proc defaults 0 0 #/dev/mmcblk0p1 /var/lib/rancher ext4 defaults 0 0 #for k3s EOT echo "console=serial0,115200 console=tty root=/dev/nfs \ nfsroot=${SERVERIP}:/srv/nfs/${SERIAL},vers=4.1,proto=tcp rw ip=dhcp rootwait \ elevator=deadline cgroup_enable=cpuset cgroup_memory=1 cgroup_enable=memory\ " | sudo tee /srv/nfs/${SERIAL}/boot/cmdline.txt > /dev/null OLDHOSTNAME="$(cat /srv/nfs/${SERIAL}/etc/hostname)" sed -i "s/${OLDHOSTNAME}/${HOSTNAME}/g" /srv/nfs/${SERIAL}/etc/hosts echo ${HOSTNAME} > /srv/nfs/${SERIAL}/etc/hostname shift done
For Ubuntu OS
Different points between Ubuntu OS and Rasbian OS:
- Boot firmware for Ubuntu OS are stored in /boot/firmware instead of /boot
- We need to specify the mount points for root and boot in the fstab file of the Ubuntu OS.
- For Ubuntu 20.04 we need to update boot/config.txt with the following:
[pi4] kernel=vmlinuz max_framebuffers=2 initramfs initrd.img followkernel
The script to setup cluster
#!/bin/sh var1="82824dee 4b3be06c 3b045773 fd09fc29" #serial var2="red yellow black green" #hostname SERVERIP=192.168.1.2 set -- $var2 for SERIAL in $var1 do HOSTNAME=$1 mkdir -p /srv/nfs/${SERIAL} tar xvzf root.tar.gz --directory /srv/nfs/${SERIAL} tar xvzf boot.tar.gz --directory /srv/nfs/${SERIAL} ln -s /srv/nfs/${SERIAL}/boot/firmware/bcm2711-rpi-4-b.dtb /srv/nfs/${SERIAL}/boot/bcm2711-rpi-4-b.dtb ln -s /srv/nfs/${SERIAL}/boot/firmware/start4.elf /srv/nfs/${SERIAL}/boot/start4.elf ln -s /srv/nfs/${SERIAL}/boot/firmware/fixup4.dat /srv/nfs/${SERIAL}/boot/fixup4.dat ln -s /srv/nfs/${SERIAL}/boot/firmware/config.txt /srv/nfs/${SERIAL}/boot/config.txt chmod 777 /srv/nfs/${SERIAL}/boot/vmlinuz echo "/srv/nfs/${SERIAL} *(rw,sync,no_root_squash,no_subtree_check)" \ >> /etc/exports exportfs -ra mkdir -p /var/snap/maas/common/maas/boot-resources/current/${SERIAL} echo "/srv/nfs/${SERIAL}/boot /var/snap/maas/common/maas/boot-resources/current/${SERIAL} none defaults,bind 0 0" >> /etc/fstab mount -a sudo tee /srv/nfs/${SERIAL}/etc/fstab > /dev/null <<EOT proc /proc proc defaults 0 0 ${SERVERIP}:/srv/nfs/${SERIAL} / nfs4 defaults,rw,nolock 0 0 # data to be shared to server ${SERVERIP}:/srv/nfs/${SERIAL}/boot/firmware /boot/firmware nfs4 defaults,rw,nolock 0 1 # data to be shared to server #/dev/mmcblk0p1 /var/lib/rancher ext4 defaults 0 0 #for k3s EOT echo "net.ifnames=0 dwc_otg.lpm_enable=0 console=serial0,115200 console=tty1 \ nfsrootdebug rootfstype=nfs4 root=/dev/nfs nfsroot=${SERVERIP}:/srv/nfs/${SERIAL} \ rw elevator=deadline rootwait fixrtc cgroup_enable=cpuset cgroup_memory=1 \ cgroup_enable=memory" | sudo tee /srv/nfs/${SERIAL}/boot/cmdline.txt > /dev/null OLDHOSTNAME="$(cat /srv/nfs/${SERIAL}/etc/hostname)" sed -i "s/${OLDHOSTNAME}/${HOSTNAME}/g" /srv/nfs/${SERIAL}/etc/hosts echo ${HOSTNAME} > /srv/nfs/${SERIAL}/etc/hostname shift done
Script to recreate symlink/mount into TFTP root (If MAAS has synced images and removed them)
Symlink UEFI firmware
SERIALS="379a846d 65d02964 349b6628 77274846" for i in $SERIALS do ln -s /var/snap/maas/common/maas/boot-resources/rpi-uefi /var/snap/maas/common/maas/boot-resources/current/${i} done
Mount client boot directory
var1="82824dee 4b3be06c 3b045773 fd09fc29" for SERIAL in $var1 do mkdir -p /var/snap/maas/common/maas/boot-resources/current/${SERIAL} done mount -a