Notebook

これは日々の作業を通して学んだことや毎日の生活で気づいたことをを記録しておく備忘録である。

HTML ファイル生成日時: 2025/12/17 11:43:53.312 (台灣標準時)

Raspberry Pi 4 に NetBSD をインストールする方法

ウェブサーバーとして使っていた Raspberry Pi 4 が停電の後に起動しなくなっ てしまったので、 NetBSD をインストールし直すこととしたでござる。以下に その手順を記録しておくでござる。

まず、 micro-SD カードを用意し、それを FAT32 でフォーマットするでござ る。まず、 micro-SD カードをカードリーダーに差し込み、カードリーダーを 計算機の USB ポートに差し込むでござる。 sd0 として見えていることを確認 するでござる。


# dmesg | tail -4
[ 355036.397782] sd0 at scsibus0 target 0 lun 0:  disk removable
[ 355037.137786] sd0: fabricating a geometry
[ 355037.137786] sd0: 29664 MB, 29664 cyl, 64 head, 32 sec, 512 bytes/sect x 60751872 sectors
[ 355037.147786] sd0: fabricating a geometry

まず、 fdisk を使って現在の状況を見てみるでござる。


# fdisk sd0
fdisk: Cannot determine the number of heads
Disk: /dev/rsd0
NetBSD disklabel disk geometry:
cylinders: 29664, heads: 64, sectors/track: 32 (2048 sectors/cylinder)
total sectors: 60751872, bytes/sector: 512

BIOS disk geometry:
cylinders: 1023, heads: 255, sectors/track: 63 (16065 sectors/cylinder)
total sectors: 60751872

Partitions aligned to 2048 sector boundaries, offset 63

Partition table:
0: Primary DOS with 32 bit FAT - LBA (sysid 12)
    start 63, size 60751809 (29664 MB, Cyls 0-3781/160/27)
1: 
2: 
3: 
No active partition.

FAT32 でフォーマットされているでござるが、一度、それを消去し、改めて FAT32 でフォーマットすることにするでござる。まず、消去するでござる。


# fdisk -u /dev/rsd0d 
fdisk: Cannot determine the number of heads
Disk: /dev/rsd0d
NetBSD disklabel disk geometry:
cylinders: 29664, heads: 64, sectors/track: 32 (2048 sectors/cylinder)
total sectors: 60751872, bytes/sector: 512

BIOS disk geometry:
cylinders: 1023, heads: 255, sectors/track: 63 (16065 sectors/cylinder)
total sectors: 60751872

Partitions aligned to 2048 sector boundaries, offset 63

Do you want to change our idea of what BIOS thinks? [n] 

Partition table:
0: Primary DOS with 32 bit FAT - LBA (sysid 12)
    start 63, size 60751809 (29664 MB, Cyls 0-3781/160/27)
1: 
2: 
3: 
No active partition.
Drive serial number: 0 (0x00000000)
Which partition do you want to change?: [none] 0
The data for partition 0 is:
Primary DOS with 32 bit FAT - LBA (sysid 12)
    start 63, size 60751809 (29664 MB, Cyls 0-3781/160/27)
sysid: [0..255 default: 12] 0

Partition table:
0: 
1: 
2: 
3: 
No active partition.
Drive serial number: 0 (0x00000000)
Which partition do you want to change?: [none] 

Installed bootfile doesn't support required options.
Update the bootcode from /usr/mdec/mbr? [n] 

We haven't written the MBR back to disk yet.  This is your last chance.
Partition table:
0: 
1: 
2: 
3: 
No active partition.
Drive serial number: 0 (0x00000000)
Should we write new partition table? [n] y

消去されたか確認してみるでござる。


# fdisk /dev/rsd0d
fdisk: Cannot determine the number of heads
Disk: /dev/rsd0d
NetBSD disklabel disk geometry:
cylinders: 29664, heads: 64, sectors/track: 32 (2048 sectors/cylinder)
total sectors: 60751872, bytes/sector: 512

BIOS disk geometry:
cylinders: 1023, heads: 255, sectors/track: 63 (16065 sectors/cylinder)
total sectors: 60751872

Partitions aligned to 16065 sector boundaries, offset 63

Partition table:
0: 
1: 
2: 
3: 
No active partition.
Drive serial number: 0 (0x00000000)

消去されたことが確認できたので、新たに FAT32 のパーティションを作成す るでござる。


