Configuring Power-On/Off Button for Raspberry Pi 4B

Introduction:
Adding a power-on/off button to your Raspberry Pi 4B can provide a convenient way to manage the device’s power state. In this guide, we’ll show you how to configure a power-on/off button using the GPIO pins on the Raspberry Pi 4B.

Step 1: Edit the /boot/config.txt File

To configure the power-on/off button, you need to edit the /boot/config.txt file on your Raspberry Pi. Open the file using the following command:

sudo vi /boot/config.txt

Step 2: Enable Shutdown Functionality

To enable the shutdown functionality of the power button (green LED turns off when shutting down), add the following line to the config file:

dtoverlay=gpio-shutdown

Step 3: Enable Power-Off Functionality

To enable the power-off functionality of the power button (both green and red LEDs turn off when powered off), add the following lines to the config file:

dtoverlay=gpio-shutdown,gpio_pin=3
dtoverlay=gpio-poweroff,gpio_pin=24,active_low=0

Explanation of options used:

  • dtoverlay=gpio-shutdown: Enables the GPIO shutdown overlay to manage the shutdown functionality.
  • gpio_pin=3: Specifies the GPIO pin (BCM numbering) to use for the shutdown function (default is GPIO3).
  • dtoverlay=gpio-poweroff: Enables the GPIO power-off overlay to manage the power-off functionality.
  • gpio_pin=24: Specifies the GPIO pin (BCM numbering) to use for the power-off function (default is GPIO24).
  • active_low=0: Sets the active_low parameter to 0, which means the GPIO pin is active high (low signal triggers the action).

Step 4: Save and Reboot

Save the changes to the /boot/config.txt file, and then reboot your Raspberry Pi for the changes to take effect:

sudo reboot

Conclusion:
By following these steps and editing the /boot/config.txt file, you can easily configure a power-on/off button for your Raspberry Pi 4B. The power button will provide you with convenient control over the device’s power state, allowing for a smooth and efficient experience in managing your Raspberry Pi.

For more detailed information and the source of this guide, you can visit the provided link: Reviving Borkin Power On/Off Button for the Raspberry Pi 4B.




Setting Up NFS Server on Raspberry Pi

Introduction:
NFS (Network File System) allows you to share directories and files between systems over a network. In this guide, we’ll walk you through setting up an NFS server on your Raspberry Pi and sharing a directory with other systems.

Step 1: Install NFS Server
To install the NFS server package, run the following command:

sudo apt-get install nfs-kernel-server -y

Step 2: Create the NFS Share Directory
Next, create a directory that you want to share with other systems. In this example, we’ll use /mnt/nfsshare:

sudo mkdir /mnt/nfsshare

Step 3: Set Permissions for the NFS Share
For the NFS share to be accessible, we need to set appropriate permissions on the shared directory. In this example, we’ll set the permissions to allow everyone full access. Note that this configuration might not be suitable for production systems.

sudo chmod 777 /mnt/nfsshare

Step 4: Configure the NFS Export
Open the /etc/exports file in a text editor:

sudo vi /etc/exports

Insert the following line at the end of the file to define the NFS share:

/mnt/nfsshare *(rw,no_root_squash,insecure,async,no_subtree_check,anonuid=1000,anongid=1000)

Explanation of the options used:

  • *: Allow any client to access the share.
  • rw: Allow read and write access to the share.
  • no_root_squash: Preserve the root user’s identity from the client-side (use with caution).
  • insecure: Allow the use of non-privileged ports for NFS.
  • async: Improve performance by allowing asynchronous writes to the shared directory.
  • no_subtree_check: Disable subtree checking to improve performance.
  • anonuid=1000 and anongid=1000: Map the anonymous user to the UID and GID 1000, which typically represents the first regular user on most systems.

Step 5: Activate the NFS Export
After modifying the /etc/exports file, apply the changes using the following command:

sudo exportfs -ra

Step 6: Start NFS Services
Start the NFS services to make the shared directory accessible:

sudo systemctl start nfs-kernel-server

Step 7: Enable NFS Services on Boot
To ensure the NFS services start automatically on boot, enable them with the following command:

