Raspberry Pi 5 向け Arch Linux イメージの作成
Raspberry Pi 5 (RPi5) に Arch Linux ARM (ALARM) をインストールしたので、その手順を残す。
ALARM は RPi5 に対応しておらず、 ALARM イメージをそのまま利用しても RPi5 はブートできない。今回は x86_64 のマシン上で ALARM イメージに chroot し、必要な設定を行うことでこれに対処する。
用意したもの
- ホスト: ブートメディアを作成するマシン。アーキテクチャは x86_64. ディストリビューションは Arch Linux (for x86_64).
- 必要であれば、 SD カードの読み書きができるデバイスも用意する。
- Raspberry Pi 5 (RPi5): 今回のターゲット環境。アーキテクチャは arm64.
ALARM の入手
Arch Linux ARM のページから入手可能
> wget http://os.archlinuxarm.org/os/ArchLinuxARM-aarch64-latest.tar.gz
ホストへのパッケージ追加
arm64 向けのイメージに chroot する際に利用するパッケージをインストールする。
まずは、 aarch64 向けバイナリを動作させるのに必要なパッケージ。 binfmt によって aarch64 向けの実行バイナリが QEMU の aarch64 エミュレーション環境上で実行されるようになる。
> sudo pacman -S qemu-user-static qemu-user-static-binfmt
systemd-binfmt サービスを動かしておく。
> sudo systemctl start systemd-binfmt.service
arch-install-scripits も入れておく。 chroot の wrapper である arch-chroot を提供するパッケージで、 chroot の操作に加えて /etc/resolv.conf の bind mount を行う。
> sudo pacman -S arch-install-scripts
SD カードパーティションの作成
fdisk を使って、 SD カード (今回は /dev/sda) に boot パーティションと rootfs パーティションを作成する。
fdisk では以下の設定をした:
- boot パーティションを 512MB で確保し、パーティションタイプを
W95 FAT32 (LBA)へ変更。 - 残りのパーティションを rootfs 用に確保する。パーティションタイプの変更はなし。
以下は、作業時のログ:
> sudo fdisk /dev/sda
[...]
Command (m for help): o
Created a new DOS (MBR) disklabel with disk identifier 0x84c3e00f.
The device contains 'dos' signature and it will be removed by a write command. See fdisk(8) man page and --wipe option for more details.
Command (m for help): p
Disk /dev/sda: 29.72 GiB, 31914983424 bytes, 62333952 sectors
Disk model: Multi-Card
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: 0x84c3e00f
Command (m for help): n
Partition type
p primary (0 primary, 0 extended, 4 free)
e extended (container for logical partitions)
Select (default p):
Using default response p.
Partition number (1-4, default 1):
First sector (2048-62333951, default 2048):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-62333951, default 62333951): +512M
Created a new partition 1 of type 'Linux' and of size 512 MiB.
Command (m for help): t
Selected partition 1
Hex code or alias (type L to list all): c
Changed type of partition 'Linux' to 'W95 FAT32 (LBA)'.
Command (m for help): n
Partition type
p primary (1 primary, 0 extended, 3 free)
e extended (container for logical partitions)
Select (default p): p
Partition number (2-4, default 2):
First sector (1050624-62333951, default 1050624):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (1050624-62333951, default 62333951):
Created a new partition 2 of type 'Linux' and of size 29.2 GiB.
Command (m for help): p
Disk /dev/sda: 29.72 GiB, 31914983424 bytes, 62333952 sectors
Disk model: Multi-Card
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: 0x84c3e00f
Device Boot Start End Sectors Size Id Type
/dev/sda1 2048 1050623 1048576 512M c W95 FAT32 (LBA)
/dev/sda2 1050624 62333951 61283328 29.2G 83 Linux
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
ファイルシステムの作成
作成したパーティションのそれぞれに対して、 mkfs でファイルシステムを作成する。
boot 用に確保した /dev/sda1 には mkfs.vfat 、 rootfs 用に確保した /dev/sda2 には mkfs.ext4 を用いた。
> sudo mkfs.vfat /dev/sda1
> sudo mkfs.ext4 /dev/sda2
マウント
/dev/sda1, /dev/sda2 を適当な場所にマウントする。
> mkdir -p ./mount/root ./mount/boot
> sudo mount /dev/sda1 ./mount/boot/
> sudo mount /dev/sda2 ./mount/root/
ALARM イメージの書き込み
ダウンロードした ALARM イメージを、マウントされた rootfs 領域に書き込む。
> sudo su
# tar -xpf ArchLinuxARM-aarch64-latest.tar.gz -C ./mount/root/
tar: Ignoring unknown extended header keyword 'LIBARCHIVE.xattr.security.capability'
tar: Ignoring unknown extended header keyword 'LIBARCHIVE.xattr.security.capability'
# exit
chroot
マウントした rootfs に chroot する。
> sudo arch-chroot ./mount/root /bin/bash
[root@machine /]#
pacman の初期化とパッケージ群のアップデートを行う。
# pacman-key --init
# pacman-key --populate archlinuxarm
# pacman -Syuu --noconfirm
タイムアウトしたため、いくつかのミラーを有効化すると改善した。
# diff -u /etc/pacman.d/mirrorlist.orig /etc/pacman.d/mirrorlist
--- /etc/pacman.d/mirrorlist.orig 2025-05-20 23:27:04.851321391 +0000
+++ /etc/pacman.d/mirrorlist 2025-05-20 23:29:27.156214459 +0000
@@ -33,16 +33,16 @@
### Japan
## Tokyo
-# Server = http://jp.mirror.archlinuxarm.org/$arch/$repo
+Server = http://jp.mirror.archlinuxarm.org/$arch/$repo
### Singapore
# Server = http://sg.mirror.archlinuxarm.org/$arch/$repo
### Taiwan
## Hsinchu
-# Server = http://tw2.mirror.archlinuxarm.org/$arch/$repo
+Server = http://tw2.mirror.archlinuxarm.org/$arch/$repo
## New Taipei City
-# Server = http://tw.mirror.archlinuxarm.org/$arch/$repo
+Server = http://tw.mirror.archlinuxarm.org/$arch/$repo
### United Kingdom
## London
@@ -50,7 +50,7 @@
### United States
## California
-# Server = http://ca.us.mirror.archlinuxarm.org/$arch/$repo
+Server = http://ca.us.mirror.archlinuxarm.org/$arch/$repo
## Florida
# Server = http://fl.us.mirror.archlinuxarm.org/$arch/$repo
## New Jersey
linux-rpi をインストールし、既存の linux-aarch64 を置き換える。
# pacman -Sy linux-rpi rpi5-eeprom --disable-sandbox
[...]
:: linux-rpi-6.12.28-1 and linux-aarch64-6.14.6-1 are in conflict (linux). Remove linux-aarch64? [y/N] y
[...]
RPi5 の boot に必要な .dtb が存在することを確認:
# ls /boot/bcm2712-rpi-5-b.dtb
/boot/bcm2712-rpi-5-b.dtb
chroot を終了
# exit
boot パーティションの準備
rootfs の /boot/ ディレクトリの内容を boot パーティションにコピーする。
RPi5 は このパーティション (/dev/sda1) を見てカーネル等をロードする。
> sudo cp -vr ./mount/root/boot/* ./mount/boot/
アンマウント
SD カードのパーティションをアンマウントする。
> sudo sync
> sudo umount ./mount/root/ ./mount/boot/
これで SD カードブートメディアの準備は完了となる。RPi5 に SD カードを挿して起動する。
参考
- Raspberry Pi 4 | Arch Linux ARM
- Raspberry Pi 5 with Arch Linux ARM and Encrypted Root
- Arch Linux ARM on a Raspberry Pi 5 Model B
- Howto install archlinuxarm raspberrypi5
- Chrooting into arm/arm64 environment from x86_64 | ArchWiki
#public