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.

0 件のコメント:

コメントを投稿