sudo systemctl enable nfs-kernel-server

Conclusion:
Congratulations! You have successfully set up an NFS server on your Raspberry Pi. The /mnt/nfsshare directory is now shared with other systems on the network. You can access this NFS share from other machines using the appropriate mount command.

Please note that for production environments or when sharing with specific clients, you should consider setting more secure and restricted permissions in the /etc/exports file.

Happy sharing!




Automating Neofetch Installation and Configuration using Ansible

Introduction:
Neofetch is a simple and visually appealing command-line system information tool. By using Ansible, we can automate the installation of Neofetch and its configuration, including adding it to the .bashrc file and displaying the Raspberry Pi’s temperature. In this guide, we’ll walk you through creating an Ansible playbook to achieve this automation.

Step 1: Install Ansible
Before proceeding, make sure you have Ansible installed on your system. If you haven’t installed Ansible yet, you can follow the official Ansible installation instructions for your operating system.

Step 2: Create the Ansible Playbook
Create a new YAML file named neofetch_setup.yaml and add the following content to it:

---
- name: Install Neofetch and update .bashrc
  hosts: your_host  # Replace "your_host" with the target host or group where you want to install Neofetch.
  become: yes

  tasks:
    - name: Install Neofetch
      apt:
        name: neofetch
        state: present

    - name: Add Neofetch to .bashrc
      blockinfile:
        path: ~/.bashrc
        block: |
          if [[ -z $(grep -Fxq "neofetch" ~/.bashrc) ]]; then
              echo "neofetch" >> ~/.bashrc
          fi

    - name: Add vcgencmd measure_temp to .bashrc
      blockinfile:
        path: ~/.bashrc
        block: |
          if [[ -z $(grep -Fxq "vcgencmd measure_temp" ~/.bashrc) ]]; then
              echo "vcgencmd measure_temp" >> ~/.bashrc
          fi

In the playbook, make sure to replace “your_host” with the target host or group where you want to install Neofetch. Also, ensure that your target host has the necessary privileges (sudo access) to install packages and modify the .bashrc file.

Step 3: Run the Ansible Playbook
To run the Ansible playbook and install Neofetch on the target host, use the following command:

ansible-playbook neofetch_setup.yaml

Ansible will connect to the target host, install Neofetch, and update the .bashrc file with the appropriate commands.

Step 4: Verify Neofetch Installation
To verify that Neofetch is installed and configured correctly, log in to the target host and open a new terminal. You should see the Neofetch output displaying system information. Additionally, the Raspberry Pi’s temperature will be displayed along with the system details.

Conclusion:
You’ve successfully created an Ansible playbook to automate the installation of Neofetch and its configuration on your Raspberry Pi. Ansible allows you to manage multiple hosts efficiently and ensure consistent setups across your infrastructure. Now you can enjoy using Neofetch to get a stylish system summary each time you open a terminal.

Happy system information tracking!




Automating Raspberry Pi Configuration with Ansible

Introduction:
Managing multiple Raspberry Pi devices can be time-consuming and error-prone if done manually. Fortunately, Ansible provides a powerful solution for automating configuration tasks across your Raspberry Pi fleet. In this guide, we’ll walk you through setting up Ansible, creating an inventory, and using playbooks to perform various tasks on your Raspberry Pi devices.

Prerequisites:
Before proceeding, make sure you have Python3 and pip installed on your Raspberry Pi. You can install pip using the following command:

sudo apt install python3-pip

Step 1: Install Ansible
First, let’s install Ansible using pip:

python3 -m pip install --user ansible-core==2.12.3

Step 2: Create Ansible Configuration
Now, create a directory for your Ansible project and add an ansible.cfg file inside it:

mkdir /ansible
vi /ansible/ansible.cfg

Paste the following configuration in the ansible.cfg file:

[defaults]
inventory = inventory
host_key_checking = False

Save the file and exit the editor.

Step 3: Create the Inventory
The inventory file contains information about the hosts (Raspberry Pi devices) you want to manage. Create an inventory file inside the /ansible directory:

vi /ansible/inventory