# fdisk -u /dev/rsd0d
fdisk: Cannot determine the number of heads
Disk: /dev/rsd0d
NetBSD disklabel disk geometry:
cylinders: 29664, heads: 64, sectors/track: 32 (2048 sectors/cylinder)
total sectors: 60751872, bytes/sector: 512

BIOS disk geometry:
cylinders: 1023, heads: 255, sectors/track: 63 (16065 sectors/cylinder)
total sectors: 60751872

Partitions aligned to 16065 sector boundaries, offset 63

Do you want to change our idea of what BIOS thinks? [n] 

Partition table:
0: 
1: 
2: 
3: 
No active partition.
Drive serial number: 0 (0x00000000)
Which partition do you want to change?: [none] 0
The data for partition 0 is:

sysid: [0..255 default: 169] 12
start: [0..3782cyl default: 63, 0cyl, 0MB] 
size: [0..3782cyl default: 60751809, 3782cyl, 29664MB] 
bootmenu: [] (space to clear)
The bootselect code is not installed, do you want to install it now? [n] 

Partition table:
0: Primary DOS with 32 bit FAT - LBA (sysid 12)
    start 63, size 60751809 (29664 MB, Cyls 0-3781/160/27)
1: 
2: 
3: 
No active partition.
Drive serial number: 0 (0x00000000)
Which partition do you want to change?: [none] 

Installed bootfile doesn't support required options.
Update the bootcode from /usr/mdec/mbr? [n] 

We haven't written the MBR back to disk yet.  This is your last chance.
Partition table:
0: Primary DOS with 32 bit FAT - LBA (sysid 12)
    start 63, size 60751809 (29664 MB, Cyls 0-3781/160/27)
1: 
2: 
3: 
No active partition.
Drive serial number: 0 (0x00000000)
Should we write new partition table? [n] y

FAT32 パーティションができたどうか確認するでござる。


# fdisk /dev/rsd0d
fdisk: Cannot determine the number of heads
Disk: /dev/rsd0d
NetBSD disklabel disk geometry:
cylinders: 29664, heads: 64, sectors/track: 32 (2048 sectors/cylinder)
total sectors: 60751872, bytes/sector: 512

BIOS disk geometry:
cylinders: 1023, heads: 255, sectors/track: 63 (16065 sectors/cylinder)
total sectors: 60751872

Partitions aligned to 2048 sector boundaries, offset 63

Partition table:
0: Primary DOS with 32 bit FAT - LBA (sysid 12)
    start 63, size 60751809 (29664 MB, Cyls 0-3781/160/27)
1: 
2: 
3: 
No active partition.
Drive serial number: 0 (0x00000000)

disklabel を使って状況を見てみるでござる。


# disklabel sd0
# /dev/rsd0:
type: SCSI
disk: SD/MMC          
label: fictitious
flags: removable
bytes/sector: 512
sectors/track: 32
tracks/cylinder: 64
sectors/cylinder: 2048
cylinders: 29664
total sectors: 60751872
rpm: 3600
interleave: 1
trackskew: 0
cylinderskew: 0
headswitch: 0           # microseconds
track-to-track seek: 0  # microseconds
drivedata: 0 

5 partitions:
#        size    offset     fstype [fsize bsize cpg/sgs]
 d:  60751872         0     unused      0     0        # (Cyl.      0 -  29663)
 e:  60751809        63      MSDOS                     # (Cyl.      0*-  29663)
disklabel: boot block size 0
disklabel: super block size 0

新たに作成した FAT32 用のパーティションは /dev/sd0e として見えているで ござる。 newfs_msdos コマンドを使って FAT32 ファイルシステムを作るでご ざる。


# newfs_msdos -F 32 /dev/rsd0e
/dev/rsd0e: 60722112 sectors in 1897566 FAT32 clusters (16384 bytes/cluster)
MBR type: 11
bps=512 spc=32 res=32 nft=2 mid=0xf0 spt=32 hds=64 hid=0 bsec=60751809 bspf=14825 rdcl=2 infs=1 bkbs=2

FAT32 でフォーマットできたはずなので、 mount してみるでござる。


# mount -t msdos /dev/sd0e /mnt
# df -m /mnt
Filesystem   1M-blocks      Used     Avail %Cap Mounted on
/dev/sd0e        29649         0     29649   0% /mnt

mount できたので、必要なファイルをダウンロードし、書き込むでござる。ま ず、 https://github.com/pftf/RPi4 から Raspberry Pi 4 用の UEFI firmware image をダウンロードするでござ る。

