pi
Bought a pi Zero 2W model to configure as my server for the arduino devices to be used in the farm at Thenkodipakkam .
Initially installed and used Debian based Raspberry Pi OS.
But later on 2024-08-21 tried to install Alpine Linux in it. Now back to pi OS as on 2024-08-22. Running on Alpine Linux since many months now.
pihole
Installed and configured pihole from testing repository in mid-July 2025.
For pihole unbound is used as DNS server here.
- disabled blacklist from unbound
- updated /etc/apk/repositories to include @testing http://dl-cdn.alpinelinux.org/alpine/edge/testing↗
- added etc/unbound/unbound.conf.d/pi-hole.conf file from https://docs.pi-hole.net/guides/dns/unbound↗
- disabled the entire server section in /etc/unbound/unbound.conf file
The above changes have been committed using and should not cause issue when rebooting.
The following has to be done after every reboot.
$ doas apk update
$ doas apk add pihole@testing
$ doas addgroup pihole $USER
$ doas service pihole start
- Access web interface at pi.hole
- Add custom DNS server for unbound as per https://docs.pi-hole.net/guides/dns/unbound/↗
- Restart unbound service
- Add stevenblack list from http://sbc.io/hosts/hosts↗ and update gravity to load the list.
- https://git.sr.ht/~prabuanand/dotfiles/blob/master/home/prabu/.local/share/mydnd.txt↗
- In expert mode, disable logging from the admin panel. Save the settings.
system state before installing pihole
prabu@pizero2w ~> df -m
Filesystem 1M-blocks Used Available Use% Mounted on
tmpfs 225 77 148 35% /
prabu@pizero2w ~> free -m
total used free shared buff/cache available
Mem: 449 157 110 77 182 205
Top applications based on memory usage - output of smem
unbound 114780 kB
wpa_supplicant 6412 kB
fish 6324 kB
Top applications based on memory usage - output of smem after disabling stevenblack host file
unbound 25412 kB
wpa_supplicant 6412 kB
fish 6324 kB
prabu@pizero2w ~> free -m
total used free shared buff/cache available
Mem: 449 69 198 77 182 292
system state after installing and running pihole
prabu@pizero2w ~> free -m
total used free shared buff/cache available
Mem: 449 65 138 130 247 244
prabu@pizero2w ~> df -m
Filesystem 1M-blocks Used Available Use% Mounted on
tmpfs 225 119 107 53% /
Top applications based on memory usage - output of smem
unbound 15876 kB
pihole-FTL 10332 kB
fish 6708 kB
wpa_supplicant 6412 kB
lbu & mem Usage
every lbu usage takes quite good amount of available memory
pizero2W:~$ df -m
Filesystem 1M-blocks Used Available Use% Mounted on
devtmpfs 10 0 10 0% /dev
shm 209 3 207 1% /dev/shm
/dev/mmcblk0 61106 153 60953 1% /media/mmcblk0
tmpfs 209 102 107 49% /
tmpfs 84 1 84 1% /run
/dev/loop0 51 51 0 100% /.modloop
pizero2W:~$ free -m
total used free shared buff/cache available
Mem: 417 56 147 104 213 246
Swap: 0 0 0
pizero2W:~$ ls -lh /var/lib/pihole/
total 7.2M
drwxr-x--- 2 pihole pihole 80 Jan 1 1970 config_backups
-rw-r--r-- 1 pihole pihole 5.5K Sep 23 18:05 dnsmasq.conf
-rw-rw-r-- 1 pihole pihole 6.1M Nov 6 21:05 gravity.db
drwxr-xr-x 2 pihole pihole 80 Jan 1 1970 gravity_backups
-rw-rw-r-- 1 pihole pihole 100K Nov 6 21:05 gravity_old.db
drwxr-xr-x 2 pihole pihole 60 Jan 1 1970 hosts
drwxrwxr-x 2 pihole pihole 100 Jan 1 1970 listsCache
-rw-r----- 1 pihole pihole 348K Sep 23 18:04 pihole-FTL.db
-rw-r----- 1 pihole pihole 32K Sep 23 18:04 pihole-FTL.db-shm
-rw-r----- 1 pihole pihole 592K Nov 6 21:55 pihole-FTL.db-wal
pizero2W:~$ doas lbu st
doas (prabu@pizero2W) password:
U var/lib/pihole/pihole-FTL.db-wal
U home/prabu/.ash_history
pizero2W:~$ doas lbu ci
pizero2W:~$ df -m
Filesystem 1M-blocks Used Available Use% Mounted on
devtmpfs 10 0 10 0% /dev
shm 209 3 207 1% /dev/shm
/dev/mmcblk0 61106 156 60950 1% /media/mmcblk0
tmpfs 209 134 75 65% /
tmpfs 84 1 84 1% /run
/dev/loop0 51 51 0 100% /.modloop
pizero2W:/tmp$ doas du -d 1 -h
3.8M ./lbu-2662-1762446369-GvY8iSeP01
3.8M ./lbu-2622-1762446336-DkeX8ov563
25M ./lbu-2622-1762446335-eYxIL8L7go
0 ./.X11-unix
0 ./.ICE-unix
33M .
pizero2W:/tmp$ df -m
Filesystem 1M-blocks Used Available Use% Mounted on
devtmpfs 10 0 10 0% /dev
shm 209 3 207 1% /dev/shm
/dev/mmcblk0 61106 156 60950 1% /media/mmcblk0
tmpfs 209 134 75 65% /
tmpfs 84 1 84 1% /run
/dev/loop0 51 51 0 100% /.modloop
pizero2W:/tmp$ doas reboot
pizero2W:~$ df -m
Filesystem 1M-blocks Used Available Use% Mounted on
devtmpfs 10 0 10 0% /dev
shm 209 3 207 1% /dev/shm
/dev/mmcblk0 61106 156 60950 1% /media/mmcblk0
tmpfs 209 102 108 49% /
tmpfs 84 1 84 1% /run
/dev/loop0 51 51 0 100% /.modloop
pizero2W:~$ df -m /tmp/
Filesystem 1M-blocks Used Available Use% Mounted on
tmpfs 209 102 108 49% /
pizero2W:~$ du -d 1 -h /tmp/
0 /tmp/.X11-unix
0 /tmp/.ICE-unix
0 /tmp/
Headless Alpine
- https://www.reddit.com/r/AlpineLinux/comments/198tvjt/headless_raspberry_pi_zero_w_wont_connect_to_wifi/↗
- https://wiki.alpinelinux.org/wiki/Raspberry_Pi#Preparation↗
- https://wiki.alpinelinux.org/wiki/Alpine_on_ARM↗ ??
- https://wiki.alpinelinux.org/wiki/Classic_install_or_sys_mode_on_Raspberry_Pi↗
Downloaded the OS alpine-rpi-3.20.2-aarch64.tar.gz for pi Zero 2W: Dowloaded the headless.apkvol.tar.gz and 3 sample files from:
https://github.com/macmpi/alpine-linux-headless-bootstrap↗
The following steps has to be done to prepare the SD card first on any windows/linux PC.
# mkdir /mnt/pi
# mount /dev/sda1 /mnt/pi
Go into the first partition (fat16).
root@homepc2 /m/pi# tar xvf ~prabu/Downloads/alpine-rpi-3.20.2-aarch64.tar.gz
After extracting the tar file to the SD card, create and edit the usercfg.txt file as follows:
root@homepc2 /m/pi# touch usercfg.txt
root@homepc2 /m/pi# cat usercfg.txt
enable_uart=1
gpu_mem=32
Now, copy the above 3 files in addition to headless.apkovl.tar.gz to the root of sdcard. The headless should be in the tar.gz format and it need not be modified.
Now eject the SD card and insert it into the pi and power it on. Once logged in, the below login screen appears:
Alpine Linux headless bootstrap v1.2 by macmpi
...
Now proceed with the next stage of installation. Since next step requires more packages tried adding apkrepos and the inbuilt wget from buysbox generated below error, but the issue got resolved after installing wget.
alpine-headless:~# setup-apkrepos
200D7DA87F000000:error:0A000086:SSL routines:tls_post_process_server_certificate:certificate verify failed:ssl/statem/statem_clnt.c:2091:
ssl_client: SSL_connect
wget: error getting response: Connection reset by peer
20AD2EA77F000000:error:0A000086:SSL routines:tls_post_process_server_certificate:certificate verify failed:ssl/statem/statem_clnt.c:2091:
ssl_client: SSL_connect
alpine-headless:~# apk add wget
alpine-headless:~# lbu commit
With the above step and a reboot, the pi is usable, but works in diskless mode. To set up the OS in the System Disk Mode, have to proceed as per below wiki: https://wiki.alpinelinux.org/wiki/Classic_install_or_sys_mode_on_Raspberry_Pi#Update_boot_partition_(keep_alpine-rpi*_image_layout)↗
Formatted the second partiton i.e root. Still the installation did not work as per wiki:
pizero1:~# apk add e2fsprogs
pizero1:~# mkfs.ext4 /dev/mmcblk0p2
root@pizero1 ~# mount /dev/mmcblk0p2 /mnt
root@pizero1 ~# mount /dev/mmcblk0p1 /mnt/boot
mount: mounting /dev/mmcblk0p1 on /mnt/boot failed: Resource busy
Due to above error, have to proceed without mounting boot partition on rootfs. The above missing step causes quite bit of hassle for moving around boot files as can be seen below:
In the next step, installation stops due to a well known error “ext4 is not supported. Only supported are: vfat”
Based on below issue, have to use the flag export FORCE_BOOTFS=1 to proceed. https://gitlab.alpinelinux.org/alpine/aports/-/issues/12353#note_152955↗
root@pizero1 ~# mount /dev/mmcblk0p2 /mnt
root@pizero1 ~# export FORCE_BOOTFS=1
root@pizero1 ~# setup-disk -m sys /mnt
ext4 is not supported. Only supported are: vfat
Continuing at your own risk.
Installing system on /dev/mmcblk0p2:
100% █████████████████████████████████████████████████████████████████████████████████████████████████████████████████████
==> initramfs: creating /boot/initramfs-rpi for 6.6.45-0-rpi
/sbin/update-raspberrypi-bootloader: INFO: replaced config.txt and saved config.txt.old
Configured kernel vmlinuz-rpi / initramfs-rpi
root@pizero1 ~# mount -o remount,rw /media/mmcblk0p1
The below steps are nearly exact, except for one step as per wiki:
pizero1:/mnt# rm -f /media/mmcblk0p1/boot/*
pizero1:/mnt# rm boot/boot
pizero1:/mnt# rm -rf /media/mmcblk0p1/*
pizero1:/mnt# mv boot/* /media/mmcblk0p1/
The last step is different from wiki. Pay close attention to your ‘pwd’ before issusing the above commands. Now verify the important files and confirm they are correct, before rebooting the pi:
prabu@pizero1 ~> cat /etc/fstab
UUID=6d58c75c-4069-41ed-950e-951dd3f81117 / ext4 rw,relatime 0 1
/dev/mmcblk0p1 /boot vfat defaults 0 0 tmpfs /tmp tmpfs nosuid,nodev 0
0 pizero1:/mnt# cat /media/mmcblk0p1/cmdline.txt
root=UUID=6d58c75c-4069-41ed-950e-951dd3f81117
modules=sd-mod,usb-storage,ext4 quiet rootfstype=ext4
Inspite of all the trouble, unable to get the camera to work in Alpine Linux . Referred below sites and more:
- https://github.com/wjtje/libcamera-apps-alpine↗
- https://raspberrypi.stackexchange.com/questions/46851/raspberry-pi-2-camera-and-alpinelinux↗
So ended up going back to Raspberry Pi OS aka Raspbian on 2024-08-22. Even here, after wasting a good of time trying to install Pi OS using Alpine, finally went back to Arch to use Raspberry Pi Imager.
Use serial access
prabu@pizero2W ~> doas mount -o remount,rw /media/mmcblk0/
prabu@pizero2W ~> cat /media/mmcblk0/usercfg.txt
dtoverlay=dwc2,dr_mode=peripheral
prabu@pizero2W ~ [1]> cat /media/mmcblk0/cmdline.txt
modules=loop,squashfs,sd-mod,usb-storage quiet console=tty1
prabu@pizero2W ~> doas vi /media/mmcblk0/cmdline.txt
prabu@pizero2W ~> cat /media/mmcblk0/cmdline.txt
modules=loop,squashfs,sd-mod,usb-storage,g_serial quiet console=ttyGS0,115200 console=tty1
prabu@pizero2W ~> cat /media/mmcblk0/cmdline.txt
modules=loop,squashfs,sd-mod,usb-storage,g_serial console=ttyGS0,115200 console=tty1
cutdown bootloader
prabu@pizero2W /m/mmcblk0> doas apk add raspberrypi-bootloader-cutdown doas (prabu@pizero2W) password: (1/2) Installing raspberrypi-bootloader-common (1.20250820-r0) (2/2) Installing raspberrypi-bootloader-cutdown (1.20250820-r0) busybox-1.37.0-r24.trigger: Executing script… raspberrypi-bootloader-common-1.20250820-r0.trigger: Executing script… raspberrypi-bootloader-common-1.20250820-r0.trigger: /usr/sbin/update-raspberrypi-bootloader: WARNING: no kernel found OK: 81 MiB in 101 packages
Headless Raspberry Pi OS
To get the headless option have to pre-configure wifi, ssh and user account using Pi Imager.
Performance Tracking
On 2024-08-22 after basic OS installation
prabu@pizero1:~ $ df -m
Filesystem 1M-blocks Used Available Use% Mounted on
udev 73 0 73 0% /dev
tmpfs 42 1 41 3% /run
/dev/mmcblk0p2 59628 2020 54563 4% /
tmpfs 209 1 209 1% /dev/shm
tmpfs 5 1 5 1% /run/lock
/dev/mmcblk0p1 510 64 447 13% /boot/firmware
tmpfs 42 0 42 0% /run/user/1000
prabu@pizero1:~ $ free -m
total used free shared buff/cache available
Mem: 417 110 166 0 192 306
Swap: 199 25 174
On 2024-08-22 after system update
Added following new packages automatically: raspi-utils-core raspi-utils-dt raspi-utils-eeprom raspi-utils-otp raspinfo
prabu@pizero1:~ $ apt list --installed |wc -l
598
prabu@pizero1:~ $ free -m
total used free shared buff/cache available
Mem: 417 127 125 0 215 289
Swap: 199 0 199
prabu@pizero1:~ $ df -m
Filesystem 1M-blocks Used Available Use% Mounted on
udev 73 0 73 0% /dev
tmpfs 42 1 41 3% /run
/dev/mmcblk0p2 59628 2036 54546 4% /
tmpfs 209 0 209 0% /dev/shm
tmpfs 5 1 5 1% /run/lock
/dev/mmcblk0p1 510 64 447 13% /boot/firmware
tmpfs 42 0 42 0% /run/user/1000
On 2024-08-22 after adding Mosquitto
prabu@pizero1:~ $ apt list --installed |wc -l
603
prabu@pizero1:~ $ free -m
total used free shared buff/cache available
Mem: 417 133 175 0 159 283
Swap: 199 3 196
prabu@pizero1:~ $ df -m
Filesystem 1M-blocks Used Available Use% Mounted on
udev 73 0 73 0% /dev
tmpfs 42 1 41 3% /run
/dev/mmcblk0p2 59628 2038 54544 4% /
tmpfs 209 0 209 0% /dev/shm
tmpfs 5 1 5 1% /run/lock
/dev/mmcblk0p1 510 64 447 13% /boot/firmware
tmpfs 42 0 42 0% /run/user/1000
On 2024-08-22 after installing python-paho library based script:
prabu@pizero1 ~> apt list --installed |wc -l
612
prabu@pizero1 ~> df -m
Filesystem 1M-blocks Used Available Use% Mounted on
udev 73 0 73 0% /dev
tmpfs 42 1 41 3% /run
/dev/mmcblk0p2 59628 2074 54509 4% /
tmpfs 209 0 209 0% /dev/shm
tmpfs 5 1 5 1% /run/lock
/dev/mmcblk0p1 510 64 447 13% /boot/firmware
tmpfs 42 0 42 0% /run/user/1000
prabu@pizero1 ~> free -m
total used free shared buff/cache available
Mem: 417 125 129 0 213 291
Swap: 199 31 168
On 2024-08-23 after installing Motion
prabu@pizero1 ~ [1]> apt list --installed |wc -l
773
prabu@pizero1 ~> df -m
Filesystem 1M-blocks Used Available Use% Mounted on
udev 73 0 73 0% /dev
tmpfs 42 1 41 3% /run
/dev/mmcblk0p2 59628 2480 54102 5% /
tmpfs 209 1 209 1% /dev/shm
tmpfs 5 1 5 1% /run/lock
/dev/mmcblk0p1 510 64 447 13% /boot/firmware
tmpfs 42 0 42 0% /run/user/1000
prabu@pizero1 ~> free -m
total used free shared buff/cache available
Mem: 417 138 140 0 189 278
Swap: 199 39 160
on 2024-08-23 after successfully running motion with extra packages
prabu@pizero1 ~> apt list --installed |wc -l
859
prabu@pizero1 ~> df -m
Filesystem 1M-blocks Used Available Use% Mounted on
udev 73 0 73 0% /dev
tmpfs 42 1 41 3% /run
/dev/mmcblk0p2 59628 2974 53608 6% /
tmpfs 209 1 209 1% /dev/shm
tmpfs 5 1 5 1% /run/lock
/dev/mmcblk0p1 510 64 447 13% /boot/firmware
tmpfs 42 0 42 0% /run/user/1000
prabu@pizero1 ~> free -m
total used free shared buff/cache available
Mem: 417 192 157 0 124 224
Swap: 199 49 150
Using pi
pi camera
$libcamera-hello
prabu@pizero1:~ $ libcamera-hello
[5:53:55.355012758] [2138] INFO Camera camera_manager.cpp:313 libcamera v0.3.0+65-6ddd79b5
[5:53:55.425653823] [2141] WARN RPiSdn sdn.cpp:40 Using legacy SDN tuning - please consider moving SDN inside rpi.denoise
[5:53:55.431520539] [2141] INFO RPI vc4.cpp:446 Registered camera /base/soc/i2c0mux/i2c@1/ov5647@36 to Unicam device /dev/media0 and ISP device /dev/media1
[5:53:55.431666997] [2141] INFO RPI pipeline_base.cpp:1104 Using configuration file '/usr/share/libcamera/pipeline/rpi/vc4/rpi_apps.yaml'
Preview window unavailable
Mode selection for 1296:972:12:P
SGBRG10_CSI2P,640x480/0 - Score: 3296
SGBRG10_CSI2P,1296x972/0 - Score: 1000
SGBRG10_CSI2P,1920x1080/0 - Score: 1349.67
SGBRG10_CSI2P,2592x1944/0 - Score: 1567
Stream configuration adjusted
[5:53:55.434788767] [2138] INFO Camera camera.cpp:1183 configuring streams: (0) 1296x972-YUV420 (1) 1296x972-SGBRG10_CSI2P
[5:53:55.435402361] [2141] INFO RPI vc4.cpp:621 Sensor: /base/soc/i2c0mux/i2c@1/ov5647@36 - Selected sensor format: 1296x972-SGBRG10_1X10 - Selected unicam format: 1296x972-pGAA
stream video
- https://forums.raspberrypi.com/viewtopic.php?t=368067↗
- https://www.raspberrypi.com/documentation/computers/camera_software.html#rpicam-vid↗
On the pi:
$ rpicam-vid -t 0 --inline --listen -o tcp://0.0.0.0:8554
On the client:
$ mpv http://192.168.1.197:8554
(+) Video --vid=1 (h264 640x480 25.000fps)
VO: [gpu] 640x480 yuv420p
mqtt broker
The MQTT protocol is a machine-to-machine (M2M)/“Internet of Things” connectivity protocol. Designed as an extremely lightweight publish/subscribe messaging transport, it is useful for connections with remote locations where a small code footprint is required and/or network bandwidth is at a premium.
- https://randomnerdtutorials.com/how-to-install-mosquitto-broker-on-raspberry-pi/↗
- https://randomnerdtutorials.com/testing-mosquitto-broker-and-client-on-raspbbery-pi/↗
Installation
Installed the broker and clients
prabu@pizero1:~ $ sudo apt install mosquitto mosquitto-clients Reading package lists... Done Building dependency tree... Done Reading state information... Done The following additional packages will be installed: libcjson1 libdlt2 libmosquitto1 The following NEW packages will be installed: libcjson1 libdlt2 libmosquitto1 mosquitto mosquitto-clients 0 upgraded, 5 newly installed, 0 to remove and 0 not upgraded. Need to get 655 kB of archives. After this operation, 1,977 kB of additional disk space will be used. ... Created symlink /etc/systemd/system/multi-user.target.wants/mosquitto.service → /lib/systemd/system/mosquitto.service. prabu@pizero1:~ $ systemctl status mosquitto.service ● mosquitto.service - Mosquitto MQTT Broker Loaded: loaded (/lib/systemd/system/mosquitto.service; enabled; preset: enabled) .... 861 /usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf
mqtt user
Created mqtt user esp32 with same password, and modified config file:
prabu@pizero1:~ $ sudo mosquitto_passwd -c /etc/mosquitto/passwd esp32 prabu@pizero1:~ $ cat /etc/mosquitto/mosquitto.conf # Place your local configuration in /etc/mosquitto/conf.d/ # # A full description of the configuration file is at # /usr/share/doc/mosquitto/examples/mosquitto.conf.example per_listener_settings true pid_file /run/mosquitto/mosquitto.pid persistence true persistence_location /var/lib/mosquitto/ log_dest file /var/log/mosquitto/mosquitto.log include_dir /etc/mosquitto/conf.d listener 1883 allow_anonymous false password_file /etc/mosquitto/passwd
testing
Tested with sub and pub on the Alpine Linux :
prabu@homepc2 /d/d/p/l/pizero> mosquitto_sub -h 192.168.1.197 -u esp32 -P esp32 -t "pi/#" get_status prabu@homepc2 ~> mosquitto_pub -h 192.168.1.197 -u esp32 -P esp32 -t "pi/control" -m "get_status"On issuing the mosquitto_pub command, saw the message on mosquitto_sub window.
mqtt-paho
The Paho Python Client provides a client class with support for MQTT v5.0, MQTT v3.1.1, and v3.1 on Python 3.7+. It also provides some helper functions to make publishing one off messages to an MQTT server very straightforward. https://github.com/eclipse/paho.mqtt.python↗
The current implementation consists of two files:
The python script that makes use of Paho python client to respond to mqtt pub requests. The script must be an executable file. The following two python packages were installed for this script:
prabu@pizero1 ~> sudo apt install python3-paho-mqtt python3-psutil
prabu@pizero1 ~/backup> ls -l /usr/local/bin/
-rwxr-xr-x 1 root root 4936 Aug 22 20:22 mqtt_paho_client.py*
MQTT Paho Service file:
prabu@pizero1 ~/backup> cat etc/systemd/system/mqtt_paho.service
[Unit]
Description=MQTT Paho Service
After=network.target
[Service]
User=prabu
# Replace with the directory containing your script
WorkingDirectory=/usr/local/bin
ExecStart=/usr/bin/python /usr/local/bin/mqtt_paho_client.py
Restart=on-failure
[Install]
WantedBy=multi-user.target⏎
Based on the above mqtt_paho_client.py code, when mqtt client publishes the get_status message , all the subscribed mqtt clients receive the below reply:
prabu@homepc2 ~> mosquitto_pub -h 192.168.1.197 -u esp32 -P esp32 -t "pi/control" -m "get_status"
prabu@homepc2 ~> mosquitto_sub -h 192.168.1.197 -u esp32 -P esp32 -t "pi/#"
Current status of pizero1 at 20:36:16
CPU Usage: 0.2%
Memory Usage: 28.5%
CPU Temp: 45.1'C
Disk Usage: 3.7%
Uptime: 3:33:00
Network: 192.168.1.197
Processes: 139
Load Average: 1m 0.18, 5m 0.20, 15m 0.13
motion
The latest released version on motion website is 4.7 and then there is also 4.6. 4.7 is not yet available for aarch64 platform of bookworm.
prabu@pizero1 ~ [1]> sudo apt list motion Listing... Done
motion/stable 4.5.1-2 arm64
prabu@pizero1 ~ [1]> sudo apt install motion
0 upgraded, 161 newly installed, 0 to remove and 0 not upgraded.
Need to get 133 MB of archives.
After this operation, 422 MB of additional disk space will be used.
At the end of installation, found the below messages: Fixed them and checked the service status:
Setting up motion (4.5.1-2) ...
Adding group `motion' (GID 112) ...
Done.
adduser: Warning: The home dir /var/lib/motion you specified already exists.
Adding system user `motion' (UID 107) ...
Adding new user `motion' (UID 107) with group `motion' ...
adduser: The home directory `/var/lib/motion' already exists. Not touching this directory.
adduser: Warning: The home directory `/var/lib/motion' does not belong to the user you are currently creating.
Adding user `motion' to group `video' ...
Done.
Created symlink /etc/systemd/system/multi-user.target.wants/motion.service → /lib/systemd/system/motion.service.
Setting up ffmpeg (8:5.1.6-0+deb12u1+rpt1) ...
Processing triggers for man-db (2.11.2-2) ...
Broadcast message from systemd-journald@pizero1 (Fri 2024-08-23 14:50:55 IST):
motion[6672]: [0:motion] [EMG] [ALL] motion_startup: Exit motion, cannot create log file /var/log/motion/motion.log: Permission denied
prabu@pizero1 ~> systemctl status motion
○ motion.service - Motion detection video capture daemon
Loaded: loaded (/lib/systemd/system/motion.service; enabled; preset: enabled)
Active: inactive (dead) since Fri 2024-08-23 14:50:55 IST; 1min 32s ago
Duration: 3.951s
Docs: man:motion(1)
Process: 6672 ExecStart=/usr/bin/motion (code=exited, status=0/SUCCESS)
Main PID: 6672 (code=exited, status=0/SUCCESS)
CPU: 1.063s
Aug 23 14:50:51 pizero1 systemd[1]: Started motion.service - Motion detection video capture daemon.
Aug 23 14:50:55 pizero1 motion[6672]: [0:motion] [NTC] [ALL] conf_load: Processing thread 0 - config file /etc/motion/moti>
Aug 23 14:50:55 pizero1 motion[6672]: [0:motion] [NTC] [ALL] conf_load: Processing thread 0 - config file /etc/motion/moti>
Aug 23 14:50:55 pizero1 motion[6672]: [0:motion] [ERR] [ALL] mycreate_path: Problem creating directory /var/log/motion: Pe>
Aug 23 14:50:55 pizero1 motion[6672]: [0:motion] [EMG] [ALL] motion_startup: Exit motion, cannot create log file /var/log/>
Aug 23 14:50:55 pizero1 motion[6672]: [0:motion] [ERR] [ALL] mycreate_path: Problem creating directory /var/log/motion: Pe>
Aug 23 14:50:55 pizero1 motion[6672]: [0:motion] [EMG] [ALL] motion_startup: Exit motion, cannot create log file /var/log/>
Aug 23 14:50:55 pizero1 systemd[1]: motion.service: Deactivated successfully.
Aug 23 14:50:55 pizero1 systemd[1]: motion.service: Consumed 1.063s CPU time.
prabu@pizero1 ~ [3]> sudo mkdir /var/log/motion
prabu@pizero1 ~> sudo chown motion:motion /var/log/motion/
prabu@pizero1 ~> systemctl status motion
● motion.service - Motion detection video capture daemon
Loaded: loaded (/lib/systemd/system/motion.service; enabled; preset: enabled)
Active: active (running) since Fri 2024-08-23 14:53:43 IST; 2s ago
Docs: man:motion(1)
Main PID: 6880 (motion)
Tasks: 1 (limit: 174)
CPU: 818ms
CGroup: /system.slice/motion.service
└─6880 /usr/bin/motion
Aug 23 14:53:43 pizero1 systemd[1]: Started motion.service - Motion detection video capture daemon.
drwxr-s--- 2 motion adm 4096 Aug 23 14:50 motion/
prabu@pizero1 ~> sudo groups motion
motion : motion video
prabu@pizero1 ~> cat /etc/group |grep adm
adm:x:4:prabu
prabu@pizero1 ~> sudo chown motion:motion /var/lib/motion
Restored the earlier working configuration of motion and camera files. Took backup. Still camera did not work
prabu@pizero1 ~ [1]> sudo cp /etc/motion/motion.conf /etc/motion/motion.conf.default
prabu@pizero1 ~> sudo cp backup/etc/motion/motion.conf /etc/motion/
prabu@pizero1 ~> sudo cp backup/etc/motion/camera1.conf /etc/motion/
From https://motion-project.github.io/4.5.1/motion_config.html#basic_setup_picam↗
In the Raspbian version based upon Debian release of ‘bullseye’ (and presumably later releases), Raspbian allows access to the PI camera via an application called libcamera. libcamera provides access to the camera as a v4l2 device but this interface is only available when using a special application. Users must run Motion using the command “libcamerify motion” and then specify /dev/video0 in the Motion configuration file.
Error: Cant find libcamerify. libcamera-tools needs to be installed to solve the above error. https://github.com/Motion-Project/motion/discussions/1620↗
prabu@pizero1 ~> sudo apt install libcamera-tools
Also executed the below command from motion website documentation:
After updating the file /lib/systemd/system/motion.service, and restarting the service, noticed that systemctl status displayed the below error message:
ERROR: ld.so: object ‘/usr/lib/aarch64-linux-gnu/libcamera/v4l2-compat.so’ from LD_PRELOAD cannot be preloaded (cannot open shared object file): ignored.
As per https://forums.raspberrypi.com/viewtopic.php?t=358211↗ installed another package.
prabu@pizero1 ~> sudo apt install libcamera-v4l2
After the above packages are installed, picam started working.
git in Pi Zero
Installed git and configured bare repository to track the configuration changes.
Issued all the below commands after installing git:
git init --bare $HOME/.systemfiles
alias sysconfig='git --git-dir=$HOME/.systemfiles --work-tree=/'
echo "alias sysconfig='git --git-dir=/home/prabu/.systemfiles --work-tree=/'" >> ~/.config/fish/config.fish
source ~/.config/fish/config.fish
git config --global user.email kprabuanand@gmail.com
git config --global user.name "Prabu Anand Kalivaradhan"
sysconfig commit -m "config file from previous setup"
sysconfig config status.showUntrackedFiles no
cat .systemfiles/config
[core]
repositoryformatversion = 0
filemode = true
bare = true
[status]
showUntrackedFiles = no
prabu@pizero1 ~> sysconfig config status.showUntrackedFiles no
sysconfig remote add origin https://github.com/prabusw/pizero2W.git↗ was a mistake sysconfig remote set-url origin git+ssh://git@github.com/prabusw/pizero2W.git https://gist.github.com/ddeveloperr/1859fd395e7cb5832c59↗
nginx
samba
samba has been configured on the pi zero2W on a diskless Alpine Linux .
© Prabu Anand K 2020-2026