2025年2月16日日曜日

How to Create Docker Image of Raspbian

README

How to Create Docker Image of Raspbian

This guide explains how to create a Docker image for Raspbian on Ubuntu/Debian.

Preparation

First, download the Raspbian OS image and unzip it:

wget https://downloads.raspberrypi.com/raspios_lite_armhf/images/raspios_lite_armhf-2024-11-19/2024-11-19-raspios-bookworm-armhf-lite.img.xz
unzip 2024-11-19-raspios-bookworm-armhf-lite.img.xz

Inspect the OS Image

Use fdisk to inspect the image and identify partitions. We need Sector size and Start Sector of second image for mount.

$ sudo fdisk --list 2024-11-19-raspios-bookworm-armhf-lite.img
Disk 2024-11-19-raspios-bookworm-armhf-lite.img: 2.38 GiB, 2550136832 bytes, 4980736 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x57b902f5

Device                                      Boot   Start     End Sectors  Size Id Type
2024-11-19-raspios-bookworm-armhf-lite.img1         8192 1056767 1048576  512M  c W95 FAT32 (LBA)
2024-11-19-raspios-bookworm-armhf-lite.img2      1056768 4980735 3923968  1.9G 83 Linux

Mount and Create Docker Image

mkdir image
sudo mount -o loop,offset=$((512*1056768)) 2024-11-19-raspios-bookworm-armhf-lite.img image
cd image
sudo tar cf ../docker-image-2024-11-19-raspios-bookworm-armhf-lite.tar .

Import the archive as a Docker image:

docker import docker-image-2024-11-19-raspios-bookworm-armhf-lite.tar raspios-bookworm-armhf-lite:2024-11-19

Check if the image is registered:

docker image list

Install qemu

If your host is x86_64, enable ARM emulation:

sudo apt-get -y install qemu-user-static

Running the Docker Image

Run the container:

docker run -it raspios-bookworm-armhf-lite:2024-11-19 /bin/bash
uname -a
Linux f5f38b46dc55 6.1.0-31-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.128-1 (2025-02-07) armv7l GNU/Linux

Summary

This guide outlines creating a Docker image from a Raspbian image, importing it into Docker, and running it with QEMU emulation on non-ARM hosts.

2025年2月10日月曜日

Static IP Configuration on Raspbian

Static IP Configuration on Raspbian (Bookworm)

Static IP Configuration on Raspbian (Bookworm)

Setting a static IP address on Raspbian Bookworm ensures your Raspberry Pi always uses the same IP, making it easier to access remotely.

1. Open the NetworkManager Configuration

sudo nmcli connection show

2. Modify the Connection to Set a Static IP

sudo nmcli connection modify "Wired connection 1" ipv4.addresses 192.168.1.100/24
sudo nmcli connection modify "Wired connection 1" ipv4.gateway 192.168.1.1
sudo nmcli connection modify "Wired connection 1" ipv4.dns "8.8.8.8 8.8.4.4"
sudo nmcli connection modify "Wired connection 1" ipv4.method manual

Replace 192.168.1.100 with your desired IP, and adjust the gateway and DNS settings as needed.

3. Save and Apply the Configuration

sudo nmcli connection up "Wired connection 1"

4. Verify the Static IP

ip addr show eth0

Check that the IP address matches your static configuration.

Your Raspberry Pi is now set with a static IP address using NetworkManager! 🌐

Power Saving on Rasbian

Power Saving on Raspbian

Power Saving on Raspbian

Raspbian allows you to optimize settings for better power efficiency. This guide focuses on methods to reduce energy consumption, making your Raspberry Pi more efficient for battery-powered or always-on projects.

Check Current CPU Frequency

cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq

Set CPU Governor to 'powersave'

sudo cpufreq-set -g powersave

Set Maximum CPU Frequency

sudo cpufreq-set -u 600000

Disable HDMI to Save Power

sudo /usr/bin/tvservice -o

Turn Off Unused USB Devices

echo '1-1' | sudo tee /sys/bus/usb/drivers/usb/unbind

Reduce GPU Memory Allocation

sudo nano /boot/config.txt
# Add or modify:
gpu_mem=16

Applying these settings can significantly reduce power consumption, ideal for headless setups or long-term operations.

Happy optimizing your Raspberry Pi! ⚡