fig_202512/www_rpi4_uefi_00.png
fig_202512/www_rpi4_uefi_01.png
fig_202512/www_rpi4_uefi_02.png
fig_202512/www_rpi4_uefi_03.png

wget などのコマンドを使ってダウンロードすることもできるでござる。


% wget -O rpi4_uefi.zip https://github.com/pftf/RPi4/releases/download/v1.50/RPi4_UEFI_Firmware_v1.50.zip
--2025-12-16 13:06:49--  https://github.com/pftf/RPi4/releases/download/v1.50/RPi4_UEFI_Firmware_v1.50.zip
Resolving github.com (github.com)... 20.27.177.113
Connecting to github.com (github.com)|20.27.177.113|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://release-assets.githubusercontent.com/github-production-release-asset/224524130/73bbe3cf-d9c0-4c20-8e14-21258ba75f36?sp=r&sv=2018-11-09&sr=b&spr=https&se=2025-12-16T06%3A03%3A21Z&rscd=attachment%3B+filename%3DRPi4_UEFI_Firmware_v1.50.zip&rsct=application%2Foctet-stream&skoid=96c2d410-5711-43a1-aedd-ab1947aa7ab0&sktid=398a6654-997b-47e9-b12b-9515b896b4de&skt=2025-12-16T05%3A03%3A06Z&ske=2025-12-16T06%3A03%3A21Z&sks=b&skv=2018-11-09&sig=xmqltdf%2FEhf2nCusOYlI51QsjgBSK6zAwdXSrx%2FIx1Q%3D&jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmVsZWFzZS1hc3NldHMuZ2l0aHVidXNlcmNvbnRlbnQuY29tIiwia2V5Ijoia2V5MSIsImV4cCI6MTc2NTg2MTg2OSwibmJmIjoxNzY1ODYxNTY5LCJwYXRoIjoicmVsZWFzZWFzc2V0cHJvZHVjdGlvbi5ibG9iLmNvcmUud2luZG93cy5uZXQifQ.COVM8dV7U4Nq6OX-A2LzDOAE6TPOu5Y-c_HMW6gslmI&response-content-disposition=attachment%3B%20filename%3DRPi4_UEFI_Firmware_v1.50.zip&response-content-type=application%2Foctet-stream [following]
--2025-12-16 13:06:50--  https://release-assets.githubusercontent.com/github-production-release-asset/224524130/73bbe3cf-d9c0-4c20-8e14-21258ba75f36?sp=r&sv=2018-11-09&sr=b&spr=https&se=2025-12-16T06%3A03%3A21Z&rscd=attachment%3B+filename%3DRPi4_UEFI_Firmware_v1.50.zip&rsct=application%2Foctet-stream&skoid=96c2d410-5711-43a1-aedd-ab1947aa7ab0&sktid=398a6654-997b-47e9-b12b-9515b896b4de&skt=2025-12-16T05%3A03%3A06Z&ske=2025-12-16T06%3A03%3A21Z&sks=b&skv=2018-11-09&sig=xmqltdf%2FEhf2nCusOYlI51QsjgBSK6zAwdXSrx%2FIx1Q%3D&jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmVsZWFzZS1hc3NldHMuZ2l0aHVidXNlcmNvbnRlbnQuY29tIiwia2V5Ijoia2V5MSIsImV4cCI6MTc2NTg2MTg2OSwibmJmIjoxNzY1ODYxNTY5LCJwYXRoIjoicmVsZWFzZWFzc2V0cHJvZHVjdGlvbi5ibG9iLmNvcmUud2luZG93cy5uZXQifQ.COVM8dV7U4Nq6OX-A2LzDOAE6TPOu5Y-c_HMW6gslmI&response-content-disposition=attachment%3B%20filename%3DRPi4_UEFI_Firmware_v1.50.zip&response-content-type=application%2Foctet-stream
Resolving release-assets.githubusercontent.com (release-assets.githubusercontent.com)... 185.199.108.133, 185.199.111.133, 185.199.110.133, ...
Connecting to release-assets.githubusercontent.com (release-assets.githubusercontent.com)|185.199.108.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 3479292 (3.3M) [application/octet-stream]
Saving to: ‘rpi4_uefi.zip’

rpi4_uefi.zip       100%[===================>]   3.32M  1.69MB/s    in 2.0s    

2025-12-16 13:06:52 (1.69 MB/s) - ‘rpi4_uefi.zip’ saved [3479292/3479292]

ZIP ファイルの中身を見てみるでござる。