Add the following content to the inventory file:

[tower]
RPIT1 ansible_host=192.168.0.220
RPIT2 ansible_host=192.168.0.221
RPIT3 ansible_host=192.168.0.222
RPTT4 ansible_host=192.168.0.223

[test]
RPI2GB ansible_host=192.168.0.227

[docker]
RPIDOCKER ansible_host=192.168.0.224

[kali]
RPIKALI ansible_host=192.168.0.226

[zeros]
RPIZEROW ansible_host=192.168.0.228 
RPIZEROW2 ansible_host=192.168.0.225

[all:vars]
ansible_ssh_user=pi ansible_ssh_pass=xxxxxxxxx

This inventory defines groups of hosts (towers, test, docker, kali, and zeros) and sets the SSH username and password to access them.

Step 4: Test Host Reachability
Before proceeding with any configuration, make sure all defined hosts are reachable using Ansible’s ping module:

ansible all -m ping

Step 5: Check OS Information
Retrieve OS information on all clients using the shell module:

ansible all -m shell -a "lsb_release -a"

Step 6: Upgrade Servers
Use a playbook to upgrade all servers:

ansible-playbook -e "target_host=all" update_upgrade.yaml

Step 7: Install Neofetch and Temperature
Create a playbook to install Neofetch and display the system temperature:

ansible-playbook -e "target_host=all" install_neofetch.yaml

Step 8: Shutdown the Tower
Create a playbook to shut down the tower (remember Docker always on):

ansible-playbook -e "target_host=tower" shutdown_now.yaml

Conclusion:
You’ve successfully set up Ansible and used playbooks to automate tasks on your Raspberry Pi devices. Ansible simplifies managing multiple devices and allows you to perform configurations efficiently and consistently. With Ansible, you can now spend less time on repetitive tasks and focus more on your Raspberry Pi projects.

Happy automating!




Setting up Docker on Raspberry Pi: A Step-by-Step Guide

Introduction:
Raspberry Pi is a versatile mini-computer, and with the growing popularity of containerization, using Docker on a Raspberry Pi can open up exciting possibilities. In this guide, we will walk you through the steps to set up Docker on your Raspberry Pi so that you can leverage the power of containerization for your projects.

Before you start:
Make sure you have a Raspberry Pi up and running with the Raspbian OS or its derivatives. Additionally, ensure you have a stable internet connection to proceed with the installation.

Step 1: Editing cmdline.txt
To enable memory control and avoid issues with mem management, we need to make some adjustments to the cmdline.txt file. Open the file using the following command:

sudo vi /boot/cmdline.txt

Add the following lines at the end of the file:

cgroup_enable=memory swapaccount=1 cgroup_memory=nokmem cgroup_enable=cpuset

Save the changes and exit the editor.

Step 2: Adjusting GPU memory
To ensure smooth performance with Docker, it is recommended to allocate at least 128MB of GPU memory. Use the following steps to make the adjustment:

  • Open the raspi-config tool:
sudo raspi-config

  • Navigate to “Advanced Options” and then “Memory Split.”
  • Set the GPU memory to 128MB.
  • Save the changes and exit the configuration tool.

Step 3: Updating your system
Before installing Docker, it’s essential to have your system up-to-date. Run the following commands to update your Raspberry Pi:

sudo apt update
sudo apt upgrade -y
sudo rpi-update
sudo reboot
sudo rpi-eeprom-update -a
sudo reboot

Step 4: Installing Docker
Now, it’s time to install Docker on your Raspberry Pi. Execute the following commands:

sudo curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
sudo reboot

Step 5: Granting permissions for Docker
To run Docker commands without using sudo, add your user to the “docker” group:

sudo groupadd docker
sudo usermod -aG docker $USER

Make sure to log out and log back in to apply the changes.

Conclusion:
Congratulations! You have successfully set up Docker on your Raspberry Pi, allowing you to harness the power of containerization for your projects. Docker provides an efficient way to manage applications and services, making development and deployment a breeze on your Raspberry Pi. Enjoy exploring the world of containers and unleash the full potential of your tiny yet powerful computing companion.

Happy coding!