Provisioning Raspberry under MAAS (Metal as a service): Difference between revisions
(Created page with "==Clients setup== ===Change default boot order on RPI=== ===Prepare RPI UEFI firmware files=== #Download the UEFI firmware from https://github.com/pftf/RPi4/releases/download/...") |
|||
(12 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
==Clients setup== | ==Clients setup== | ||
===Prepare RPI UEFI firmware files=== | ===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 | #Download the UEFI firmware from https://github.com/pftf/RPi4/releases/download/v1.30/RPi4_UEFI_Firmware_v1.30.zip | ||
Line 7: | Line 6: | ||
##Going to: Device Manager → Raspberry Pi Configuration → Advanced Settings | ##Going to: Device Manager → Raspberry Pi Configuration → Advanced Settings | ||
##Disabled 3GB ram limitation and save. | ##Disabled 3GB ram limitation and save. | ||
#Change boot order setting: | |||
##Move IPV4 PXE Boot to the top and save. (So that RPI will always boot from MAAS first even after deployed, so we don't need to format storage when release machines) | |||
#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. | #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. | ||
Line 41: | Line 42: | ||
---- | ---- | ||
Notes: If there is no option to select kernel, it means the images are not yet synced. | Notes: If there is no option to select kernel, it means the images are not yet synced. | ||
To use MAAS CLI to set default commission kernel: | |||
<pre> | |||
# save api key | |||
sudo maas apikey --username=admin > api_key | |||
# login with MAAS CLI | |||
maas login admin http://192.168.1.2:5240/MAAS - < api_key | |||
# set kernel with MAAS CLI | |||
maas admin maas set-config name=default_min_hwe_kernel value=hwe-20.04-edge | |||
</pre> | |||
===Configure DHCP server to provide TFTP IP to client === | ===Configure DHCP server to provide TFTP IP to client === | ||
#Go to settings -> DHCP Snippets, and add a new snippet with this option: | #Go to settings -> DHCP Snippets, and add a new snippet with this option: | ||
Line 124: | Line 135: | ||
elevator=deadline cgroup_enable=cpuset cgroup_memory=1 cgroup_enable=memory\ | elevator=deadline cgroup_enable=cpuset cgroup_memory=1 cgroup_enable=memory\ | ||
" | sudo tee /srv/nfs/${SERIAL}/boot/cmdline.txt > /dev/null | " | 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</pre> | |||
===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: | |||
<pre>[pi4] | |||
kernel=vmlinuz | |||
max_framebuffers=2 | |||
initramfs initrd.img followkernel</pre> | |||
The script to setup cluster | |||
<pre> | |||
#!/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 | |||
SYMLINK_TFTP_ROOT="/var/snap/maas/common/maas/boot-resources/current" | |||
TFTP_ROOT=$(cd -P "$SYMLINK_TFTP_ROOT" && pwd) | |||
mkdir -p ${TFTP_ROOT}/${SERIAL} | |||
echo "/srv/nfs/${SERIAL}/boot ${TFTP_ROOT}/${SERIAL} none defaults,bind 0 0" >> /etc/fstab | |||
mount ${TFTP_ROOT}/${SERIAL} | |||
ln -s ${TFTP_ROOT}/${SERIAL}/firmware/bcm2711-rpi-4-b.dtb ${TFTP_ROOT}/${SERIAL}/bcm2711-rpi-4-b.dtb | |||
ln -s ${TFTP_ROOT}/${SERIAL}/firmware/start4.elf ${TFTP_ROOT}/${SERIAL}/start4.elf | |||
ln -s ${TFTP_ROOT}/${SERIAL}/firmware/fixup4.dat ${TFTP_ROOT}/${SERIAL}/fixup4.dat | |||
ln -s ${TFTP_ROOT}/${SERIAL}/firmware/config.txt ${TFTP_ROOT}/${SERIAL}/config.txt | |||
chmod 777 ${TFTP_ROOT}/${SERIAL}/vmlinuz | |||
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)" | OLDHOSTNAME="$(cat /srv/nfs/${SERIAL}/etc/hostname)" | ||
Line 152: | Line 226: | ||
==Use Ansible to manage clients== | ==Use Ansible to manage clients== | ||
[[Use Ansible to manager cluster]] |
Latest revision as of 12:08, 7 December 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.
- Change boot order setting:
- Move IPV4 PXE Boot to the top and save. (So that RPI will always boot from MAAS first even after deployed, so we don't need to format storage when release machines)
- 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. To use MAAS CLI to set default commission kernel:
# save api key sudo maas apikey --username=admin > api_key # login with MAAS CLI maas login admin http://192.168.1.2:5240/MAAS - < api_key # set kernel with MAAS CLI maas admin maas set-config name=default_min_hwe_kernel value=hwe-20.04-edge
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} echo "/srv/nfs/${SERIAL} *(rw,sync,no_root_squash,no_subtree_check)" \ >> /etc/exports exportfs -ra SYMLINK_TFTP_ROOT="/var/snap/maas/common/maas/boot-resources/current" TFTP_ROOT=$(cd -P "$SYMLINK_TFTP_ROOT" && pwd) mkdir -p ${TFTP_ROOT}/${SERIAL} echo "/srv/nfs/${SERIAL}/boot ${TFTP_ROOT}/${SERIAL} none defaults,bind 0 0" >> /etc/fstab mount ${TFTP_ROOT}/${SERIAL} ln -s ${TFTP_ROOT}/${SERIAL}/firmware/bcm2711-rpi-4-b.dtb ${TFTP_ROOT}/${SERIAL}/bcm2711-rpi-4-b.dtb ln -s ${TFTP_ROOT}/${SERIAL}/firmware/start4.elf ${TFTP_ROOT}/${SERIAL}/start4.elf ln -s ${TFTP_ROOT}/${SERIAL}/firmware/fixup4.dat ${TFTP_ROOT}/${SERIAL}/fixup4.dat ln -s ${TFTP_ROOT}/${SERIAL}/firmware/config.txt ${TFTP_ROOT}/${SERIAL}/config.txt chmod 777 ${TFTP_ROOT}/${SERIAL}/vmlinuz 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