% unzip -l rpi4_uefi.zip 
Archive:  rpi4_uefi.zip
  Length      Date    Time    Name
---------  ---------- -----   ----
  3997696  11-21-2025 18:49   RPI_EFI.fd
    54264  11-21-2025 18:49   bcm2711-rpi-4-b.dtb
    54353  11-21-2025 18:49   bcm2711-rpi-400.dtb
    54873  11-21-2025 18:49   bcm2711-rpi-cm4.dtb
      243  11-21-2025 18:42   config.txt
     5496  11-21-2025 18:49   fixup4.dat
  2299008  11-21-2025 18:49   start4.elf
        0  11-21-2025 18:49   overlays/
     1566  11-21-2025 18:49   overlays/miniuart-bt.dtbo
     2775  11-21-2025 18:49   overlays/upstream-pi4.dtbo
     4998  11-21-2025 18:42   Readme.md
        0  11-21-2025 18:42   firmware/
     9136  11-21-2025 18:42   firmware/LICENCE.txt
        0  11-21-2025 18:42   firmware/brcm/
     7163  11-21-2025 18:42   firmware/brcm/brcmfmac43455-sdio.clm_blob
   631467  11-21-2025 18:42   firmware/brcm/brcmfmac43455-sdio.bin
     2172  11-21-2025 18:42   firmware/brcm/brcmfmac43455-sdio.txt
     2074  11-21-2025 18:42   firmware/brcm/brcmfmac43455-sdio.Raspberry
      502  11-21-2025 18:42   firmware/Readme.txt
---------                     -------
  7127786                     19 files

これらのファイルを FAT32 でフォーマットされた micro-SD カードに書き込 めばよいでござる。


# cd /mnt
# pwd
/mnt
# unzip /tmp/rpi4_uefi.zip 
Archive:  /tmp/rpi4_uefi.zip
 extracting: RPI_EFI.fd  
 extracting: bcm2711-rpi-4-b.dtb  
 extracting: bcm2711-rpi-400.dtb  
 extracting: bcm2711-rpi-cm4.dtb  
 extracting: config.txt  
 extracting: fixup4.dat  
 extracting: start4.elf  
   creating: overlays/
 extracting: overlays/miniuart-bt.dtbo  
 extracting: overlays/upstream-pi4.dtbo  
 extracting: Readme.md  
   creating: firmware/
 extracting: firmware/LICENCE.txt  
   creating: firmware/brcm/
 extracting: firmware/brcm/brcmfmac43455-sdio.clm_blob  
 extracting: firmware/brcm/brcmfmac43455-sdio.bin  
 extracting: firmware/brcm/brcmfmac43455-sdio.txt  
 extracting: firmware/brcm/brcmfmac43455-sdio.Raspberry  
 extracting: firmware/Readme.txt  

ファイルが書き込まれたかどうか見てみるでござる。


# ls -lF
total 6432
-rwxr-xr-x  1 root  wheel  3997696 Nov 21 18:49 RPI_EFI.fd*
-rwxr-xr-x  1 root  wheel     4998 Nov 21 18:42 Readme.md*
-rwxr-xr-x  1 root  wheel    54264 Nov 21 18:49 bcm2711-rpi-4-b.dtb*
-rwxr-xr-x  1 root  wheel    54353 Nov 21 18:49 bcm2711-rpi-400.dtb*
-rwxr-xr-x  1 root  wheel    54873 Nov 21 18:49 bcm2711-rpi-cm4.dtb*
-rwxr-xr-x  1 root  wheel      243 Nov 21 18:42 config.txt*
drwxr-xr-x  1 root  wheel    16384 Dec 16 13:09 firmware/
-rwxr-xr-x  1 root  wheel     5496 Nov 21 18:49 fixup4.dat*
drwxr-xr-x  1 root  wheel    16384 Dec 16 13:09 overlays/
-rwxr-xr-x  1 root  wheel  2299008 Nov 21 18:49 start4.elf*

書き込まれたようなので、 umount して、カードリーダーを取り外すでござる。


# cd
# umount /mnt

次に、外付け SSD を用意するでござる。外付け SSD を計算機の USB ポート に取り付けるでござる。


