sanjaysikdar.dev

Blog

HomeAboutTools
Sanjay Sikdar

Sanjay Sikdar

Software developer who enjoys developing software, solving challenges, and programming.

GithubLinkedInMain SiteSitemapRSS

© 2026 All rights reserved. Sanjay Sikdar

raspberry-piiotkiosk

Raspberry Pi Zero 2W Kiosk

Sanjay Sikdar

Sanjay Sikdar

·Feb 23, 2025·5 min read
Raspberry Pi Zero 2W Kiosk

Setup Raspberry Pi - Kiosk Mode

This guide will help you set up a Raspberry Pi Zero 2W to run in kiosk mode, displaying a specific website. The steps include installing the Raspberry Pi OS Lite, configuring auto-login, installing necessary packages, and setting up Chromium to run in kiosk mode. Additionally, it includes optimizations to speed up boot time and reduce memory usage.

Key Steps:

  • Install Raspberry Pi OS Lite (Bullseye): Flash the OS and enable SSH and WiFi.

  • Enable Auto-Login: Configure the system to log in automatically.

  • Install Required Packages: Install X.Org, xinit, Openbox, and Chromium.

  • Configure Openbox: Set up Xserver configurations and Chromium launch script.

  • Create Systemd Service: Ensure the kiosk mode starts automatically.

  • Optimize Boot Time: Disable unnecessary services and create swap memory.

By following these steps, your Raspberry Pi Zero 2W will automatically launch Chromium in kiosk mode, displaying the specified website on boot.

1. Install Raspberry Pi OS Lite (32-bit) - [bullseye]

Flash the OS using Raspberry Pi Imager or balenaEtcher.

Enable SSH and WiFi by:

  • Creating a blank file named ssh in the boot partition.

  • Creating a wpa_supplicant.conf file with:

    bash
    country=IN
    ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
    update_config=1
     
    network={
        ssid="Your_WiFi_Name"
        psk="Your_WiFi_Password"
        scan_ssid=1
    }

2. Enable Auto-Login

bash
sudo raspi-config
  • Select 1 System Options > S5 Boot / Auto Login.

  • Choose B2 Console Autologin (for CLI)

  • Select Finish and reboot when prompted.

3. Installation Requirements

Update the system and install required packages:

bash
sudo apt update && sudo apt upgrade 
sudo reboot
  • Server X (usually X.Org)

  • xinit (https://wiki.debian.org/xinit)

  • Openbox (https://wiki.debian.org/Openbox)

bash
sudo apt-get install --no-install-recommends xserver-xorg x11-xserver-utils xinit openbox
  • Chromium
bash
sudo apt-get install --no-install-recommends chromium-browser

4. Configurations

Now we'll configure Openbox, which sets Xserver configurations on start:

bash
sudo nano /etc/xdg/openbox/autostart

Add the following line to the bottom of the file, then save it and exit.

bash
 
# Configuration
WEBSITE_URL="https://sanjaysikdar.dev"
 
# Disable screensaver, screen blanking, and power management
xset s off
xset s noblank
xset -dpms
 
# Auto-detect screen resolution
RESOLUTION=$(xrandr 2>/dev/null | grep '*' | awk '{print $1}')
if [ -z "$RESOLUTION" ]; then
    RESOLUTION="1920x1080"  # Default fallback can be ="1280x720"
fi
SCREEN_WIDTH=$(echo $RESOLUTION | cut -d 'x' -f1)
SCREEN_HEIGHT=$(echo $RESOLUTION | cut -d 'x' -f2)
 
 
echo "Detected screen resolution: ${SCREEN_WIDTH}x${SCREEN_HEIGHT}"
 
# Check internet connection using ping before launching Chromium
if ping -c 1 -W 2 google.com >/dev/null 2>&1; then
    echo "Internet connected. Proceeding with Chromium launch."
else
    echo "No internet connection detected. Exiting."
fi
 
# Allow quitting the X server with CTRL-ALT-Backspace
# setxkbmap -option terminate:ctrl_alt_bksp
 
# Prevent Chromium restore prompts
sed -i 's/"exited_cleanly":false/"exited_cleanly":true/' ~/.config/chromium/'Local State'
sed -i 's/"exit_type":"[^"]\+"/"exit_type":"Normal"/' ~/.config/chromium/Default/Preferences
 
# Clean up Chromium cache, cookies, and logs
find ~/.config/chromium/Default/ -type f \( -name "Cookies" -o -name "History" -o -name "*.log" -o -name "*.ldb" -o -name "*.sqlite" \) -delete
rm -rf ~/.config/chromium/Default/Logs/*
 
# Clear system logs
sudo journalctl --vacuum-time=1d
sudo find /var/log -type f \( -name "*.log" -o -name "*.gz" -o -name "*.1" \) -delete
sudo truncate -s 0 /var/log/syslog /var/log/dmesg
 
# Kill any existing Chromium instances
pkill -9 chromium-browser 2>/dev/null
pkill -9 chrome 2>/dev/null
 
 
# Start Chromium in kiosk mode
chromium-browser --kiosk --disable-gpu --noerrdialogs --disable-infobars --disable-features=TranslateUI \
    --disable-session-crashed-bubble --no-sandbox --disable-notifications --disable-sync-preferences \
    --no-sandbox --disable-background-mode --disable-popup-blocking --no-first-run \
    --enable-gpu-rasterization --disable-translate --disable-logging --disable-default-apps \
    --disable-extensions --disable-crash-reporter --disable-pdf-extension --disable-new-tab-first-run \
    --disable-dev-shm-usage --start-maximized --mute-audio --disable-crashpad --hide-scrollbars \
    --ash-hide-cursor --memory-pressure-off --force-device-scale-factor=1 --window-position=0,0 \
    --window-size=${SCREEN_WIDTH},${SCREEN_HEIGHT} "$WEBSITE_URL" &
 
if [ $? -eq 0 ]; then
    echo "Chromium started successfully."
else
    echo "Failed to start Chromium."
    sudo reboot
fi

Edit the file: .bash_profile

bash
sudo nano /home/znas/.bash_profile
  • note: znas is the my username.

Add the following line to the bottom of the file, then save it and exit.

bash
[[ -z $DISPLAY && $XDG_VTNR -eq 1 ]] && startx -- -nocursor

Try Rebooting & Test!

bash
sudo reboot now

Enable uPower

bash
sudo apt install upower -y
sudo systemctl enable upower
sudo systemctl start upower
sudo systemctl status upower

More Optimization

Speed Up Boot

  1. Disable unnecessary services & Disable Logging to Reduce Memory Usage:

    bash
    sudo systemctl disable --now avahi-daemon.service  # Disable mDNS (not needed)
    sudo systemctl disable --now ModemManager.service  # Disable modem manager
    sudo systemctl disable --now triggerhappy.service  # Disable hotkey daemon
    sudo systemctl disable --now systemd-timesyncd.service  # Disable time sync (use cron instead)
     
    sudo systemctl disable hciuart
    sudo systemctl disable --now systemd-journald
    sudo systemctl disable --now rsyslog
  2. Disable Overscan (for full-screen display)

    bash
    sudo raspi-config
    • Display Options → D1 Underscan → Disable

    • Display Options > D5 Disable Splash Screen

    • Display Options > D5 Disable Splash Screen Edit the config.txt file:

    bash
    sudo nano /boot/config.txt

    If disable_splash is not found, add this line at the end:

    bash
    disable_splash=1
  3. Create Swap Memory

    plaintext
    sudo fallocate -l 1G /swapfile 
    sudo chmod 600 /swapfile
    sudo mkswap /swapfile
    sudo swapon /swapfile
    echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
    • sudo fallocate -l 512M /swapfile # Create a 512MB swap file

    To reduce SD card wear, set swappiness to 10:

    bash
    echo 'vm.swappiness=10' | sudo tee -a /etc/sysctl.conf
    sudo sysctl -p

To check logs

bash
/etc/xdg/openbox/autostart  > /tmp/kiosk.log 2>&1 &
cat /tmp/kiosk.log
bash
cat ~/.xsession-errors

Host change

bash
sudo nmtui
sudo rm -rf ~/.config/chromium/Singleton*

Set Timezone

bash
sudo timedatectl set-timezone Asia/Kolkata
sudo systemctl enable systemd-timesyncd
sudo systemctl restart systemd-timesyncd
timedatectl
Sanjay Sikdar

Written by Sanjay Sikdar

Software developer who enjoys developing software, solving challenges, and programming.