# dmesg | tail -7
[ 356770.416511] sd0 at scsibus0 target 0 lun 0:  disk fixed
[ 356770.416511] sd0: fabricating a geometry
[ 356770.416511] sd0: 931 GB, 953869 cyl, 64 head, 32 sec, 512 bytes/sect x 1953525168 sectors
[ 356770.426511] sd0: fabricating a geometry
[ 356770.476512] sd0: GPT GUID: 2c9eefbd-4a85-4a95-82dc-6b14dd7018a5
[ 356770.476512] dk6 at sd0: "EFI", 163840 blocks at 32768, type: msdos
[ 356770.476512] dk7 at sd0: "netbsd-root", 1953325056 blocks at 196608, type: ffs

NetBSD evbarm-aarch64 用のイメージをダウンロードするでござる。

fig_202512/www_netbsd_00.png
fig_202512/www_netbsd_01.png
fig_202512/www_netbsd_02.png
fig_202512/www_netbsd_03.png
fig_202512/www_netbsd_04.png
fig_202512/www_netbsd_05.png
fig_202512/www_netbsd_06.png
fig_202512/www_netbsd_07.png
fig_202512/www_netbsd_08.png
fig_202512/www_netbsd_09.png

wget でダウンロードするには、以下のようにすればよいでござる。


% wget http://nycdn.netbsd.org/pub/NetBSD-daily/netbsd-10/20251214142047Z/evbarm-aarch64/binary/gzimg/arm64.img.gz
--2025-12-16 13:15:24--  http://nycdn.netbsd.org/pub/NetBSD-daily/netbsd-10/20251214142047Z/evbarm-aarch64/binary/gzimg/arm64.img.gz
Resolving nycdn.netbsd.org (nycdn.netbsd.org)... 151.101.77.6, 2a04:4e42:12::262
Connecting to nycdn.netbsd.org (nycdn.netbsd.org)|151.101.77.6|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 401094848 (383M) [application/x-gzip]
Saving to: ‘arm64.img.gz’

arm64.img.gz        100%[===================>] 382.51M  6.79MB/s    in 60s     

2025-12-16 13:16:24 (6.37 MB/s) - ‘arm64.img.gz’ saved [401094848/401094848]

圧縮を解くでござる。


% gunzip arm64.img.gz
% ls -lF arm64.img 
-rw-r--r--  1 daisuke  wheel  1586495488 Dec 15 02:20 arm64.img
% file arm64.img 
arm64.img: DOS/MBR boot sector; partition 1 : ID=0xc, active, start-CHS (0x2,10,9), end-CHS (0xc,60,48), startsector 32768, 163840 sectors; partition 4 : ID=0xee, start-CHS (0x0,0,2), end-CHS (0x2,10,8), startsector 1, 32767 sectors

この arm64.img を dd コマンドを使って外付け SSD に書き込めばよいでござ る。


# dd if=/tmp/arm64.img of=/dev/rsd0d bs=1m
1513+0 records in
1513+0 records out
1586495488 bytes transferred in 17.599 secs (90146911 bytes/sec)

準備ができたので、 micro-SD カードと外付け SSD を Raspberry Pi 4 に取 り付けて、電源を入れれば、 NetBSD が起動するでござる。



Frequently accessed files

  1. Misc___Taiwan/20240207_00.html
  2. Computer___TeX/20240410_00.html
  3. Computer___TeX/20231107_00.html
  4. Misc___Taiwan/20240819_00.html
  5. Book___Chinese/20240424_00.html
  6. Computer___TeX/20230726_01.html
  7. Computer___TeX/20240411_00.html
  8. Computer___Python/20250330_00.html
  9. Misc___Japan/20240718_00.html
  10. Misc___Taiwan/20240903_01.html
  11. Computer___TeX/20240414_00.html
  12. Computer___Network/20230516_00.html
  13. Computer___NetBSD/20250301_01.html
  14. Computer___NetBSD/20230119_00.html
  15. Computer___TeX/20240414_01.html
  16. Computer___Network/20240130_00.html
  17. Computer___FreeBSD/20220621_0.html
  18. Computer___Python/20220715_0.html
  19. Computer___Python/20220518_0.html
  20. Computer___Network/20241214_00.html
  21. Computer___NetBSD/20240810_00.html
  22. Computer___NetBSD/20250409_00.html
  23. Computer___Debian/20230102_00.html
  24. Computer___Python/20240101_00.html
  25. Computer___NetBSD/20240805_03.html
  26. Computer___NetBSD/20250113_00.html
  27. Computer___NetBSD/20241102_00.html
  28. Computer___Hardware/20240820_00.html
  29. Computer___Python/20220410_0.html
  30. Misc___Japan/20240610_00.html


HTML file generated by Kinoshita Daisuke.