RaspberryPi – matoken's blog https://matoken.org/blog Is there no plan B? Fri, 11 Apr 2025 20:17:00 +0000 ja hourly 1 https://wordpress.org/?v=6.8.1 https://matoken.org/blog/wp-content/uploads/2025/03/cropped-1865f695c4eecc844385acef2f078255036adccd42c254580ea3844543ab56d9-32x32.jpeg RaspberryPi – matoken's blog https://matoken.org/blog 32 32 rpi-update後にRaspberry Piが起動しなくなってしまい困る https://matoken.org/blog/2025/03/06/raspberry-pi-stopped-booting/ https://matoken.org/blog/2025/03/06/raspberry-pi-stopped-booting/#respond Wed, 05 Mar 2025 22:37:18 +0000 https://matoken.org/blog/?p=4434

家で常時起動しているsingle-board computerのRaspberry Pi 3 model Bがkernel更新をした後再起動に失敗して起動しなくなりました.
長らく安定して動いていたので色々忘れていて解決まで時間がかかってしまいました.

追記)

その後しばらくしてまた起動しなくなりました.今度はmicroSD cardの読み込み,書き込みともにエラーとなりました.microSD自体が壊れてしまったようです.このときにはもう故障しかけていたのでしょうね…….

rpi-updateコマンドでkernelを更新した後から起動しなくなりました.
LEDの状態は赤点灯,緑不点灯でした.
UARTは何も出ず.(恐らくこのときにはUART-USBアダプタが故障していた)

たまに/bootの1つ目のFATパーティションにダーティビットが立って起動に失敗することがあるのでmicroSD cardをPCに繋いでfsckをかけましたが今回はこれは外れで問題ありませんでした.

$ sudo fsck -n /dev/mmcblk0p1
fsck from util-linux 2.40.4
fsck.fat 4.2 (2021-01-31)
/dev/mmcblk0p1: 394 files, 49156/261115 clusters

kernelのファイル群の展開や書き込み失敗したのかもと/bootを上書きすることに.
rpi-updateコマンドではバックアップもとっているようですがよく理解していないのでオリジナルイメージから書き込むことに.

Raspberry Pi OS bookworm armhfイメージの入手
$ lftp -c torrent https://downloads.raspberrypi.com/raspios_lite_armhf/images/raspios_lite_armhf-2024-11-19/2024-11-19-raspios-bookworm-armhf-lite.img.xz.torrent
Name: 2024-11-19-raspios-bookworm-armhf-lite.img.xz
dn:534M up:0 complete, ratio:0.00/0.00/0.00
  peers:24 connected:0 active:0 complete:0
Seeding in background...
[215700] Moving to background to complete transfers...
$ wget https://downloads.raspberrypi.com/raspios_lite_armhf/images/raspios_lite_armhf-2024-11-19/2024-11-19-raspios-bookworm-armhf-lite.img.xz.sha256 \
  https://downloads.raspberrypi.com/raspios_lite_armhf/images/raspios_lite_armhf-2024-11-19/2024-11-19-raspios-bookworm-armhf-lite.img.xz.sig
$ sha256sum -c 2024-11-19-raspios-bookworm-armhf-lite.img.xz.sha256
$ gpg --verify 2024-11-19-raspios-bookworm-armhf-lite.img.xz.sig
Note
gpg公開鍵はここのものを使いました.わかりやすいページが欲しいところです. https://www.raspberrypi.org/raspberrypi_downloads.gpg.key
Raspberry Pi OSイメージの展開とパーティションデバイスマップ
$ unxz 2024-11-19-raspios-bookworm-armhf-lite.img.xz
$ sudo kpartx -av ./2024-11-19-raspios-bookworm-armhf-lite.img
add map loop0p1 (254:3): 0 1048576 linear 7:0 8192
add map loop0p2 (254:4): 0 3923968 linear 7:0 1056768
1つ目のパーティションをmicro SDに上書き
$ sudo dd if=/dev/mapper/loop0p1 of=/dev/mmcblk0p1 bs=4M conv=fsync status=progress ; sync
$ sync
Note

if=::入力元デバイス
of=::出力先デバイス
bs=::ブロックサイズを4MBに変更
conv=fsync::ディスクへの書き出しを保証

この状態でRaspberry Piにmicro SDと接続して起動を試すとやはり失敗します.
そういえばUUIDが違うのではということで確認します.

Raspberry Pi OS bookworm armhf lite 2024-11-19でのUUID
$ sudo blkid /dev/mapper/loop0p2
/dev/mapper/loop0p2: LABEL="rootfs" UUID="bb15c8e6-d999-4838-be67-5ff200bffa46" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="57b902f5-02"
$ sudo mount -o ro /dev/mapper/loop0p1 /mnt
$ cat /mnt/cmdline.txt
console=serial0,115200 console=tty1 root=PARTUUID=57b902f5-02 rootfstype=ext4 fsck.repair=yes rootwait quiet init=/usr/lib/raspberrypi-sys-mods/firstboot
自分の環境のUUID
$ sudo blkid /dev/mmcblk0p2
/dev/mmcblk0p2: LABEL="rootfs" UUID="3a324232-335f-4617-84c3-d4889840dc93" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="71493291-02"

ずれているので1つ目のパーティションのcmdline.txtのroot=PARTUUID=の値をを利用中のrootになる2つ目のパーティションのPARTUUIDに書き換えます.

console=serial0,115200 console=tty1 root=PARTUUID=57b902f5-02 rootfstype=ext4 fsck.repair=yes rootwait quiet init=/usr/lib/raspberrypi-sys-mods/firstboot

console=serial0,115200 console=tty1 root=PARTUUID=71493291-02 rootfstype=ext4 fsck.repair=yes rootwait quiet init=/usr/lib/raspberrypi-sys-mods/firstboot

これで起動するようになりました.

ddする前にcmdline.txt, config.txtを退避しておいてdd後に戻す方が良かったですね.ddを使わずファイルコピーでも大丈夫だったと思います.

例えばこのようにcmdline.txt, config.txt以外をコピー(未検証)

rsync -avcI –exclude=cmdline.txt –exclude=config.txt $FROM $TO

若しくはmicroSDしか使っていないのでroot=/dev/mmcblk0p2のほうがいいかもしれません.

うまく行ったかと思いましたが,無線LANデバイスのwlan0が見えません.
有線LANは利用できたので,そちらからrpi-updateでkernelを更新して再起動することでデバイスが見え,接続も出来るようになりました.

ちなみにこの状態や,別のmicro SDでOSを書き込んだばかりの状態でもUARTから何も表示できませんでした.どうも断線してしまったようです.USB側はOSからserialに見えるので多分ピンソケットあたりを買って付けかえることで治りそうな感じはします.
でも手間や送料を考えると以下のようなものを買ってしまったほうがいいかもしれません.

PC環境
$ dpkg-query -W fdisk kpartx util-linux coreutils
coreutils       9.5-1+b1
fdisk   2.40.4-5
kpartx  0.11.1-1
util-linux      2.40.4-5
$ lsb_release -dr
Description:    Debian GNU/Linux trixie/sid
Release:        n/a
$ arch
x86_64
Raspberry Pi環境
$ lsb_release -dr
No LSB modules are available.
Description:    Raspbian GNU/Linux 12 (bookworm)
Release:        12
$ uname -a
Linux raspberrypi 6.12.16-v7+ #1859 SMP Mon Feb 24 13:10:45 GMT 2025 armv7l GNU/Linux
$ grep "^Model" /proc/cpuinfo
Model           : Raspberry Pi 3 Model B Rev 1.2
]]>
https://matoken.org/blog/2025/03/06/raspberry-pi-stopped-booting/feed/ 0
Raspberry Pi OS を buster から bullseye に dist-upgrade https://matoken.org/blog/2021/11/12/raspberry-pi-os-buster-to-bullseye-dist-upgrade/ https://matoken.org/blog/2021/11/12/raspberry-pi-os-buster-to-bullseye-dist-upgrade/#comments Thu, 11 Nov 2021 23:18:14 +0000 http://matoken.org/blog/?p=3430

Raspberry Pi OS bullseye がリリースされていたので手元のRaspberry Pi 3 model B のOS をbuster からbullseye にアップグレードしてみました.

今回の環境は以下のような感じです.

BOARD
Raspberry Pi 3 model B
OS
Raspberry Pi OS buster armhf
OS導入ストレージ
microSD 32GB
主なサービス
OpenSSH, samba
操作
ssh経由

バックアップ

/etc は etckeeper(git) で管理しているのでリモートにpush しておきます./home は手動でバックアップ.
その他必要に応じてバックアップ.

もしくはストレージをまるごとイメージでバックアップ.(SD Card Copier/dd等)

buster を最新にする

Raspberry Pi OS buster を最新の状態します.

$ sudo mount -o remount,rw /boot (1)
$ sudo apt update (2)
$ sudo apt upgrade (3)
$ sudo reboot (4)
  1. 読み取りファイルシステムを書き込み可能に
  2. パッケージ情報の更新
  3. パッケージを最新に
  4. 必要に応じて再起動

操作ログを取得する

script コマンドで操作ログをファイルに書き出すようにしておきます.何か合った時に参照します.(接続元の端末でも保存しておくと例えばdisk fullなどのときにも保存されるので安心)

$ script -a ~/buster2bullseye_$(date +%F-%T).log

パッケージの状態をチェックする

$ dpkg --audit (1)
$ dpkg --get-selections | grep 'hold
  1. エラーのあるパッケージがないか確認
  2. ホールド状態のパッケージがないか確認

APT source-list ファイルの準備

/etc/apt/sources.list を書き換えます.busterbullseye に変更.編集時には apt edit-sources コマンドを使うと文法チェックをしてくれる.

$ sudo apt edit-sources
$ cat /etc/apt/sources.list
deb http://raspbian.raspberrypi.org/raspbian/ bullseye main contrib non-free rpi
deb-src http://raspbian.raspberrypi.org/raspbian/ bullseye main contrib non-free rpi

/etc/apt/sources.list.d/ 以下も確認して,Raspberry Pi OS 以外のリポジトリはコメントアウトする.(apt edit-sources ${FILENAME} で編集可能)

パッケージ情報を更新する

$ sudo apt update

アップグレードに必要な容量があるか確認する

$ sudo apt -o APT::Get::Trivial-Only=true full-upgrade

読み込み専用ファイルシステムを書き込み可能にする

$ sudo mount -o remount,rw /boot

OpenSSH Server をアップグレードする

アップグレード中に新規の SSH 接続が出来ない ようなので前もってアップグレードしておく.(トラブルが起きなければ既存のセッションだけで問題ないはずだが念の為)

$ sudo apt install openssh-server

アップグレード後ssh 接続ができることを確認.

システムの最小アップグレード

$ sudo apt upgrade --without-new-pkgs

システムのアップグレード

$ sudo apt full-upgrade

手元の環境では full-upgrade 時に以下のような依存関係のエラーになりました.

$ sudo apt full-upgrade
Reading package lists... Done
Building dependency tree
Reading state information... Done
Calculating upgrade... Error!
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 libc6-dev : Breaks: libgcc-8-dev (< 8.4.0-2~) but 8.3.0-6+rpi1 is to be installed
E: Error, pkgProblemResolver::Resolve generated breaks, this may be caused by held packages.

gcc-8-base パッケージを導入して再度 dist-upgrade を試みることで解決しました.

$ sudo apt install gcc-8-base libc6-dev
$ sudo apt full-upgrade

KMS video driver の設定

/boot/config.txt を編集します.ファイル内の dtoverlay=vc4-fkms-v3d 行をコメントアウトし,[all] セクション内に dtoverlay=vc4-kms-v3d を記述します.

[all]
#dtoverlay=vc4-fkms-v3d (1)
dtoverlay=vc4-kms-v3d (2)
  1. コメントアウト
  2. 追記

再起動したら大体終わり.

RaspberryPiOS bullseye

後はサードパーティのAPT source-list ファイルを修正したり,アプリケーションの設定をしたり,bullseyeでサポートされなくなったパッケージを確認したり,アップグレード時に削除されたパッケージを確認したり…….

一通り設定が終わったらここでもバックアップをしておく.

]]>
https://matoken.org/blog/2021/11/12/raspberry-pi-os-buster-to-bullseye-dist-upgrade/feed/ 2
Raspberry Pi の OSイメージを書き込む Raspberry Pi Imager v1.6 の新機能で書き込み時にカスタマイズ https://matoken.org/blog/2021/03/26/burn-os-image-of-raspberry-pi-customize-when-writing-with-new-features-of-raspberry-pi-imager-v1-6/ https://matoken.org/blog/2021/03/26/burn-os-image-of-raspberry-pi-customize-when-writing-with-new-features-of-raspberry-pi-imager-v1-6/#respond Fri, 26 Mar 2021 13:40:51 +0000 http://matoken.org/blog/?p=3147

Raspberry Pi で利用するストレージへのOSイメージ書き込みツールのRaspberry Pi Imagerの最新版のv1.6がリリースされたようです.

自分は出た当初少し試しただけで他のツールに比べて嬉しいことがあまりないと感じたので使っていなかったのですが,このv1.6ではイメージのカスタマイズ機能が入ったようなので試してみました.

Raspberry Pi Imagerの導入

$ sudo apt install rpi-imager

Raspberry Pi OSであればパッケージが存在するのでこれを導入すればokです.

Linux/Windows/macOSはGitHubのreleaseページから入手できます.
若しくは,Raspberry Pi downloadsページにもあります.こちらだとGutHubとファイル名が違いますがamd64の.debをdiffしてみると同じもので署名ファイルもあります..AppImageもありますが試してみると最新ではないようでした.

$ wget https://github.com/raspberrypi/rpi-imager/releases/download/v1.6/rpi-imager_1.6_amd64.deb (1)
$ wget https://downloads.raspberrypi.org/imager/imager_1.6_amd64.deb https://downloads.raspberrypi.org/imager/imager_1.6_amd64.deb.sig (2)
$ diff ./imager_1.6_amd64.deb ./rpi-imager_1.6_amd64.deb (3)
$ gpg2 --verify ./imager_1.6_amd64.deb.sig (4)
gpg: assuming signed data in './imager_1.6_amd64.deb'
gpg: Signature made Tue 16 Mar 2021 08:56:51 PM JST
gpg:                using RSA key 54C3DD610D9D1B4AF82A37758738CD6B956F460C
gpg: Good signature from "Raspberry Pi Downloads Signing Key" [unknown]
gpg: WARNING: This key is not certified with a trusted signature!
gpg:          There is no indication that the signature belongs to the owner.
Primary key fingerprint: 54C3 DD61 0D9D 1B4A F82A  3775 8738 CD6B 956F 460C
$ gpg2 --verify ./imager_1.6_amd64.deb.sig ./rpi-imager_1.6_amd64.deb
gpg: Signature made Tue 16 Mar 2021 08:56:51 PM JST
gpg:                using RSA key 54C3DD610D9D1B4AF82A37758738CD6B956F460C
gpg: Good signature from "Raspberry Pi Downloads Signing Key" [unknown]
gpg: WARNING: This key is not certified with a trusted signature!
gpg:          There is no indication that the signature belongs to the owner.
Primary key fingerprint: 54C3 DD61 0D9D 1B4A F82A  3775 8738 CD6B 956F 460C
$ sudo apt install ././imager_1.6_amd64.deb (5)
  1. GitHubからダウンロード
  2. downloads.raspberrypi.orgからダウンロード
  3. ファイル名は違うけど同じ内容なのを確認
  4. 署名確認
  5. インストール

Debian sid amd64環境ではAppImageが古いので.debを導入しました.

Imagerの起動と書き込み設定

Raspberry Pi ロゴのアイコンの「Imager」や, rpi-imager を実行すると起動します.

ここで,「ctrl + shift + x」を押すことで今回のカスタマイズ用の拡張オプション画面が表示されます.

rpi imager01
rpi imager02
rpi imager03
rpi imager04

今回はhostnameの修正,SSHの有効化,ssh公開鍵の登録,Wi-Fi 設定,タイムゾーンの設定を行いました.

「SAVE」して「RASPBERRY PI OS LITE (32-BIT)」を書き込んでみました.

書き込みが終了しても1つ目のパーティション(/boot)がマウントされたままでした.これはバグかな?(1回しか試していないので勘違いかもしれない)

$ mount | grep /dev/mmcblk0p1 (1)
/dev/mmcblk0p1 on /media/matoken/boot type vfat (rw,nosuid,nodev,relatime,uid=1000,gid=1000,fmask=0022,dmask=0022,codepage=437,iocharset=ascii,shortname=mixed,showexec,utf8,flush,errors=remount-ro,uhelper=udisks2)
$ sudo umount /dev/mmcblk0p1 (2)
  1. 1つ目のパーティションがマウントされたまま
  2. アンマウントする

カスタマイズ内容確認

書き込まれたメディアの中を見ると /boot/firstrun.sh が作成されていました.Raspberry Pi Imagerは直接設定を書き換えるわけではなく,OSイメージを書き込んだあと子のファイルを作って,Raspberry Pi OSの初回起動時にこのscriptを実行して設定を反映していくようです.

/boot/firstrun.sh
#!/bin/bash

set +e

CURRENT_HOSTNAME=`cat /etc/hostname | tr -d " \t\n\r"`
echo raspberrypi-custom >/etc/hostname
sed -i "s/127.0.1.1.*$CURRENT_HOSTNAME/127.0.1.1\traspberrypi-custom/g" /etc/hosts
FIRSTUSER=`getent passwd 1000 | cut -d: -f1`
FIRSTUSERHOME=`getent passwd 1000 | cut -d: -f6`
install -o "$FIRSTUSER" -m 700 -d "$FIRSTUSERHOME/.ssh"
install -o "$FIRSTUSER" -m 600 <(echo "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPgwY9aZPxN/YoBBzd7TOcCk7EuGO0E9PuUjCHPtTuHP mk@x220") "$FIRSTUSERHOME/.ssh/authorized_keys"
echo 'PasswordAuthentication no' >>/etc/ssh/sshd_config
systemctl enable ssh
cat >/etc/wpa_supplicant/wpa_supplicant.conf <<WPAEOF
country=JP
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
ap_scan=1

update_config=1
network={
	ssid="matoken"
	psk="○○○○○○○○○○○○"
}

WPAEOF
chmod 600 /etc/wpa_supplicant/wpa_supplicant.conf
rfkill unblock wifi
for filename in /var/lib/systemd/rfkill/*:wlan ; do
  echo 0 > $filename
done
rm -f /etc/xdg/autostart/piwiz.desktop
rm -f /etc/localtime
echo "Asia/Tokyo" >/etc/timezone
dpkg-reconfigure -f noninteractive tzdata
cat >/etc/default/keyboard <<KBEOF
XKBMODEL="pc105"
XKBLAYOUT="us"
XKBVARIANT=""
XKBOPTIONS=""
KBEOF
dpkg-reconfigure -f noninteractive keyboard-configuration
rm -f /boot/firstrun.sh
sed -i 's| systemd.run.*||g' /boot/cmdline.txt
exit 0

ちょっと雑かなと感じるところもありますが便利な感じです.
( /etc/wpa_supplicant/wpa_supplicant.confwpa_passphrase コマンドを通してpskにしておきたいとか)

自分はsd card書き込み前にPCでマウントしてパッケージを最新にしたりインストールしたりといったことをしているので,sd card書き込みをしなくてもこのファイルを書き出してくれると嬉しいかなと思いました.

アンインストール

$ sudo apt purge rpi-imager
$ rm -r ~/.config/Raspberry\ Pi/Imager.conf ~/.cache/Raspberry\ Pi/Imager

パッケージを削除して,設定ファイルとキャッシュを削除しました.

環境

$ dpkg-query -W rpi-imager
rpi-imager      1.6
$ lsb_release -dr
Description:    Debian GNU/Linux bullseye/sid
Release:        unstable
$ uname -m
x86_64
]]>
https://matoken.org/blog/2021/03/26/burn-os-image-of-raspberry-pi-customize-when-writing-with-new-features-of-raspberry-pi-imager-v1-6/feed/ 0
Raspberry Pi OS armhfでWidevineDRMビデオを観られるようになったので試す https://matoken.org/blog/2021/03/21/watch-widevine-drm-video-on-raspberry-pi-os-armhf/ https://matoken.org/blog/2021/03/21/watch-widevine-drm-video-on-raspberry-pi-os-armhf/#respond Sat, 20 Mar 2021 22:05:39 +0000 http://matoken.org/blog/?p=3124

Raspberry Pi OS armhfに libwidevinecdm0 パッケージが入ったようです.Raspberry Pi 3 Model Bでも動作したのでメモしておきます.

libwidevinecdm0 パッケージはWidevineというDRM付きコンテンツを閲覧するためのパッケージです.

Widevineは結構あちこちで見かけます.siteには以下のようなサービスが載っていました.

libwidevinecdm0 services

まずWidevineに非対応な状態でNetflixのコンテンツを閲覧しようとするとこのようなエラーになります.

libwidevinecdm0 ng

Note
Netflixの会員じゃなくても次で試せます.
TV番組・ドラマを無料で視聴 | Netflix お試し無料配信

ここで libwidevinecdm0 パッケージを導入してChromiumを起動しなおせばOKなはずですがうまく行きません.
chrome://components/ を見ても Widevine が出てきません.

https://bitmovin.com/demos/drm にアクセスしてみると, Detected , using No DRM と表示されDRMが使えないようです.

Raspberry Pi 4 Model B/400以外の事例が見当たらないのでもしかして何らかの要件が足りなくてRaspberry Pi 4 より前のバージョンでは動かないのかな?とか思ったのですが,もう少し調べるとRaspberry Pi OSのChromiumには chromiumchromium-browser の2つのパッケージがあるようです.

chromium
$ apt show chromium
Package: chromium
Version: 88.0.4324.146-1~deb10u1
Priority: optional
Section: web
Maintainer: Debian Chromium Team <chromium@packages.debian.org>
Installed-Size: 114 MB
Provides: gnome-www-browser, www-browser
Depends: libasound2 (>= 1.0.16), libatk-bridge2.0-0 (>= 2.5.3), libatk1.0-0 (>= 2.2.0), libatomic1 (>= 4.8), libatspi2.0-0 (>= 2.9.90), libavcode
c58 (>= 7:4.0), libavformat58 (>= 7:4.1), libavutil56 (>= 7:4.0), libc6 (>= 2.28), libcairo2 (>= 1.6.0), libcups2 (>= 1.7.0), libdbus-1-3 (>= 1.9
.14), libdrm2 (>= 2.4.38), libevent-2.1-6 (>= 2.1.8-stable), libexpat1 (>= 2.0.1), libflac8 (>= 1.3.0), libfontconfig1 (>= 2.12.6), libfreetype6
(>= 2.3.9), libgbm1 (>= 17.1.0~rc2), libgcc1 (>= 1:4.0), libgdk-pixbuf2.0-0 (>= 2.22.0), libglib2.0-0 (>= 2.39.4), libgtk-3-0 (>= 3.19.12), libha
rfbuzz0b (>= 2.2.0), libicu63 (>= 63.1-1~), libjpeg62-turbo (>= 1.5.0), libjsoncpp1 (>= 1.7.4), liblcms2-2 (>= 2.2+git20110628), libminizip1 (>=
1.1), libnspr4 (>= 2:4.9-2~), libnss3 (>= 2:3.22), libopenjp2-7 (>= 2.2.0), libopus0 (>= 1.1), libpango-1.0-0 (>= 1.14.0), libpng16-16 (>= 1.6.2-
1), libpulse0 (>= 0.99.1), libre2-5 (>= 20160901), libsnappy1v5, libstdc++6 (>= 7), libvpx5 (>= 1.6.0), libwebp6 (>= 0.5.1), libwebpdemux2 (>= 0.
5.1), libwebpmux3 (>= 0.6.1-2), libx11-6 (>= 2:1.4.99.1), libxcb1 (>= 1.9.2), libxcomposite1 (>= 1:0.3-1), libxdamage1 (>= 1:1.1), libxext6, libx
fixes3, libxml2 (>= 2.7.4), libxrandr2, libxslt1.1 (>= 1.1.25), zlib1g (>= 1:1.2.2), chromium-common (= 88.0.4324.146-1~deb10u1)
Recommends: chromium-sandbox
Suggests: chromium-l10n, chromium-shell, chromium-driver
Conflicts: libgl1-mesa-swx11, libnettle4, libsecret-1-0 (<< 0.18)
Breaks: chromium-lwn4chrome (<= 1.0-2), chromium-tt-rss-notifier (<= 0.5.2-2)
Homepage: http://www.chromium.org/Home
Download-Size: 48.9 MB
APT-Sources: http://raspbian.raspberrypi.org/raspbian buster/main armhf Packages
Description: web browser
 Web browser that aims to build a safer, faster, and more stable internet
 browsing experience.
 .
 This package contains the web browser component.
chromium-browser
$ apt show chromium-browser
Package: chromium-browser
Version: 88.0.4324.187-rpt1
Priority: optional
Section: web
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Installed-Size: 329 MB
Provides: chromium, chromium-browser-inspector, www-browser
Pre-Depends: dpkg (>= 1.15.6)
Depends: libasound2 (>= 1.0.16), libatk-bridge2.0-0 (>= 2.5.3), libatk1.0-0 (>= 2.2.0), libatspi2.0-0 (>= 2.9.90), libc6 (>= 2.18), libcairo2 (>=
 1.6.0), libcups2 (>= 1.7.0), libdbus-1-3 (>= 1.9.14), libdrm2 (>= 2.4.38), libexpat1 (>= 2.0.1), libgbm1 (>= 17.1.0~rc2), libgcc1 (>= 1:4.3), li
bgdk-pixbuf2.0-0 (>= 2.22.0), libglib2.0-0 (>= 2.39.4), libgtk-3-0 (>= 3.21.5), libnspr4 (>= 2:4.9-2~), libnss3 (>= 2:3.22), libpango-1.0-0 (>= 1
.14.0), libx11-6 (>= 2:1.4.99.1), libxcb1 (>= 1.9.2), libxcomposite1 (>= 1:0.3-1), libxdamage1 (>= 1:1.1), libxext6, libxfixes3, libxkbcommon0 (>
= 0.5.0), libxrandr2, libxtst6, bash (>= 4), xdg-utils, chromium-codecs-ffmpeg-extra (= 88.0.4324.187-rpt1) | chromium-codecs-ffmpeg (= 88.0.4324
.187-rpt1), libraspberrypi0, libgl1-mesa-dri
Recommends: chromium-browser-l10n
Suggests: webaccounts-chromium-extension, unity-chromium-extension, adobe-flashplugin
Conflicts: chromium, chromium-browser-inspector
Replaces: chromium, chromium-browser-inspector
Homepage: https://chromium.googlesource.com/chromium/src/
Download-Size: 103 MB
APT-Manual-Installed: no
APT-Sources: http://archive.raspberrypi.org/debian buster/main armhf Packages
Description: Chromium web browser, open-source version of Chrome
 An open-source browser project that aims to build a safer, faster, and more
 stable way for all Internet users to experience the web.

そしてうまく行かなかったのは chromium でした.
chromium-browser を入れて(排他なので chromim パッケージは削除される)再度試すと,chrome://components/Widevine が現れて,

libwidevinecdm0 componets

https://bitmovin.com/demos/drm にアクセスしてみると, Detected , using widevine と表示されるようになりNetflixのコンテンツも閲覧できました.

libwidevinecdm0 netflix

Note
攻殻機動隊 SAC_2045 より.なんだかOPがPortal感

ということで,Raspberry Pi 3 Model B + Raspberry Pi OS armhf でも libwidevinecdm0 パッケージと chromium-browser パッケージを導入することでWidevineのDRMコンテンツが観られるようになりました :)
(DRMなしで閲覧できたほうが嬉しいですが)

$ sudo apt update
$ sudo apt install chromium-browser libwidevinecdm0
$ chromium-browser &
環境
$ dpkg-query -W chromium-browser* libwidevinecdm0
chromium-browser        88.0.4324.187-rpt1
chromium-browser-inspector
chromium-browser-l10n   88.0.4324.187-rpt1
libwidevinecdm0 4.10.1679.0-1
$ lsb_release -dr
Description:    Raspbian GNU/Linux 10 (buster)
Release:        10
$ uname -m
armv7l
$ cat /proc/device-tree/model ;echo
Raspberry Pi 3 Model B Rev 1.2
]]>
https://matoken.org/blog/2021/03/21/watch-widevine-drm-video-on-raspberry-pi-os-armhf/feed/ 0
Raspberry Pi の温度管理をソフトウェアで頑張る https://matoken.org/blog/2020/12/07/do-your-best-to-control-the-temperature-of-raspberry-pi-with-softwar/ https://matoken.org/blog/2020/12/07/do-your-best-to-control-the-temperature-of-raspberry-pi-with-softwar/#respond Sun, 06 Dec 2020 15:02:07 +0000 http://matoken.org/blog/?p=2881

この記事は日本Androidの会秋葉原支部ロボット部 Advent Calendar 2020 の12/07分の記事です.

内容は 日本Androidの会秋葉原支部ロボット部 第96回勉強会 で発表した内容を加筆修正したものです.

はじめに

Raspberry Pi という英国発の教育向けとして2012年に発売された安価なシングルボードコンピュータがあります.教育向けとして発売されましたが趣味にもよく使われています.OSは標準ではLinux(DebianベースのRaspberry Pi OS)が採用されています.

私はもっぱら省電力のLinuxマシンとして使うことが多いです.

トラブル

今夏空調のない部屋の自宅サーバの横でRaspberry Pi 3 model B + Raspberry Pi OS arm64(β)で計算をさせていたのですが,しばらく動かしていると固まるようになりました.

再起動すればしばらく動きますがしばらくするとやはり固まります.これをどうにか出来ないかと調べてみました.

ログの取得

まずはログを録ってみます.

crontabで1分毎に情報を記録
* * * * *       printf "`date +\%s`,`cat /sys/class/thermal/thermal_zone0/temp`,`echo "obase=2; ibase=16; \`vcgencmd get_throttled | cut -f2 -dx\`" | bc`,`vcgencmd measure_clock arm|cut -f2 -d=`\n" >> ~/.temp.log

内容はこんな感じです.(外気温度も録ればよかった)

UNIX Time
date +%s
SoC温度
/sys/class/thermal/thermal_zone0/temp
スロットリング周りのフラグ
vcgencmd get_throttled
arm周波数
vcgencmd measure_clock arm

ログがファイルに書かれる間にフリーズしてデータが失われるのを防ぐために /etc/fstab のマウントオプションに sync オプションも付けておきます.(再起動かremountで反映)

ログを取得している状態で負荷を掛けます.今回は /dev/urandom をcatすることで計算させました.今回のRaspberry Pi 3 model Bは4coreあるので4つ動かしています.

今回のテストで使った負荷(いつもはvanity address/vttとかとか)
$ cat /dev/urandom > /dev/null &
$ cat /dev/urandom > /dev/null &
$ cat /dev/urandom > /dev/null &
$ cat /dev/urandom > /dev/null &

熱が原因?

しばらく動かしてRaspberry Piが固まった後にログを確認してみます.
SoCの温度が85度を何度か記録した後に固まっているようです.
85度というのはRaspberry Pi OSでの標準のSoC制限温度のようです.この温度の5度前(標準では80度)からサーマルスロットリングが始まるようです.

サーマルスロットリングでクロックが下がって温度が下がれば問題無さそうだけど80度からクロックが下がっても85度を超えて固まってしまっているようです.
ベータ版のRaspberry Pi OS amd64を使っているせいかもしれないと思い,標準のRaspberry Pi OS armhf(32bit)版に変更して同様に試してみましたが同様の動きのようです.

正攻法としてはヒートシンク,ファンの増設や空調を入れるとよさそうですが,金欠なのでとりあえずソフトだけでどうにか出来ないかと試しました.

SoC制限温度を下げる

まずSoCの制限温度ですが,公式フォーラムで70度以下にしたほうがいいという書き込みを見かけました.逆に100度でも大丈夫という人も居るのですが安全側の70度にしてみます.

この設定は /boot/config.txt でパラメータを設定できます.以下は70度に設定たときの例です.この状態で再起動すると反映されます.

temp_limit=70

再起動後以下のコマンドで設定が反映されているか確認が出来ます.

$ vcgencmd get_config int | grep ^temp_limit=
temp_limit=70

この状態で負荷を掛けると70度を越えるくらいで固まりました.やはり制限温度を越えると固まってい舞うようです.

SoCの最大周波数を下げてみる

Raspberry Pi 3 model B のSoCは最大周波数1.2GHzです.これを下げてみます.

/boot/config.txtarm_freq= で設定できます.以下は800MHzに設定したときの例です.再起動で反映されます.

arm_freq=800

再起動後に設定が反映されているか確認します.

$ vcgencmd get_config int | grep ^arm_freq=
arm_freq=800

この状態で負荷を掛けるとやはり固まります.まあサーマルスロットリングが効いても固まるので仕方がない感じです.

SoCの最小周波数を下げてみる(これが効くのでは?)

次にSoC最小周波数を下げてみます.既定値は600MHzで,サーマルスロットリングでもここまで下がっているのでこれを更に下げると温度が下がりそうな気がします.

/boot/config.txtarm_freq_min= で設定できます.以下は400MHzに設定したときの例です.再起動で反映されます.

arm_freq_min=400

しかし再起動後に確認してみると600MHzより下には設定できないみたいで600MHzになってしまいます.

$ vcgencmd get_config int | grep ^arm_freq_min=
arm_freq_min=600

この状態で負荷を掛けるとやはり600Mhzまでしか下がらず固まります.

残念ながらRaspberry Pi のスロットリングでは無理そうです.

maxcpusでコアを制限してみる

Linuxのブートパラメータで maxcpus を指定することでコアを制限できます.Raspberry Pi の場合は /boot/cmdline.txt で設定できます.

設定後以下のコマンドで確認できます.

$ grep -o -E 'maxcpus=.{0,9} ' /proc/cmdline
maxcpus=1
$ grep ^processor /proc/cpuinfo | wc -l
1

これでCPU core1津で動作しています.しかし最大周波数を600MHzかつ1coreでも同様にフリーズしてしまいました.

cpufreqでクロック制御

IntelCPUのNotePCなどではcoufreqを使ってこのあたりの制御をするのですが,これでも600mHzより下には下げられないようで駄目でした.

LimitCPUで指定プロセスの制限を行う

LimitCPUは指定プロセスを監視し,CPU利用率や%で制限するプログラムです.Linux, MacOS, *BSDなどのUNIX-Likesystemで利用できます.
Raspberry Pi OSではcpulimitパッケージとしてパッケージングされており,コマンドもcoulimitです.

cpulimitの導入
$ sudo apt install cpulimit

cpulimitコマンドに制限したいプロセスIDやプロセス名と制限を指定することで動作します.

cat からはじまるプロセスを50%に制限
$ pgrep ^cat | xargs -n1 -I{} sh -c "cpulimit -p {} -l 50 -v &"

cpulimitで50%に制限してみたt頃温度が下がるのを確認できました.数日動かしても固まらなくなったようです.
定期的にSoCの温度を確認して制限を変更していくと良さそうでうs.

LimitCPUはCPUlimitの開発が止まった後のフォークですが,その後CPUlimitが新しく開発が始まっているようです.詳細は以下のページを参照してください.

cgroupでCPUリソース制限(未確認)

LimitCPUが効いたので恐らくcgroupでのCPUリソース制限でも大丈夫そうです.(未確認)

おわりに

現在は気温も下がり制限などしなくても問題ありません.でもきっと来夏にまた起こると思うのでそこでまた確認するつもりです.

しかし,今回の解決方法はCPUのリソースを制限して温度を下げて居るので計算量は減っています.空調を入れたりCPUファンを導入するのが正攻法になるのかなと思います.
CPUファンはサードパーティーから各種発売されているのでそれらを使うかDIYする感じになると思います.

そういえば最近Raspberry Pi OSの設定コマンドの raspi-config の中に Set behaviour of GPIO fan というメニューが出来たり,Raspberry Pi 4には公式のCPUファンが発売されているのでこれらを使うのが良さそうです.

]]>
https://matoken.org/blog/2020/12/07/do-your-best-to-control-the-temperature-of-raspberry-pi-with-softwar/feed/ 0
Raspberry Pi Model Bの8GB RAM版の発売とRaspberry Pi OS https://matoken.org/blog/2020/05/30/8gb-ram-version-of-raspberry-pi-model-b-launched-and-raspberry-pi-os/ https://matoken.org/blog/2020/05/30/8gb-ram-version-of-raspberry-pi-model-b-launched-and-raspberry-pi-os/#respond Sat, 30 May 2020 14:03:11 +0000 http://matoken.org/blog/?p=2754

Raspberry Pi 4 Model Bの8GB RAM版が発表.同時に発売され,日本も同時発売になったようです.

日本だと今はこのあたりでしょうか.

RAM が8GB あるとデスクトップ用途がRAM を気にせず使えるようになりそうですね.後は例えばビデオミーティングアプリのJitsi Meet をRaspberry Pi でホストしている人がいたりしますが,現在は設定を少し変えて省エネ設定で動かしていますが規定値の設定で動きそうです.
そして8GBもあると気になるのが標準OSのRaspbianがarmhf(32bit)にしか対応していないところ.
別のディストリビューションを使えばarm64(b4bit)は利用できますが標準OSが非対応なのはちょっと悲しいです.

私はDebian をよく使います.

これも今回発表がありました.64bit版のベータがリリースされました.

Not to be left out, today we’ve released an early beta of our own 64-bit operating system image.

Raspbianの名前も変わり,Raspberry Pi OS と改められるようです.

Both our 32-bit and 64-bit operating system images have a new name: Raspberry Pi OS.

新しい64bitの Raspberry Pi OS は以下から入手できます.

ダウンロードサイトのディレクトリもraspiosが出来ています.これまでの32bitは raspios_armhf になるようです.

$ w3m -dump https://downloads.raspberrypi.org/ | grep -E 'raspbian|raspios'
[DIR] raspbian/                         2020-02-25 16:50    -
[DIR] raspbian_full/                    2020-02-14 13:52    -
[DIR] raspbian_lite/                    2020-02-14 13:49    -
[DIR] raspios_arm64/                    2020-05-28 04:38    -
[DIR] raspios_armhf/                    2020-05-28 05:27    -
[DIR] raspios_full_armhf/               2020-05-28 05:28    -
[DIR] raspios_lite_armhf/               2020-05-28 05:27    -
[ ]   wp-slice-raspbian                 2020-05-28 07:46 1.0K

armhfのリリースノートを観るとこれまでのものに今回のバージョンが追記されていました.(64biには未だ存在しない)

$ w3m -dump https://downloads.raspberrypi.org/raspios_armhf/release_notes.txt | grep ^2020-05-27:$ -A 33
2020-05-27:
  * Added Bookshelf application
  * Added Raspberry Pi Diagnostics application
  * Added magnifier plugin to taskbar - needs magnifier application installed from Recommended Software to enable
  * Added Magnifier application to Recommended Software
  * Added marketing questionnaire as initial Chromium tab
  * Version 0.25 of Scratch 2 included - uses external application to access IMU on SenseHAT
  * Version 1.0.5 of Scratch 3 included - uses external application to access IMU on SenseHAT
  * Version 32.0.0.371 of Flash player included
  * Version 1.0.6 of Node-RED included
  * Version 6.7.1 of VNC Server included
  * Version 6.20.113 of VNC Client included
  * Internal audio outputs enabled as separate ALSA devices
  * MagPi preinstall removed and replaced with Beginner’s Guide
  * MagPi weblink removed from main menu
  * Chromium made default application for PDF files
  * Common icon loading code for lxpanel plugins used
  * Italian translations added
  * Initial move of mouse pointer to menu button disabled
  * Padding at left of menu button removed
  * Focus behaviour changed so that focus moves to desktop if no windows are opened - improves reliability of Orca screen reader
  * Bug fix - focus bug in volume plugin
  * Bug fix - keyboard repeat interval bug in Mouse & Keyboard Settings
  * Bug fix - battery detection bug in battery plugin
  * Bug fix - spurious active areas on taskbar when plugins are hidden
  * Bug fix - occasional crash in file manager on file selection
  * Disk ID is now regenerated on first boot
  * Updated udev rules
    - Remove unused argon rule
    - Add vcsm-cma to video group
    - Add pwm to gpio group
  * i2cprobe: More flexible I2C/SPI alias mapping
  * Raspberry Pi firmware 21e1fe3477ffb708a5736ed61a924fd650031136
  * Linux kernel 4.19.118

Raspberry Pi の Download ページを観るとここもアップデートされていました.

Raspberry Pi OS (previously called Raspbian) is our official operating system for all models of the Raspberry Pi.

この64bit beta版はRaspberry Pi 3 と 4 で動作するようです.(2 v1.2でも多分動く)

Note, the 64bit OS is only install-able on the Pi 3 and Pi 4 devices

ということでRaspberry Pi 3 なら持ってる!ということでダウンロードしてみました.

$ wget https://downloads.raspberrypi.org/raspios_arm64/images/raspios_arm64-2020-05-28/2020-05-27-raspios-buster-arm64.zip https://downloads.raspberrypi.org/raspios_arm64/images/raspios_arm64-2020-05-28/2020-05-27-raspios-buster-arm64.zip.sha256 https://downloads.raspberrypi.org/raspios_arm64/images/raspios_arm64-2020-05-28/2020-05-27-raspios-buster-arm64.zip.sig
$ sha256sum -c 2020-05-27-raspios-buster-arm64.zip.sha256
2020-05-27-raspios-buster-arm64.zip: OK
$ gpg --verify ./2020-05-27-raspios-buster-arm64.zip.sig
gpg: assuming signed data in './2020-05-27-raspios-buster-arm64.zip'
gpg: Signature made Thu 28 May 2020 01:05:10 PM JST
gpg:                using RSA key 54C3DD610D9D1B4AF82A37758738CD6B956F460C
gpg: Good signature from "Raspberry Pi Downloads Signing Key" [expired]
gpg: Note: This key has expired!
Primary key fingerprint: 54C3 DD61 0D9D 1B4A F82A  3775 8738 CD6B 956F 460C

署名の確認をすると期限切れのようです.新しい鍵を貰ってきてインポートして再度署名確認します.(ダウンロードページあたりにリンクして欲しい)

$ wget https://www.raspberrypi.org/raspberrypi_downloads.gpg.key
$ gpg ./raspberrypi_downloads.gpg.key
gpg: WARNING: no command supplied.  Trying to guess what you mean ...
pub   rsa2048 2017-04-10 [SC] [expires: 2021-04-21]
      54C3DD610D9D1B4AF82A37758738CD6B956F460C
uid           Raspberry Pi Downloads Signing Key
sub   rsa2048 2017-04-10 [E] [expires: 2021-04-21]
$ gpg --import ./raspberrypi_downloads.gpg.key
gpg: key 8738CD6B956F460C: 1 signature not checked due to a missing key
gpg: key 8738CD6B956F460C: "Raspberry Pi Downloads Signing Key" 3 new signatures
gpg: Total number processed: 1
gpg:         new signatures: 3
  :
$ gpg --verify ./2020-05-27-raspios-buster-arm64.zip.sig
gpg: assuming signed data in './2020-05-27-raspios-buster-arm64.zip'
gpg: Signature made Thu 28 May 2020 01:05:10 PM JST
gpg:                using RSA key 54C3DD610D9D1B4AF82A37758738CD6B956F460C
gpg: Good signature from "Raspberry Pi Downloads Signing Key" [unknown]
gpg: WARNING: This key is not certified with a trusted signature!
gpg:          There is no indication that the signature belongs to the owner.

とりあえず良さそうです.

sd card等に書き込みます.今回dd で書きましたが,公式のRaspberry Pi Imager を使ったほうがいいかもですね.

$ time zcat ./2020-05-27-raspios-buster-arm64.zip | pv | sudo dd of=/dev/sdz bs=16M conv=fdatasync
3.46GiB 0:02:34 [22.9MiB/s] [                                                                                                                                 <=>               ]
0+92723 records in
0+92723 records out
3711959040 bytes (3.7 GB, 3.5 GiB) copied, 212.594 s, 17.5 MB/s

real    3m32.613s
user    0m30.584s
sys     2m12.420s
$ sync

これを使って起動してみると普通に起動します.

Raspberry Pi 3 Model B Rev 1.2で試しました
$ cat /proc/device-tree/model ;echo
Raspberry Pi 3 Model B Rev 1.2
aarch64 kernelです
$ uname -a
Linux raspberrypi 5.4.42-v8+ #1319 SMP PREEMPT Wed May 20 14:18:56 BST 2020 aarch64 GNU/Linux
パッケージもarm64
$ LC_ALL=C dpkg-architecture --print-set
DEB_BUILD_ARCH=arm64; DEB_BUILD_ARCH_ABI=base; DEB_BUILD_ARCH_BITS=64; DEB_BUILD_ARCH_CPU=arm64; DEB_BUILD_ARCH_ENDIAN=little; DEB_BUILD_ARCH_LIBC=gnu; DEB_BUILD_ARCH_OS=linux;
DEB_BUILD_GNU_CPU=aarch64; DEB_BUILD_GNU_SYSTEM=linux-gnu; DEB_BUILD_GNU_TYPE=aarch64-linux-gnu; DEB_BUILD_MULTIARCH=aarch64-linux-gnu; DEB_HOST_ARCH=arm64; DEB_HOST_ARCH_ABI=ba
se; DEB_HOST_ARCH_BITS=64; DEB_HOST_ARCH_CPU=arm64; DEB_HOST_ARCH_ENDIAN=little; DEB_HOST_ARCH_LIBC=gnu; DEB_HOST_ARCH_OS=linux; DEB_HOST_GNU_CPU=aarch64; DEB_HOST_GNU_SYSTEM=li
nux-gnu; DEB_HOST_GNU_TYPE=aarch64-linux-gnu; DEB_HOST_MULTIARCH=aarch64-linux-gnu; DEB_TARGET_ARCH=arm64; DEB_TARGET_ARCH_ABI=base; DEB_TARGET_ARCH_BITS=64; DEB_TARGET_ARCH_CPU
=arm64; DEB_TARGET_ARCH_ENDIAN=little; DEB_TARGET_ARCH_LIBC=gnu; DEB_TARGET_ARCH_OS=linux; DEB_TARGET_GNU_CPU=aarch64; DEB_TARGET_GNU_SYSTEM=linux-gnu; DEB_TARGET_GNU_TYPE=aarch
64-linux-gnu; DEB_TARGET_MULTIARCH=aarch64-linux-gnu; export DEB_BUILD_ARCH DEB_BUILD_ARCH_ABI DEB_BUILD_ARCH_BITS DEB_BUILD_ARCH_CPU DEB_BUILD_ARCH_ENDIAN DEB_BUILD_ARCH_LIBC D
EB_BUILD_ARCH_OS DEB_BUILD_GNU_CPU DEB_BUILD_GNU_SYSTEM DEB_BUILD_GNU_TYPE DEB_BUILD_MULTIARCH DEB_HOST_ARCH DEB_HOST_ARCH_ABI DEB_HOST_ARCH_BITS DEB_HOST_ARCH_CPU DEB_HOST_ARCH
_ENDIAN DEB_HOST_ARCH_LIBC DEB_HOST_ARCH_OS DEB_HOST_GNU_CPU DEB_HOST_GNU_SYSTEM DEB_HOST_GNU_TYPE DEB_HOST_MULTIARCH DEB_TARGET_ARCH DEB_TARGET_ARCH_ABI DEB_TARGET_ARCH_BITS DE
B_TARGET_ARCH_CPU DEB_TARGET_ARCH_ENDIAN DEB_TARGET_ARCH_LIBC DEB_TARGET_ARCH_OS DEB_TARGET_GNU_CPU DEB_TARGET_GNU_SYSTEM DEB_TARGET_GNU_TYPE DEB_TARGET_MULTIARCH
導入パッケージ数(ヘッダ5行を除いて1303個)
$ dpkg-query -l|wc -l
1308
パッケージリスト(dpkg-query -l)

https://gist.github.com/6215f11e53ee668b04246ecd1d08f3db

ディスク利用量は3GB程
$ df -m
Filesystem     1M-blocks  Used Available Use% Mounted on
/dev/root          29938  2840     25832  10% /
devtmpfs             329     0       329   0% /dev
tmpfs                457     0       457   0% /dev/shm
tmpfs                457     1       457   1% /run
tmpfs                  5     1         5   1% /run/lock
tmpfs                457     0       457   0% /sys/fs/cgroup
/dev/mmcblk0p1       253    54       200  22% /boot
tmpfs                 92     0        92   0% /run/user/1000
有線/無線LAN認識
$ ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether b8:27:eb:46:60:13 brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.182/24 brd 192.168.1.255 scope global dynamic noprefixroute eth0
       valid_lft 258810sec preferred_lft 226410sec
    inet6 fe80::2979:45f7:e3bf:a4d9/64 scope link
       valid_lft forever preferred_lft forever
3: wlan0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN group default qlen 1000
    link/ether b8:27:eb:13:35:46 brd ff:ff:ff:ff:ff:ff
Bluetooth
$ bluetoothctl
Agent registered
[bluetooth]# list
Controller B8:27:EB:EC:CA:B9 raspberrypi [default]
[bluetooth]# quit
raspi-config等もある
Raspberry Pi 3 Model B Rev 1.2


┌─────────┤ Raspberry Pi Software Configuration Tool (raspi-config) ├──────────┐
│                                                                              │
│  1 Change User Password Change password for the 'pi' user                    │
│  2 Network Options      Configure network settings                           │
│  3 Boot Options         Configure options for start-up                       │
│  4 Localisation Options Set up language and regional settings to match your  │
│  5 Interfacing Options  Configure connections to peripherals                 │
│  6 Overclock            Configure overclocking for your Pi                   │
│  7 Advanced Options     Configure advanced settings                          │
│  8 Update               Update this tool to the latest version               │
│  9 About raspi-config   Information about this configuration tool            │
│                                                                              │
│                                                                              │
│                                                                              │
│                                                                              │
│                     <Select>                     <Finish>                    │
│                                                                              │
└──────────────────────────────────────────────────────────────────────────────┘
screenfetch(Raspbian logoじゃなくDebian logoになった)

RasPiOS screenfetch 20200530 23:05:27 2909997

pfetch
$ pfetch/pfetch
  _____      pi@raspberrypi
 /  __ \     os     Debian GNU/Linux 10 (buster)
|  /    |    host   Raspberry Pi 3 Model B Rev 1.2
|  \___-     kernel 5.4.42-v8+
-_           uptime 52m
  --_        pkgs   1313
             memory 203M / 913M

て感じで試し始めました.
しばらく使ってみようかと思います.

あ,余ったRaspberry Pi があったらください :p

もし問題が見つかったら以下を確認して報告すると直るかもしれません.

]]>
https://matoken.org/blog/2020/05/30/8gb-ram-version-of-raspberry-pi-model-b-launched-and-raspberry-pi-os/feed/ 0
Raspberry Pi公式のOS書き込みソフトウェアの Raspberry Pi Imager を少し試す https://matoken.org/blog/2020/03/08/try-raspberry-pi-imager-the-official-os-writing-software-for-raspberry-pi/ https://matoken.org/blog/2020/03/08/try-raspberry-pi-imager-the-official-os-writing-software-for-raspberry-pi/#comments Sun, 08 Mar 2020 14:37:48 +0000 http://matoken.org/blog/?p=2704

Instagram の動画がわかりやすいですね.
Raspberry Pi公式のOSイメージ書き込みソフトウェアです.少し試してみました.

導入

ダウンロードページにはWindows/macOSの他 Ubuntu amd64 向けの.debへのリンクしか無いのですが, https://downloads.raspberrypi.org/imager/ にアクセスすると AppImage と .sig がありました.
どちらも amd64 なので他のArchtectureじゃ使えないようです.Raspbianのarmhf版くらいは欲しいですね.

とりあえず Ubuntu 20.04 amd64 では .deb を,Debian sid amd64 では AppImage を試してみました.

debの場合

ダウンロードして署名検証して dpkg -i で導入したのですがpkgが足りなくてエラーが出力されました.足りないパッケージは apt install -f で導入しました.足りなかったパッケージは qml-module-qt-labs-settingslibdleyna-core-1.0-5 でした.(環境により変わるはず)

$ wget https://downloads.raspberrypi.org/imager/imager_amd64.deb https://downloads.raspberrypi.org/imager/imager_amd64.deb.sig
$ gpg --verify ./imager_amd64.deb.sig
gpg: assuming signed data in './imager_amd64.deb'
gpg: Signature made Fri Mar  6 20:49:08 2020 JST
gpg:                using RSA key 54C3DD610D9D1B4AF82A37758738CD6B956F460C
gpg: Good signature from "Raspberry Pi Downloads Signing Key" [unknown]
gpg: WARNING: This key is not certified with a trusted signature!
gpg:          There is no indication that the signature belongs to the owner.
Primary key fingerprint: 54C3 DD61 0D9D 1B4A F82A  3775 8738 CD6B 956F 460C
$ sudo dpkg -i ./imager_amd64.deb
$ sudo apt install -f
$ sudo rpi-imager
AppImage の場合

ダウンロードして署名検証して実行権を付けるだけです.

$ wget https://downloads.raspberrypi.org/imager/imager_amd64.AppImage https://downloads.raspberrypi.org/imager/imager_amd64.AppImage.sig
$ gpg --verify ./imager_amd64.AppImage.sig
gpg: assuming signed data in './imager_amd64.AppImage'
gpg: Signature made Fri 06 Mar 2020 10:34:08 PM JST
gpg:                using RSA key 54C3DD610D9D1B4AF82A37758738CD6B956F460C
gpg: Good signature from "Raspberry Pi Downloads Signing Key" [unknown]
gpg: WARNING: This key is not certified with a trusted signature!
gpg:          There is no indication that the signature belongs to the owner.
Primary key fingerprint: 54C3 DD61 0D9D 1B4A F82A  3775 8738 CD6B 956F 460C
$ chmod +x ./imager_amd64.AppImage
$ sudo ./imager_amd64.AppImage
余録).debを展開してとりあえず実行
$ ar x ./imager_amd64.deb
$ tar xf data.tar.xz
$ sudo ./usr/bin/rpi-imager

起動

root権が必要です.一般ユーザでも起動できるのですが,書き込み時にSD cardにアクセスできないエラーが出てしまいます.

20200308 15:03:05 1211621

OS list 取得エラー(一時的なサーバ側の問題)

現在サーバ側でSSLの問題があり大抵以下のようなエラーになります.9回に1回の割合で成功するらしいですが,私は30回ほど試してやっとうまく行きました.数日待てば治るそうなのでしばらく待ってから試す方がいいかもしれません.

20200307 17:03:40 265752

Caleb says:5th Mar 2020 at 3:32 pm
Currently giving me a “Error downloading OS list from Internet” when running it on a raspberry pi 4b

Avatar Gordon Hollingworth says:5th Mar 2020 at 5:05 pm
Yes, that’s because downloads.raspberrypi.org needs its SSL stuff updated. It should happen in the next few days!

Otherwise keep loading it, there’s a 1 in 9 chance you’ll get through to the server that does work!

Gordon

ちなみにOS listが取得できなくても自分でダウンロードしたイメージの書き込みやSD cardの消去は出来ます.

20200307 17:03:24 252063

Imagerの起動

起動するとこんな画面です.「CHOOSE OS」でOSイメージの選択(Raspbian各種とLibreELEC),ユーティリティ,消去,カスタムが選択できます.
「CHOOSE SD CARD」でSD cardやUSBメモリなどが選択できます.

20200307 17:03:12 251909

OSイメージの選択

20200308 15:03:20 1209635
20200308 15:03:02 1210096

SD card等の選択「CHOOSE SD CARD」

この画面を表示してからSD cardやUSBメモリ等を挿入するとリアルタイムに表示さるのでわかりやすいです.内蔵diskは出てきませんが,マウント中のHDDなどは出てくるので間違えないように注意しましょう.
選択できるストレージは1度に1つだけのようです.複数のメディアに書き込む場合は複数回の実行が必要です.

20200308 15:03:27 1210403

OSイメージ書き込み

「WRITE」ボタンを押すことで書き込みが開始されます.SecureEraseを試みてイメージ書き込み,ベリファイを行います.終わるまでしばらく待ちましょう.

20200308 15:03:57 1211527
20200308 15:03:30 1211923
20200308 15:03:30 1215554

自動ダウンロードしたイメージ

deb版の方は ~root/.cache/Raspberry Pi/Imager/lastdownload.cache として 最後に利用したものだけ が残るようです.なので同じイメージであれば2回目はダウンロードせずに済みます.
別のイメージを利用すると上書きされてそのイメージになります.

AppImage は /tmp/runtime-root 以下のようなので再起動したら消えてしまいますね.

QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to ‘/tmp/runtime-root’

rpi-imagerでLibreELEC RPi1を書き込んだ後出来たキャッシュファイルと LibreELEC からダウンロードしたファイルを比較
# sha256sum ./lastdownload.cache
80cd38e0a576f75caaecf511970ae563c5b605896074809643aecfdc91344bcf  ./lastdownload.cache
# wget http://releases.libreelec.tv/LibreELEC-RPi.arm-9.2.0.img.gz
# sha256sum LibreELEC-RPi.arm-9.2.0.img.gz
80cd38e0a576f75caaecf511970ae563c5b605896074809643aecfdc91344bcf  LibreELEC-RPi.arm-9.2.0.img.gz
# diff -as lastdownload.cache LibreELEC-RPi.arm-9.2.0.img.gz
Files lastdownload.cache and LibreELEC-RPi.arm-9.2.0.img.gz are identical

おわりに

てことで応用が聞かない感じなのでRaspberry Piを初めて使う人向けかなーと感じました.LibreELECなんかも同じようなツールを用意しているしOSイメージ書き込みで躓く人が多いのでツールが用意されているのかもしれないですね.
更に面倒だという人はOSイメージ入りのストレージを購入すると良さそうです.

個人的なおすすめは現在だとダウンロードは手動で書き込みには balenaEtcher がいいかなと思います.これもマルチプラットホーム対応で更に同時に複数のストレージに書き込みも可能です.

試した環境

deb版を試したUbuntu環境
$ dpkg-query -W rpi-imager qml-module-qt-labs-settings libdleyna-core-1.0-5
libdleyna-core-1.0-5:amd64
qml-module-qt-labs-settings:amd64       5.12.5-5
rpi-imager      1.0
$ lsb_release -dr
Description:    Ubuntu Focal Fossa (development branch)
Release:        20.04
$ uname -m
x86_64
AppImage版を試したDebian環境
$ lsb_release -dr
Description:    Debian GNU/Linux bullseye/sid
Release:        unstable
$ uname -m
x86_64
]]>
https://matoken.org/blog/2020/03/08/try-raspberry-pi-imager-the-official-os-writing-software-for-raspberry-pi/feed/ 1
Raspberry Pi が起動しなくて困る(未解決・microSD不良?) https://matoken.org/blog/2019/11/18/raspberry-pi-wont-start-up-unresolved-microsd-defective/ https://matoken.org/blog/2019/11/18/raspberry-pi-wont-start-up-unresolved-microsd-defective/#respond Mon, 18 Nov 2019 05:59:36 +0000 http://matoken.org/blog/?p=2667

先日AmazonでmicroSD cardを購入しました.Samsung ドライブレコーダー向け microSDカード32GB 正規代理店保証品 MB-MJ32GA/ECというものです.

これにRaspberry Pi向けのイメージを書き込んで起動しようとすると,RaspberryPiでLEDがピカッピカー.って感じで2回光って消えます.そしてSerialには以下のメッセージが表示され起動しません.

Error: invalid dtb and unrecognized/unsupported machine ID
  r1=0x00000c42, r2=0x00000000
Available machine support:

ID (hex)        NAME
ffffffff        Generic DT based system
ffffffff        BCM2835
Please check your kernel config and/or bootloader.

はじめに試したイメージは自作のものだったのでそのせいかと思ったのですが,Raspbian Buster Lite 2019-09-26 でも同様の動きになります.
ボード側をRaspberry Pi Zero/ZeroW/A+と試しましたがどれでも同じ動作です.

でもmicroSDを交換すると起動します.microSDが怪しそうです.
f3で速度や容量を確認してみました.

容量は問題無さそうなのですが,

最大読み出し速度100MB/s、最大書き込み速度30MB/s

とのことですが実際は読み込み20MB/s前後,書き込み速度は10MB/s前後くらいなので遅すぎる感じがします.
ということでmicroSDが怪しいのでとりあえず返品しようかと思います…….

]]>
https://matoken.org/blog/2019/11/18/raspberry-pi-wont-start-up-unresolved-microsd-defective/feed/ 0
Raspberry Piのraspistilコマンドでジオタグ埋め込みを試すとエラーになる https://matoken.org/blog/2019/11/14/error-when-trying-to-embed-geotags-with-raspberry-pis-raspistil-command/ https://matoken.org/blog/2019/11/14/error-when-trying-to-embed-geotags-with-raspberry-pis-raspistil-command/#respond Thu, 14 Nov 2019 06:15:03 +0000 http://matoken.org/blog/?p=2642

Raspberry Pi の専用コマンドの中に raspistil コマンドというものがあります.
(Raspbianの libraspberrypi-bin パッケージ内にあります.)

このコマンドで専用カメラでの撮影が出来ます.
インターバル撮影してMapillaryにアップロードしてマッピングの足しに出来ないかなと少し試してみました.

何時もは撮影した画像に別撮りしたGPSデータを埋め込むのですが,raspistillのオプションを確認すると最近はgpsdから位置情報見て埋め込むオプションがあって便利そうです.

しかし,その -gps オプションを利用するとエラーになります.

$ raspistill -gps -o test2.jpg
libgps.so.22: cannot open shared object file: No such file or directory
Unable to load the libGPS library

とりあえずリンク張ったら動きました.

$ sudo ln -s /usr/lib/arm-linux-gnueabihf/libgps.so.23.0.0 /usr/lib/arm-linux-gnueabihf/libgps.so.22

add)
バグ報告したらすぐ修正されました.しばらくしたら反映されるでしょう :)

しかしexifを確認しても位置情報は埋め込まれていません.室内でGPS弱いのでまた後で屋外で試してみます.

しかし,8MPのimx219ではピントが無限遠ではなく近くに設定されているようでそのままではちょっとダメそう.そして画角はもっと広角なのが欲しいです.

raspistil01
raspistil02

ピントの方は以下のページを参考に少し調整してみるとこんな感じに.もう少し行けそうだけど壊しそうで怖い.

raspistil03

画角も狭いしこういうものを買うと良さそう.誰か買って試してみてください.(そして飽きたら安く譲って😏)

環境(Raspbian Buster Lite 2019-09-26を2019-11-12にapt update && apt upgradeした環境)
$ dpkg-query -W gpsd libgps23 libraspberrypi-bin
gpsd 3.17-7
libgps23:armhf 3.17-7
libraspberrypi-bin 1.20190925+1-1
$ lsb_release -dr
Description: Raspbian GNU/Linux 10 (buster)
Release: 10
$ uname -a
Linux raspberrypi 4.19.75+ #1270 Tue Sep 24 18:38:54 BST 2019 armv6l GNU/Linux
$ cat /proc/device-tree/model ;echo
Raspberry Pi Model B Plus Rev 1.2
]]>
https://matoken.org/blog/2019/11/14/error-when-trying-to-embed-geotags-with-raspberry-pis-raspistil-command/feed/ 0
Raspbian Buster 2019-09-26 https://matoken.org/blog/2019/10/01/raspbian-buster-2019-09-26/ https://matoken.org/blog/2019/10/01/raspbian-buster-2019-09-26/#respond Tue, 01 Oct 2019 03:06:53 +0000 http://matoken.org/blog/?p=2521

リリースされていました.

2019-09-26:
* rpi-eeprom included
  - This will automatically update the SPI EEPROM on the Raspberry Pi 4 to the latest stable version.
     See https://rpf.io/eeprom for more information.
* New icon theme for file manager icons
* Appearance Settings - option for identical desktop on both monitors
* Appearance Settings - option to show different desktop icons on both monitors
* Taskbar automatically moved to monitor 0 if monitor 1 not found at boot
* Switching of audio output between two HDMI devices added to volume plugin
* Switching of audio input devices added to volume plugin
* .asoundrc (ALSA config file) now uses 'plug' values to support more devices
* Audio Settings tool modified to integrate more closely with volume plugin to reduce duplicated code
* Screen Configuration tool now shows separate menus for resolution and refresh rate
* Primary and active monitor settings removed from Screen Configuration tool
* Overscan support added for FKMS driver
* New keyboard shortcuts added - Ctrl-Alt-End brings up shutdown menu; Ctrl-Alt-M moves taskbar between monitors
* Latest changes to Bluez ALSA interface integrated to improve connection to Bluetooth audio devices
* Mousepad used as simple text editor instead of leafpad
* Version 3.2 of Thonny added
* Version 74 of Chromium added
* Version 3.0.8 of VLC added
* Version 32.0.0.255 of Flash player added
* Version 6.5.0 of RealVNC Server added
* Version 6.19.715 of RealVNC Viewer added (full image only)
* Version 12.0.1 of Mathematica added (full image only)
* Version 0.20.8 of NodeRED added (full image only)
* Version 3.1.0 of Sonic Pi added (full image only)
* Scratch 3 added (full image only)
* Bug fix - URL handling in Terminal
* Bug fix - octal values in SSIDs in network plugin
* Bug fix - remaining value in progress bar when transferring files
* Bug fix - integration of xarchiver tool with file manager
* Bug fix - start menu opening on incorrect monitor
* Bug fix - minimised applications wrongly displayed on taskbar on second monitor
* Bug fix - Bluetooth icon disappearing on x86 platforms when Bluetooth turned off
* Bug fix - Screen Configuration tool not shown on x86 platforms and settings not being saved
* Various translation updates
* Various minor bug fixes
* Epiphany/Web removed
* ntfs-3g included
* pciutils added
* Linux kernel 4.19.75
* Raspberry Pi firmware 01508e81ec1e918448227ca864616d56c430b46d

このショートカットが便利かも?

  • New keyboard shortcuts added – Ctrl-Alt-End brings up shutdown menu; Ctrl-Alt-M moves taskbar between monitors

とりあえず,liteだけダウンロードキューに入れておきました.

$ wget https://downloads.raspberrypi.org/raspbian_lite/images/raspbian_lite-2019-09-30/2019-09-26-raspbian-buster-lite.zip.torrent \
  https://downloads.raspberrypi.org/raspbian_lite/images/raspbian_lite-2019-09-30/2019-09-26-raspbian-buster-lite.zip.sig
$ transmission-cli 2019-09-26-raspbian-buster-lite.zip.torrent

ADD: その後ダウンロードが終わったのでverify

$ gpg --verify ./2019-09-26-raspbian-buster-lite.zip.sig
gpg: assuming signed data in './2019-09-26-raspbian-buster-lite.zip'
gpg: Signature made Mon 30 Sep 2019 09:43:50 PM JST
gpg:                using RSA key 54C3DD610D9D1B4AF82A37758738CD6B956F460C
gpg: Good signature from "Raspberry Pi Downloads Signing Key" [unknown]
gpg: WARNING: This key is not certified with a trusted signature!
gpg:          There is no indication that the signature belongs to the owner.
Primary key fingerprint: 54C3 DD61 0D9D 1B4A F82A  3775 8738 CD6B 956F 460C

#Raspberry Pi 4 model B も先週あたりに工事設計認証が総務省のリストに載ったようだし日本発売も間近?(所謂技適問題)
##電源バグも修正してくれると嬉しい

]]>
https://matoken.org/blog/2019/10/01/raspbian-buster-2019-09-26/feed/ 0
特定グループでのみ dmesg command を有効にする https://matoken.org/blog/2019/03/03/enable-dmesg-command-only-for-certain-groups/ https://matoken.org/blog/2019/03/03/enable-dmesg-command-only-for-certain-groups/#comments Sun, 03 Mar 2019 13:43:09 +0000 http://matoken.org/blog/?p=2304 Debian の linux 4.8.0 以降で一般ユーザによる dmesg が無効化されたので,kernelパラメータの kernel.dmesg_restrict を修正して dmesg command を一般ユーザでも実行できるようにしましたがこれだと全ユーザで実行できてしまいます.sudo を設定してログの読める adm ユーザだけが dmesg command を実行できるようにしてみました.

dmesgを実行したいユーザをadm group に登録する(loginし直して反映しておく)

$ sudo addgroup matoken adm
$ exit

visudo command で /etc/sudoers を編集して adm group は NOPASSWD で dmesg command を実行できるようにする(念の為編集前にもう1枚端末を開いて sudo -s しておいたり,at等で5分後に /etc/sudoers を巻き戻すようにしておくとミスっても安心)

$ sudo visudo
$ sudo git diff /etc/sudoers
diff --git a/sudoers b/sudoers
index d4cc632..ac3bd77 100644
--- a/sudoers
+++ b/sudoers
@@ -21,6 +21,7 @@ root  ALL=(ALL:ALL) ALL

 # Allow members of group sudo to execute any command
 %sudo  ALL=(ALL:ALL) ALL
+%adm   ALL=NOPASSWD: /usr/bin/dmesg

 # See sudoers(5) for more information on "#include" directives:

adm group のユーザでdmesg コマンドが追加されているのを確認

$ sudo -l | grep dmesg
    (root) NOPASSWD: /usr/bin/dmesg

adm group のユーザが認証無しで sudo dmesg が実行できるのを確認

$ id | grep -o adm
adm
$ sudo dmesg -H | tail -1
[  +0.015080] smsc95xx 1-1.1:1.0 eth0: link up, 100Mbps, full-duplex, lpa 0xCDE1

このとき kernel.dmesg_restrict = 1 で sudo を通さないと dmesg は実行できない

$ cat /proc/sys/kernel/dmesg_restrict
1
$ dmesg 
dmesg: read kernel buffer failed: Operation not permitted
$ LC_MESSAGES=ja_JP.UTF-8 dmesg 
dmesg: read kernel buffer failed: 許可されていない操作です

~/.profile にalias を設定

$ echo 'alias dmesg="sudo dmesg"' | tee -a ~/.profile                                                                                                                                   
alias dmesg="sudo dmesg"
$ source ~/.profile
$ dmesg -H | tail -1
[  +0.015080] smsc95xx 1-1.1:1.0 eth0: link up, 100Mbps, full-duplex, lpa 0xCDE1

環境

$ dpkg-query -W sudo util-linux linux-image-*
linux-image-4.19.0-2-arm64      4.19.16-1
linux-image-4.19.0-2-arm64-unsigned
linux-image-arm64       4.19+102
sudo    1.8.27-1
util-linux      2.33.1-0.1
$ lsb_release -dr
Description:    Debian GNU/Linux buster/sid
Release:        testing
$ uname -a
Linux rpi3 4.19.0-2-arm64 #1 SMP Debian 4.19.16-1 (2019-01-17) aarch64 GNU/Linux
$ cat /proc/device-tree/model ;echo
Raspberry Pi 3 Model B Rev 1.2

]]>
https://matoken.org/blog/2019/03/03/enable-dmesg-command-only-for-certain-groups/feed/ 1
Debian buster/sid でdmesgを一般ユーザで実行 https://matoken.org/blog/2019/03/03/run-dmesg-as-a-general-user-with-debian-buster-sid/ https://matoken.org/blog/2019/03/03/run-dmesg-as-a-general-user-with-debian-buster-sid/#comments Sun, 03 Mar 2019 13:07:56 +0000 http://matoken.org/blog/?p=2302 ※この方法だと全ユーザで dmesg が実行できてしまうので sudo を使ってグループを制限する次の方法のほうがいいかもしれない.


Debian buster arm64 環境を作りました( Raspberry Pi 3 Model B の USB起動で Debian buster arm64 を動かす – matoken’s meme )が,dmesg でエラーとなります.sudo dmesg は動く.

$ dmesg 
dmesg: read kernel buffer failed: Operation not permitted
$ LC_MESSAGES=ja_JP.UTF-8 dmesg 
dmesg: read kernel buffer failed: 許可されていない操作です

そういえば以前 Debian sid amd64 でも起こった現象です.
Debian では Linux 4.8.0 から仕様が変わってroot 以外ではdmesg が読めないようになっています.log file の読める adm group のユーザも駄目.
これは kernelパラメータの kernel.dmesg_restrict で設定されていて以下のようなコマンドで確認できます.

$ sudo sysctl -a|grep dmesg
kernel.dmesg_restrict = 1
$ cat /proc/sys/kernel/dmesg_restrict
1

これを 1 から 0 に変更することで以前と同じ動作となります.sysctl コマンドや,

$ sudo sysctl -w kernel.dmesg_restrict=0

/proc/sys/kernel/dmesg_restrict を直接書き換えることで一時的に変更できます.

echo 0 | sudo tee /proc/sys/kernel/dmesg_restrict

動きました.

$ id | grep -o adm
$ echo hello | sudo tee /dev/kmsg 
hello
[  562.152729] hello
$ dmesg -H | tail
[  +0.019933] brcmfmac mmc1:0001:1: firmware: failed to load brcm/brcmfmac43430-sdio.clm_blob (-2)
[  +0.020182] firmware_class: See https://wiki.debian.org/Firmware for information about missing firmware
[  +0.020886] brcmfmac mmc1:0001:1: Direct firmware load for brcm/brcmfmac43430-sdio.clm_blob failed with error -2
[  +0.021916] brcmfmac: brcmf_c_process_clm_blob: no clm_blob available (err=-2), device may have limited channels available
[  +0.026818] brcmfmac: brcmf_c_preinit_dcmds: Firmware: BCM43430/1 wl0: Oct 23 2017 03:55:53 version 7.45.98.38 (r674442 CY) FWID 01-e58d219f
[  +0.077925] systemd-udevd[376]: link_config: autonegotiation is unset or enabled, the speed and duplex are not writable.
[  +0.537137] EXT4-fs (sda2): re-mounted. Opts: (null)
[  +2.001639] smsc95xx 1-1.1:1.0 eth0: hardware isn't capable of remote wakeup
[  +1.563625] smsc95xx 1-1.1:1.0 eth0: link up, 100Mbps, full-duplex, lpa 0xCDE1
[Mar 2 05:58] hello

再起動すると元に戻ってしまうので,/etc/sysctl.d/local.conf などに設定を書いてくと次回起動時以降も反映されます.

$ sudo install -m 644 -o root -g root /dev/null /etc/sysctl.d/local.conf
$ echo 'kernel.dmesg_restrict = 0' | sudo tee -a /etc/sysctl.d/local.conf
kernel.dmesg_restrict = 0

試した環境

$ dmesg --version
dmesg from util-linux 2.33.1
$ dpkg-query -W util-linux linux-image-*
linux-image-4.19.0-2-arm64      4.19.16-1
linux-image-4.19.0-2-arm64-unsigned
linux-image-arm64       4.19+102
util-linux      2.33.1-0.1
$ lsb_release -dr
Description:    Debian GNU/Linux buster/sid
Release:        testing
$ uname -a
Linux rpi3 4.19.0-2-arm64 #1 SMP Debian 4.19.16-1 (2019-01-17) aarch64 GNU/Linux
$ cat /proc/device-tree/model ;echo
Raspberry Pi 3 Model B Rev 1.2

]]>
https://matoken.org/blog/2019/03/03/run-dmesg-as-a-general-user-with-debian-buster-sid/feed/ 1
Raspberry Pi 3 Model B の USB起動で Debian buster arm64 を動かす https://matoken.org/blog/2019/03/01/launch-debian-buster-arm-64-with-raspberry-pi-3-model-b-usb-boot/ https://matoken.org/blog/2019/03/01/launch-debian-buster-arm-64-with-raspberry-pi-3-model-b-usb-boot/#comments Thu, 28 Feb 2019 21:41:13 +0000 http://matoken.org/blog/?p=2295 最近入手した(遅) RaspberryPi 3 model B で USB メモリ起動の Debian buster aarch64 を設定してみたときのメモです.

ジモティー経由で Raspberry Pi 3 model B を入手しました.Raspberry Pi 3 model B + USB Wi-Fi + USB Bluetooth + ケースのセットが2,500円 + 送料手数料 500円と安いです.普通に新品で買うと 8,000円近くすると思います.今この記事を書いている時点で未だ在庫はあるようなので興味のある人は買うといいかもしれません.(6個同梱可能なのでそれだと1個あたりが少し安くなるので近所の友達と買うといいかも)

IMG-20190208-184136IMG-20190208-185154IMG-20190208-185222IMG-20190213-212056

64bitになった Raspberry Pi は欲しいと思っていたので安く手に入って助かりました :)
(後継の Raspberry Pi 3 Model B+/A+ や,SoCが 3B と同じで無線機能のない 2B v1.2 とかも欲しいですね.)

Raspberry Pi 3 model B は 32bitだけでなく64bit も利用できるハードウェアです.せっかくなので 64bitで動かしたいけど今の時点では Raspbian は 32bitのみです.そこで Debian の arm64 を試すことにしました.

Raspberry Pi 3 用 Debian buster arm64 イメージの入手とUSBメモリへの書き込み

イメージは岩松さんの東京エリアDebian勉強会の資料を真似して作ろうと思っていたのですが,

DebianWiki の RaspberryPi3 の項目を見たら非公式だけどイメージがあったので今回はそれを利用しました.現在 testing の Buster のイメージが入手できます.

ストレージは通常 microSD を利用しますが,手持ちがないのと Raspberry Pi 3 B はUSB起動が可能なはずなのでUSBメモリを利用することにしました.USB 2.0接続の容量2GBのものを用意しました.

このような感じでイメージを入手してハッシュのチェックをした後USBメモリへ書き込みました.ここでは Linuxのddコマンドで書き込んでいますが,Etcherなどを利用すると色々な環境でGUIでの書き込みが可能です.
※イメージは最新のものを利用するようにしましょう.

$ wget -c https://people.debian.org/~gwolf/raspberrypi3/20190206/20190206-raspberry-pi-3-buster-PREVIEW.img.xz https://people.debian.org/~gwolf/raspberrypi3/20190206/20190206-raspberry-pi-3-buster-PREVIEW.img.xz.sha256
$ sha256sum -c ./20190206-raspberry-pi-3-buster-PREVIEW.img.xz.sha256
20190206-raspberry-pi-3-buster-PREVIEW.img.xz: 完了
$ xzcat 20190206-raspberry-pi-3-buster-PREVIEW.img.xz | pv | sudo dd of=/dev/sdb bs=1M oflag=dsync

USBから起動できるようOTPを設定する

注意:OTPの設定は1度しか出来ないし,元に戻すことも出来ないと思われます.起動時間が長くなるなどデメリットもあるので気をつけて設定してください.

このUSBメモリを Raspberry Pi に接続して電源を入れてみましたが起動しません.恐らく OTP(One Time Programmable)メモリの設定が USB起動に対応していないので以下のページを参考に設定します.(Raspberry Pi 3+ シリーズは標準でUSB起動可能なのでこの設定は不要なはずです.)

先ず Raspbian 2017-04-10 以降のイメージを書き込んだ microSD を用意して起動します.
( uart経由で繋ぎたい場合起動前に /boot/config.txt に enable_uart=1 を書いておきます. $ echo enable_uart=1 | tee -a /media/matoken/boot/config.txt )

OTP を確認するとやはり有効になっていませんでした.

pi@raspberrypi:~$ vcgencmd otp_dump | grep ^17:
17:1020000a

以下のように /boot/config.txtprogram_usb_boot_mode=1 を追記して再起動すると反映されます.

$ echo program_usb_boot_mode=1 | sudo tee -a /boot/config.txt
program_usb_boot_mode=1
pi@raspberrypi:~$ sudo reboot

17 が 3020000a に変わればOK

pi@raspberrypi:~$ vcgencmd otp_dump | grep ^17:
17:3020000a

詳細は以下を参照してください

17 – bootmode register

Bit 1: sets the oscillator frequency to 19.2MHz
Bit 3: enables pull ups on the SDIO pins
Bit 19: enables GPIO bootmode
Bit 20: sets the bank to check for GPIO bootmode
Bit 21: enables booting from SD card
Bit 22: sets the bank to boot from
Bit 28: enables USB device booting
Bit 29: enables USB host booting (ethernet and mass storage)

設定前が,1020000a -> 0b010000001000000000000000001010 で設定後が,0x3020000a -> 0b110000001000000000000000001010 てことで,Bit 29 が 0 から 1 になってネットワーク起動とUSB起動を試すようにります.この状態で microSD 起動を試すとこれも大丈夫でした.(優先度は microSD > USB,Networkは未確認)

USBメモリからの起動

この状態で shutdown し,microSD を取り出して Debian の導入した USB メモリを接続して起動で起動しました.(USB起動の場合なかなか起動が始まらず焦ったけど30秒ほど待つとUARTにログが出はじめる.HDMIの出力は未確認)

login は root:raspberry
ちゃんと 64bit です :)

root@rpi3:~# uname -a
Linux rpi3 4.19.0-2-arm64 #1 SMP Debian 4.19.16-1 (2019-01-17) aarch64 GNU/Linux

細々とした設定(ほぼ余録)

パッケージの更新

root@rpi3:~# apt update && apt upgrade

一般ユーザの追加

root@rpi3:~# useradd -m matoken
root@rpi3:~# passwd matoken
Enter new UNIX password: 
Retype new UNIX password: 
passwd: password updated successfully
root@rpi3:~# chsh matoken -s /bin/bash

OpenSSH の設定変更

root@rpi3:~# diff -u /etc/ssh/sshd_config.old /etc/ssh/sshd_config
--- /etc/ssh/sshd_config.old    2019-02-06 15:15:46.940904823 +0000
+++ /etc/ssh/sshd_config        2019-02-16 13:17:17.076873278 +0000
@@ -29,7 +29,7 @@
 # Authentication:

 #LoginGraceTime 2m
-PermitRootLogin yes
+PermitRootLogin prohibit-password
 #StrictModes yes
 #MaxAuthTries 6
 #MaxSessions 10
@@ -53,7 +53,7 @@
 #IgnoreRhosts yes

 # To disable tunneled clear text passwords, change to no here!
-#PasswordAuthentication yes
+PasswordAuthentication no
 #PermitEmptyPasswords no

 # Change to yes to enable challenge-response passwords (beware issues with
@@ -119,3 +119,5 @@
 #      AllowTcpForwarding no
 #      PermitTTY no
 #      ForceCommand cvs server
+
+AllowGroups sshusers

sshusers グループを作成して ssh login 出来るユーザを登録

root@rpi3:~# sudo groupadd sshusers
root@rpi3:~# sudo usermod -a -G sshusers matoken

短いmodulus を削除する

root@rpi3:~# awk '$5>=3071' /etc/ssh/moduli | tee /etc/ssh/moduli.tmp
root@rpi3:~# wc -l /etc/ssh/moduli /etc/ssh/moduli.tmp
    427 /etc/ssh/moduli
    368 /etc/ssh/moduli.tmp
    795 total
root@rpi3:~# sudo mv /etc/ssh/moduli.tmp /etc/ssh/moduli

hostpcからssh公開鍵をcpしておく

$ ssh-copy-id -i ~/.ssh/id_ed25519_pi.pub matoken@rpi3

ssh鍵ペアを作っておく

root@rpi3:~# sudo -u matoken ssh-keygen -t ed25519

sshd の再起動

root@rpi3:~# systemctl restart ssh

ssh login時に通知を飛ばすようにしておく

root@rpi3:~# vi /etc/ssh/sshrc
root@rpi3:~# chmod +x /etc/ssh/sshrc
root@rpi3:~# cat /etc/ssh/sshrc
#!/bin/sh

/home/matoken/bin/telegram.sh sshrc:${USER}@`hostname`:${SSH_CONNECTION}
/home/matoken/bin/sms.sh sshrc:${USER}@`hostname`:${SSH_CONNECTION}

ssh でパスワードログインできず,鍵認証でログインが出来る&通知が飛ぶのを確認

root@rpi3:~# ssh root@localhost -o PasswordAuthentication=yes
root@rpi3:~# ssh matoken@localhost -o PasswordAuthentication=yes
root@rpi3:~# ssh matoken@localhost -i ~/.ssh/id_ed25519

自分のネットワークに合わせて /etc/iptables/rules.v4, /etc/iptables/rules.v6 を変更.

root@rpi3:~# grep -v ^# /etc/iptables/rules.v4
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -s 127.0.0.0/8 -m comment --comment "RFC3330 loopback" -j ACCEPT
-A INPUT -s 192.168.1.0/24 -m comment --comment "RFC1918 reserved" -j ACCEPT
-A INPUT -p tcp -m tcp --dport 22 -m comment --comment SSH -j REJECT --reject-with icmp-port-unreachable
COMMIT
root@rpi3:~# grep -v ^# /etc/iptables/rules.v6
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -s ::1/128 -m comment --comment "RFC3513 loopback" -j ACCEPT
-A INPUT -p tcp -m tcp --dport 22 -m comment --comment SSH -j REJECT --reject-with icmp6-port-unreachable
COMMIT

sudo を導入して設定

root@rpi3:~# apt install sudo

sudo groupにユーザを登録

root@rpi3:~# usermod -a -G sudo matoken

sudo が利用できるのを確認

matoken@rpi3:~$ sudo grep ^root: /etc/shadow
sudo: unable to resolve host rpi3: Name or service not known
root:!..VyaTFxP8kT6:17933:0:99999:7:::

rootユーザをロック

$ sudo passwd -l root 
sudo: unable to resolve host rpi3: Name or service not known
passwd: password expiry information changed.
matoken@rpi3:~$ sudo passwd -S root
sudo: unable to resolve host rpi3: Name or service not known
root L 02/06/2019 0 99999 7 -1

sudo時などに「sudo: unable to resolve host rpi3: Name or service not known」と言われるので hosts の localhost に rpi3 を追加

matoken@rpi3:~$ sudo vi /etc/hosts
127.0.0.1 localhost rpi3

ここで再起動すると rootfs が見つからないと言われ起動しない.

(initramfs) Gave up waiting for root file system device. Common problems:
- Boot args (cat /proc/cmdline)
- Check rootdelay= (did the system wait long enough?)
- Missing modules (cat /proc/modules; ls /dev)
ALERT! /dev/mmcblk0p2 does not exist. Dropping to a shell!


BusyBox v1.27.2 (Debian 1:1.27.2-3) built-in shell (ash)
Enter 'help' for a list of built-in commands.

cmdline では /dev/mmcblkp2 から起動しようとしているが, /dev/sda2 から起動したい

(initramfs) ls /dev
block tty12 tty47
bsg tty13 tty48
bus tty14 tty49
char tty15 tty5
console tty16 tty50
core tty17 tty51
cpu_dma_latency tty18 tty52
disk tty19 tty53
fb0 tty2 tty54
fd tty20 tty55
full tty21 tty56
gpiochip0 tty22 tty57
gpiochip1 tty23 tty58
input tty24 tty59
kmsg tty25 tty6
kvm tty26 tty60
mem tty27 tty61
memory_bandwidth tty28 tty62
network_latency tty29 tty63
network_throughput tty3 tty7
null tty30 tty8
port tty31 tty9
psaux tty32 ttyAMA0
ptmx tty33 ttyS0
pts tty34 ttyS1
random tty35 ttyS2
sda tty36 ttyS3
sda1 tty37 urandom
sda2 tty38 vcs
snapshot tty39 vcs1
stderr tty4 vcsa
stdin tty40 vcsa1
stdout tty41 vcsu
tty tty42 vcsu1
tty0 tty43 vga_arbiter
tty1 tty44 zero
tty10 tty45
tty11 tty46
(initramfs) cat /proc/cmdline
bcm2708_fb.fbwidth=656 bcm2708_fb.fbheight=416 bcm2708_fb.fbswap=1 dma.dmachans=0x7f35 bcm2709.boardrev=0xa02082 bcm2709.serial=0xfaf144 bcm2709.uart_clock=48000000 smsc95xx.macaddr=B8:27:EB:FA:F1:44 vc_mem.mem_base=0x3ec00000 vc_mem.mem_size=0x40000000 console=tty0 console=ttyS1,115200 root=/dev/mmcblk0p2 rw elevator=deadline fsck.repair=yes net.ifnames=0 cma=64M rootwait

/boot を mount して書き換えようと思ったけどうまく mount 出来ない?

(initramfs) mkdir /tmp/boot
(initramfs) mount /dev/sda1 /tmp/boot
mount: mounting /dev/sda1 on /tmp/boot failed: Invalid argument
(initramfs) ls -la /dev/sda1 /tmp/boot
brw-------    1 0        0           8,   1 Jan  1 00:00 /dev/sda1

/tmp/boot:
total 0
drwxr-xr-x    2 0        0                0 Jan  1 00:10 .
drwxr-xr-x    3 0        0                0 Jan  1 00:10 ..
(initramfs) mount -t vfat /dev/sda1 /tmp/boot
mount: mounting /dev/sda1 on /tmp/boot failed: No such device
(initramfs) mkdir /tmp/root
(initramfs) modprobe ext4
(initramfs) mount /dev/sda2 /tmp/root
[ 2144.515323] EXT4-fs (sda2): mounted filesystem with ordered data mode. Opts: (null)
(initramfs) find /tmp/root -name "vfat.ko"
/tmp/root/usr/lib/modules/4.19.0-2-arm64/kernel/fs/fat/vfat.ko
(initramfs) modprobe -v /tmp/root/usr/lib/modules/4.19.0-2-arm64/kernel/fs/fat/vfat.ko
(initramfs) lsmod|grep fat
(initramfs) mount -t vfat /dev/sda1 /tmp/boot
mount: mounting /dev/sda1 on /tmp/boot failed: No such device
(initramfs) lsmod|grep fat

一旦電源を切って /boot/cmdline.txt の root=/dev/mmcblk0p2 を root=/dev/sda2 に書き換えて起動するようになった.(LABEL指定に変えたほうがいいかな)

$ cat /boot/firmware/cmdline.txt 
console=tty0 console=ttyS1,115200 root=/dev/sda2 rw elevator=deadline fsck.repair=yes net.ifnames=0 cma=64M rootwait

raspi3-firmware あたりのアップデートが掛かると上書きされるよう.

systemd から sysvinit に変更(RAMが開くかと思ったけど数MB程度だった)

$ sudo apt install sysvinit-core sysvinit-utils

LANGを設定
en_US.UTF-8 UTF-8, ja_JP.UTF-8 UTF-8 を有効にして,デフォルトロケールを ja_JP.UTF-8 にしたりした.

$ sudo dpkg-reconfigure locales
$ echo 'export LANG="ja_JP.UTF-8"
export LC_TIME="en_US.UTF-8"' | tee -a ~/.profile
$ source ~/.profile
$ locale
LANG=ja_JP.UTF-8
LANGUAGE=
LC_CTYPE="ja_JP.UTF-8"
LC_NUMERIC="ja_JP.UTF-8"
LC_TIME=en_US.UTF-8
LC_COLLATE="ja_JP.UTF-8"
LC_MONETARY="ja_JP.UTF-8"
LC_MESSAGES="ja_JP.UTF-8"
LC_PAPER="ja_JP.UTF-8"
LC_NAME="ja_JP.UTF-8"
LC_ADDRESS="ja_JP.UTF-8"
LC_TELEPHONE="ja_JP.UTF-8"
LC_MEASUREMENT="ja_JP.UTF-8"
LC_IDENTIFICATION="ja_JP.UTF-8"
LC_ALL=

Raspberry Pi には rtc がなくて再起動などで時計が初期化されてしまうので fake-hwclock を導入(電源断時などの時間はカウントされないので時間がずれるが時計が巻き戻らない)

$ sudo apt install fake-hwclock

ntpdate を導入して起動時の時計合わせをするようにする(systemdのままだとntpの面倒を見てくれるので必要ない)

$ sudo apt install ntpdate
$ sudo vi /etc/boot.d/ntpdate
$ cat /etc/boot.d/ntpdate
#!/bin/sh

ntpdate 1.jp.pool.ntp.org
$ sudo chmod +x /etc/boot.d/ntpdate

ntpdate iptables に合わせてこっちのほうがいいかも?(有線接続後に時計合わせする)

$ cat /etc/network/interfaces.d/eth0 
auto eth0

# TODO: switch back to iptables-persistent once it re-enters testing
iface eth0 inet dhcp
        pre-up iptables-restore < /etc/iptables/rules.v4
        pre-up ip6tables-restore < /etc/iptables/rules.v6
        up ntpdate 1.jp.pool.ntp.org

uartでsetial接続するために /etc/inittab に以下を設定(systemdだと設定済みなので不要)

T1:23:respawn:/sbin/getty -L ttyS1 115200 vt100

msmtpを導入してメールを飛ばせるように

$ sudo apt install msmtp
$ sudo vi /etc/msmtprc
$ grep -v ^# /etc/msmtprc|uniq
defaults
syslog on
aliases /etc/aliases

tls on
tls_trust_file /etc/ssl/certs/ca-certificates.crt
auth on
syslog LOG_MAIL

account gmail
host smtp.gmail.com
port 587
from matohara@gmail.com
user matohara
password throjfeekdewxeib

account default : gmail
$ sudo vi /etc/aliases
$ grep -v ^# /etc/aliases
mailer-daemon:hoge@example.com
postmaster:hoge@example.com
nobody:hoge@example.com
hostmaster:hoge@example.com
usenet:hoge@example.com
news:hoge@example.com
webmaster:hoge@example.com
www:hoge@example.com
ftp:hoge@example.com
abuse:hoge@example.com
noc:hoge@example.com
security:hoge@example.com
root: hoge@example.com
default: hoge@example.com
$ echo 'hello' | msmtp matoken@ya.ru
$ sudo apt install msmtp-mta
$ echo 'hello' | /usr/sbin/sendmail matoken@ya.ru

無線を無効にするために /boot/firmware/config.txt に以下を追記……再起動しても反映されない?要確認

dtoverlay=pi3-disable-wifi
dtoverlay=pi3-disable-bt

apticron を導入して更新をメールで通知する

$ sudo apt install apticron
$ sudo cp -p /usr/lib/apticron/apticron.conf /etc/apticron/
$ grep ^EMAIL= /etc/apticron/apticron.conf #必要なら宛先を書き換えたり
EMAIL="root"

deborphan でみなしごパッケージを通知するようにする

$ sudo apt install deborphan
$ sudo crontab -e
$ sudo crontab -l | grep deborphan | grep -v ^#
7 4 * * *       deborphan && printf "\nsudo apt --autoremove purge \$( deborpha)'

てことでとりあえず動くようになったけど昔もらったノベルティのUSBメモリなのでこのまま運用すると多分すぐ壊れてしまうと思います.
最近秋葉原でセールになっている様な安い SSD とか欲しいですね.

こちらは起動終了のUARTのメッセージ

asciicast

]]>
https://matoken.org/blog/2019/03/01/launch-debian-buster-arm-64-with-raspberry-pi-3-model-b-usb-boot/feed/ 1
Raspberry Pi の USB-OTG ethernet の MAC address を model B の ethernet と同じ規則で設定する https://matoken.org/blog/2018/11/07/set-the-mac-address-of-raspberry-pi-s-usb-otg-ethernet-with-the-same-rule-as-the-ethernet-of-model-b/ https://matoken.org/blog/2018/11/07/set-the-mac-address-of-raspberry-pi-s-usb-otg-ethernet-with-the-same-rule-as-the-ethernet-of-model-b/#respond Wed, 07 Nov 2018 14:19:08 +0000 http://matoken.org/blog/?p=2227

Raspberry Pi model A/A+/Zero/ZeroW/ZeroHW/Compute Module/Compute module 3ではUSB-OTGが利用できます.(ZeroHW/Compute Module/Compute module 3は自分は未確認)

USB-OTGでUSBをEthernetにしてHostPCからアクセスするようにするとUSBケーブル1本で電源と併用できて便利です.

このときMACアドレスはモジュール読み込み毎に自動生成されます.
以下の例では,接続先(PC等)から見えるMACが HOST MAC 6a:b3:b1:5e:22:89 で,Raspberry Pi の中でのMACが MAC ae:3a:c7:8e:50:38 になっています.

$ sudo modprobe g_ether
$ dmesg | tail -15
[   88.517568] using random self ethernet address
[   88.517590] using random host ethernet address
[   88.519210] usb0: HOST MAC 6a:b3:b1:5e:22:89
[   88.520195] usb0: MAC ae:3a:c7:8e:50:38
[   88.520396] using random self ethernet address
[   88.520412] using random host ethernet address
[   88.520534] g_ether gadget: Ethernet Gadget, version: Memorial Day 2008
[   88.520546] g_ether gadget: g_ether ready
[   88.520580] dwc2 20980000.usb: bound driver g_ether
[   88.866651] IPv6: ADDRCONF(NETDEV_UP): usb0: link is not ready
[   94.048758] dwc2 20980000.usb: new device is high-speed
[   94.128837] dwc2 20980000.usb: new device is high-speed
[   94.197523] dwc2 20980000.usb: new address 9
[   96.057234] g_ether gadget: high-speed config #1: CDC Ethernet (ECM)
[   96.095719] IPv6: ADDRCONF(NETDEV_CHANGE): usb0: link becomes ready
$ /sbin/ifconfig usb0
usb0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 10.42.0.212  netmask 255.255.255.0  broadcast 10.42.0.255
        inet6 fe80::5855:ab0c:6628:557c  prefixlen 64  scopeid 0x20<link>
        ether ae:3a:c7:8e:50:38  txqueuelen 1000  (Ethernet)
        RX packets 208  bytes 17243 (16.8 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 67  bytes 7696 (7.5 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

これは毎回変わるのでふと気づくとホストPCのネットワークの設定が沢山になっていたり…….

$ nmcli connection show | grep ethernet | wc -l
25

MAC addressを固定するにはモジュール読み込み時に指定してあげればOKです.

$ sudo rmmod g_ether
$ sudo modprobe g_ether host_addr=de:ad:fe:ef:00:01 dev_addr=de:ad:fe:ef:00:00
$ dmesg | egrep usb0:.*MAC | tail -2
[ 1067.248443] usb0: HOST MAC de:ad:fe:ef:00:01
[ 1067.248958] usb0: MAC de:ad:fe:ef:00:00

永続化するには,g_etherモジュールを読んでいるところで指定してあげます.

/boot/cmdline.txt の場合 rootwait の前に以下を追加
modules-load=dwc2,g_cdc g_ether.host_addr=de:ad:fe:ef:00:01 g_ether.dev_addr=de:ad:fe:ef:00:00
/etc/modules の場合
g_ether g_ether.host_addr=de:ad:fe:ef:00:01 g_ether.dev_addr=de:ad:fe:ef:00:00
Note

※g_cdcの場合はこんな感じで

g_cdc g_cdc.host_addr=de:ad:fe:ef:00:01 g_cdc.dev_addr=de:ad:fe:ef:00:00

/etc/rc.local の場合 exit より前の行に以下を追加(※model Aの場合 cmdline.txt, modules 共に module は読み込まれるけど動作はうまく行かないことが多いので rc.local が良さそう)
modprobe g_ether host_addr=de:ad:fe:ef:00:01 dev_addr=de:ad:fe:ef:00:00

このときのMAC addressは g_ether が自動生成したものを使うのが無難だとおもうのですが,ランダムとかでいんだろうか?という不安があります.

ベンダーIDに使われていない領域だったら多分問題ないですが,これから埋まることもありそうです.(IPアドレスのプライベートIPアドレスのような領域があるのかもしれ無いけど未確認)

Raspberry Pi model B シリーズのNICには Raspberry Pi Foundation のベンダーコードが使われています.

nmap のMAC addressベンダー情報のファイルから確認
$ grep -i raspberry /usr/share/nmap/nmap-mac-prefixes
B827EB Raspberry Pi Foundation

Raspberry Pi の smsc95xx の MAC address の生成は,上6桁はベンダーIDの b8:27:eb を,下6桁はボードのserialの下6桁を割り当てているようです.

MAC address generation
To have a predetermined MAC address, a given SMSC LAN9512 must be attached to an EEPROM that contains the MAC address. But on the Raspberry Pi Model B, this EEPROM is not present; therefore, this driver must assign a MAC address itself. We do this by generating a MAC address from the board’s serial number. This guarantees that a given Raspberry Pi will always have the same MAC address and that two Raspberry Pis are extremely unlikely to be assigned the same MAC address.

手元の Raspberry Pi 2 Model B を確認すると確かにそうなっているようです.

$ ifconfig | grep ether
		ether b8:27:eb:ff:56:0a  txqueuelen 1000  (Ethernet)
$ grep Serial /proc/cpuinfo
Serial          : 0000000094ff560a
$ sed -n "s/^Serial.*:.*\(..\)\(..\)\(..\)$/b8:27:eb:\1:\2:\3/p" /proc/cpuinfo
b8:27:eb:ff:56:0a
$ cat /proc/device-tree/model ;echo
Raspberry Pi 2 Model B Rev 1.1
Note

16進数6桁は 0xFFFFFF → 16777215です,Raspberry Pi は2018年3月時点で190万台出荷しているようなので2周目に入っています.低い確率でしょうが同じMAC addressが割り当てられる可能性が…….

we’ve sold 19 million Raspberry Pis in total

内蔵ネットワークに自分でMAC addressを指定したい場合はこんな感じでいけます.

/boot/cmdline.txt に以下を設定
smsc95xx.macaddr=b8:27:eb:00:00:00
/etc/network/interfaces でも設定できるはずだがRaspbianでは未確認
hwaddress ether b8:27:eb:00:00:00

CPU Serialを詐称する手も?

ということで,Raspberry Pi model A / Zero でもこの MAC address が利用できそうな感じです.外向けの HOST MAC をこのアドレスにしてみます.

$ sed -n "s/^Serial.*:.*\(..\)\(..\)\(..\)$/b8:27:eb:\1:\2:\3/p" /proc/cpuinfo | tee ~/macaddress
b8:27:eb:d8:63:18
$ sudo vi /boot/cmdline.txt
$ sudo reboot
  :
  :
$ dmesg | grep usb0
[    4.937660] usb0: HOST MAC b8:27:eb:d8:63:18
[    4.937845] usb0: MAC 86:d7:fe:57:f2:d5

ホストPCでもちゃんと指定したものになっています.

$ /sbin/ifconfig enxb827ebd86318 | grep ether
			 ether b8:27:eb:d8:63:18  txqueuelen 1000  (Ethernet)

とりあえずこれで使ってみようと思います.

環境
$ lsb_release -d
Description:    Raspbian GNU/Linux 9.4 (stretch)
$ uname -m
armv6l
$ cat /proc/device-tree/model ;echo
Raspberry Pi Model A Rev 2

]]>
https://matoken.org/blog/2018/11/07/set-the-mac-address-of-raspberry-pi-s-usb-otg-ethernet-with-the-same-rule-as-the-ethernet-of-model-b/feed/ 0
Raspbian stretch 2018-10-09 https://matoken.org/blog/2018/10/12/raspbian-stretch-2018-10-09/ https://matoken.org/blog/2018/10/12/raspbian-stretch-2018-10-09/#respond Thu, 11 Oct 2018 21:54:55 +0000 http://matoken.org/blog/?p=2179

Raspberry Pi の Debian ベースのディストリビューションの最新版の Raspbian 2018-10-09 がリリースされたようです.

curl -sS -o – http://downloads.raspberrypi.org/raspbian/release_notes.txt | perl -e ‘$c=0;while(<STDIN>){if$c!=0 ) && ( $=~/^\ /{print $}elsif($c==0){print $_}else{exit} $c++}’
2018-10-09:
  * In startup wizard, assign keyboard to country as per Debian installer recommendations
  * In startup wizard, add option to use US keyboard in preference to country-specific option
  * In startup wizard, show IP address on first page
  * In startup wizard, check for existing wifi network connection and show it if there is one
  * In startup wizard, install language support packages for LibreOffice and other applications
  * In startup wizard, improve operation with keyboard only and no mouse
  * Password change in Raspberry Pi Configuration and startup wizard now works properly if passwords contain shell characters
  * Battery indicator plugin modified to cope with Pi-top hardware monitor crashing
  * Networking plugin hides wifi password characters by default
  * In Scratch 2 GPIO plugin, set pin from dropdown list rather than free text
  * In Scratch 2 SenseHAT plugin, swap x and y axis values for LED array
  * Include latest Adobe Flash player (31.0.0.108)
  * Include latest RealVNC Server (6.3.1)
  * Include libav-tools
  * Include ssh-import-id
  * Removed Mathematica
  * Merge in latest third-party code for Bluetooth ALSA interface
  * Add ability to prevent software update changing configuration files, by creating ~/.config/.lock file
  * Various other small bug fixes, tweaks and changes to text
  * Make dhcpcd work with 3G devices
  * Add hw acceleration to ffmpeg
  * Improved WiFi-BT coexistence parameters
  * Run fake-hwclock before systemd-fsck-root
  * Raspberry Pi PoE HAT support
  * Linux kernel 4.14.71
  * Raspberry Pi firmware 5b49caa17e91d0e64024380119ad739bb201c674

個人的には 「 Add hw acceleration to ffmpeg」 が嬉しいです.自分でbuildしなくてもよくなってそうです.

$ dpkg-query -W ffmpeg
ffmpeg  7:3.2.10-1~deb9u1+rpt2
$ ffmpeg 2>&1 | grep -o -E '\--enable-omx-rpi|\--enable-mmal'
--enable-omx-rpi
--enable-mmal

とりあえずダウンロードしておきます.

$ # ダウンロードURL確認
$ LANG=C wget --max-redirect=0 https://downloads.raspberrypi.org/raspbian_lite_latest 2>&1 | sed -En 's/Location: ([^ ]*).*$/\1/p'
https://downloads.raspberrypi.org/raspbian_lite/images/raspbian_lite-2018-10-11/2018-10-09-raspbian-stretch-lite.zip
$ # ファイル確認
$ w3m -dump https://downloads.raspberrypi.org/raspbian_lite/images/raspbian_lite-2018-10-11/
Index of /raspbian_lite/images/raspbian_lite-2018-10-11

   [ICO]                        Name                        Last    Size Description
                                                          modified
  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
[PARENTDIR] Parent Directory                                           -
[ ]         2018-10-09-raspbian-stretch-lite.info        2018-10-09  54K
                                                              13:34
[ ]         2018-10-09-raspbian-stretch-lite.zip         2018-10-09 351M
                                                              13:34
[ ]         2018-10-09-raspbian-stretch-lite.zip.sha1    2018-10-11   79
                                                              11:38
[ ]         2018-10-09-raspbian-stretch-lite.zip.sha256  2018-10-11  103
                                                              11:38
[ ]         2018-10-09-raspbian-stretch-lite.zip.sig     2018-10-10  473
                                                              13:37
[ ]         2018-10-09-raspbian-stretch-lite.zip.torrent 2018-10-11  28K
                                                              11:38
  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━


Apache/2.4.10 (Debian) Server at downloads.raspberrypi.org Port 80
$ # bitttorrent と 署名ファイルダウンロード
$ wget https://downloads.raspberrypi.org/raspbian_lite/images/raspbian_lite-2018-10-11/2018-10-09-raspbian-stretch-lite.zip.torrent https://downloads.raspberrypi.org/raspbian_lite/images/raspbian_lite-2018-10-11/2018-10-09-raspbian-stretch-lite.zip.sig
$ # Transmission で ダウンロード
$ transmission-cli ./2018-10-09-raspbian-stretch-lite.zip.torrent
   :
$ # 署名確認
$ gpg --verify 2018-10-09-raspbian-stretch-lite.zip.sig
]]>
https://matoken.org/blog/2018/10/12/raspbian-stretch-2018-10-09/feed/ 0
Raspberry Pi でHTML5版「艦これ」を試すも失敗 https://matoken.org/blog/2018/08/23/failure-to-try-html-5-version-kankore-at-raspberry-pi/ https://matoken.org/blog/2018/08/23/failure-to-try-html-5-version-kankore-at-raspberry-pi/#respond Wed, 22 Aug 2018 21:42:49 +0000 http://matoken.org/blog/?p=2036

先日「艦これ」がHTML5になったと聞いて試してみました.確かにadobe Flashの導入されていないLinux端末でも問題なく動作します.

kankore html5

Linuxも言及されていますね.
ということはarmやなにやでも動作するはずってことでまずはRaspberry Pi 2 B で試してみました.結果から言うと失敗しました.

環境

試した環境はこんな感じです.

  • board : Raspberry Pi 2 B

  • OS : RASPBIAN STRETCH WITH DESKTOP 2018-06-27

  • SoC : BCM2837

  • CPU : ARMv7

  • RAM : 1GB

  • WebBrowser : Chromium 65.0.3325.181-0+rpt4

RASPBIAN STRETCH WITH DESKTOP 2018-06-27 を導入して,system を apt update && apt upgrade した状態です.あとは既定値のままで,ウェブブラウザは Chromium,操作はVNC経由で行いました.
解像度が大分上がっています.とりあえず F11 でフルスクリーン表示にして, Ctrl + – で画面を縮小してみました.
ログインしてスクリーンが黒く塗りつぶされるまで数分,「Weigh Anchor! Download Now…」の表示のプログレス画面ですごく時間がかかります.20分以上経ってからエラー画面(所謂猫った状態)になります.
3回試して毎回プログレスバーが8割ほどのところでコケます.
システムの状態を見ていると,黒い画面の頃からずっとCPUが100%で張り付いたままです.RAMには余裕があります.恐らくゲームデータをローカルにコピーして展開などの処理でCPUを使い切ってなかなか処理が終わらずタイ雨アウトしているのではないかと思います.
CPUがボトルネックのようなのでクロックをオーバークロックしてみましたが体感速度は変わらずやはりエラーとなります.2回試しても同じように失敗して駄目でした.

ということでRaspberry Pi 2 B で艦これは今のところ無理そうです.しばらく待って艦これ自体のチューニングが進んだり,CPUの強化されている Raspberry Pi 2 B v1.2(BCM2837)以降なら動くかもしれません.持っている人にはぜひ試して結果を教えてほしいです.

#ちなみに試すのに一回あたり30分ほどかかっているので動いたとしてもあまり現実的ではないかもしれません…….どうしてもやりたいなら母艦の画面を転送したほうが良さそう.

192.168.2.211 (raspberrypi) - VNC Viewer_045範囲を選択_048192.168.2.211 (raspberrypi) - VNC Viewer_046

SoC

cpu clock

RAM

Pi

BCM2836

4 x 900Mhz

1GB

2B

BCM2837

4 x 900MHz

1GB

2B v1.2

BCM2837

4 x 1.2GHz

1GB

3B

BCM2837B0

4 x 1.4GHz

1GB

3B+

]]>
https://matoken.org/blog/2018/08/23/failure-to-try-html-5-version-kankore-at-raspberry-pi/feed/ 0
Raspbianの初期設定ウィザード( first-boot configuration )を試す https://matoken.org/blog/2018/07/14/try-raspbian-first-boot-configuration/ https://matoken.org/blog/2018/07/14/try-raspbian-first-boot-configuration/#respond Sat, 14 Jul 2018 11:15:14 +0000 http://matoken.org/blog/?p=2001 先日Raspberry Pi向けのOSのRaspbian 2018-06-27がリリースされました.

2018-06-27:
  * New first-boot configuration wizard added
  * Recommended Software installer added
  * Bluej, Greenfoot, NodeRED, Claws Mail, VNC Viewer removed from image - can now be installed from Recommended Applications
  * Qpdfview PDF viewer installed instead of Xpdf
  * Version 65.0 of Chromium browser included, with latest Flash player
  * Volume up / down keys now change by 5% increments and affect currently-selected output device rather than internal device only
  * Network plugin now remembers previously-entered WiFi network passwords when prompting for reconnection
  * Serial port and serial console can now be switched separately in Raspberry Pi Configuration
  * Lxkeymap keyboard language setting application removed - replaced with dialog within Raspberry Pi Configuration
  * Wifi country and keyboard language setting dialogs in Raspberry Pi Configuration now callable from other applications
  * New version of Piboto font included to render with correct weight under some rogue applications
  * Reconnection to Bluetooth audio devices on reboot improved
  * Disable click-to-rename behaviour in file manager if single-click selection enabled
  * Appearance Settings dialog makes config changes to some Qt files to match selected theme
  * MIME file type associations improved
  * Multiple desktop management options removed from mouse middle-click menu
  * Menu shortcuts to Raspberry Pi website amended
  * Python 2 IDLE menu link removed
  * Sample Magpi PDF installed in /home/pi/MagPi
  * Various minor tweaks, bug fixes and appearance changes
  * Bluetooth updates
    - Firmware with Bluetooth 4.2 features
    - SCO profile suppot added via bthelper.service
  * Linux kernel 4.14.50+
  * Raspberry Pi firmware 748fb17992426bb29d99224b93cb962fefbdc833

* New first-boot configuration wizard added が気になります.初回起動時にセットアップウィザードが走るようになったようです.気になるので試してみました.

先ずはOSイメージを入手.
以下のページから RASPBIAN STRETCH WITH DESKTOP の方を入手します.

適当な方法でイメージをSD cardに書き込みます.

HDMIモニタに接続,若しくはVNC経由(今回は後者)で起動すると「Welcome to Raspberry Pi」というウィンドウが表示されます.

Welcome to Raspberry Pi_001

まずは国関連の設定.以下は日本でに言語環境で利用する場合です.

Country: Japan
Language : Japanise
Timezone: Tokyo

Welcome to Raspberry Pi_003

次はpi アカウントのパスワードの設定です.初期状態ではraspberryですが,ここのままだとsshやVNCなどのリモート接続を有効にすると誰でも入れてしまい乗っ取られてしまうのでぜひ変更しましょう.(piアカウントを無効にして別のユーザを作るのもいいですね)

Welcome to Raspberry Pi_005

次にWi-Fiの設定です.今回試した Raspberry Pi は Raspberry Pi 2 B でWi-Fiは付いていませんがUSBのWi-Fiドングルを刺していたらこの画面になりました.付けていなくてもRaspberry Pi 3 B / Raspberry Pi 3 B+ / Raspberry Pi Zero W でも設定できると思います.

Welcome to Raspberry Pi_008

次は Update です.しばらく時間がかかります.

Welcome to Raspberry Pi_009

Updateが終了すると「System is up to date」と表示されます.

Welcome to Raspberry Pi_014

これでおしまい.「Reboot」ボタンで設定が反映されます.

Welcome to Raspberry Pi_015

もしまたこのウィザードを実行したい場合はpiwizコマンドで実行できます.

$ sudo -i piwiz

もし,以前からのRaspbianで実行したい場合はpiwizパッケージを導入することで実行できるようになります.

$ sudo apt update
$ sudo apt install piwiz

raspi-configrc_guiの簡易版みたいな感じですね.
画面は英語ですが,言語ファイルがあるので日本語化もできそうです.しかし,日本語化が反映されるのは設定後?となるとあまり意味はないですかね…….

]]>
https://matoken.org/blog/2018/07/14/try-raspbian-first-boot-configuration/feed/ 0
microSDスロットの固定機構の壊れたRaspberry Pi 2 Bのバネを取り外して普通に使えるようにする https://matoken.org/blog/2018/05/26/remove-the-broken-raspberry-pi-2-b-spring-of-microsd-slot/ https://matoken.org/blog/2018/05/26/remove-the-broken-raspberry-pi-2-b-spring-of-microsd-slot/#respond Fri, 25 May 2018 16:20:54 +0000 http://matoken.org/blog/?p=1903 SANY0011

Raspberry Pi 2 Bを使っているのですが,以前からmicroSDソケットの固定機構が壊れてしまっています.セロハンテープで留めて更にケースに入れて動きにくくしているのですがたまにずれるようで起動中にストレージを見失ってしまうことがあります.(そして数回に一回は要fsckに)

ちょっと面倒なので対処したいなと思いながら放置していたのですが,また今日も起こったので調べてみることに.多分microSDを押し返すピンかバネを無くしてしまえたら解決しそうな気がします.でも内部が見えないのでどこにピンやバネがあるのかよくわからないです.

SANY0015

きっと先駆者が居るだろうと検索するといくつかそれらしいページを見つけました.

ソケットを交換するアプローチ

ソケットの中のスプリングを取り出してしまうアプローチ

後者のスプリングを取り出すのが簡単そうだし,最悪失敗しても前者のソケットを交換すればいいかなと試してみました.スプリングの場所が分かったのですが現物を見てもよくわからないです.光を当てながら少し斜めから見るとバネが見えました.バネの横の部分を一旦開けて中を確認する人も居るようです.

SANY0019

ここで安全ピンのピン先でこじるようにと思いましたがちょっと安全ピンが大きいせいかソケットが膨らむのでジャンパワイヤのオスを使いました.

ソケットのスプリングの上側からこじるとプラスチックのラッチが外れました.一旦ラッチを取り出して更にその奥をこじるとスプリングの反応がありました.スプリングを内側に倒してから引っ張り上げるようにして取り外せました.

SANY0020

この状態でmicroSDを差し込むとmicroSDは押し返されなくなりました!これで最近のRaspberry Pi Zero(多分3B/3B+も)と同じような使い勝手になったと思います.

SANY0022

今回はRaspberry Pi 2 Bでしたが,Raspberry Pi B+/Raspbery Pi A+もロック機構が壊れたら同様の機構なので同じように解決できると思います.

今だと最新のRaspberry Pi 3 B+を買う人が多いでしょうが.

]]>
https://matoken.org/blog/2018/05/26/remove-the-broken-raspberry-pi-2-b-spring-of-microsd-slot/feed/ 0
Devuan ascii armhf(Raspberry Pi)で時計合わせ https://matoken.org/blog/2018/02/20/devuan-ascii-armhf-raspberry-pi-set-time/ https://matoken.org/blog/2018/02/20/devuan-ascii-armhf-raspberry-pi-set-time/#respond Tue, 20 Feb 2018 14:24:10 +0000 http://matoken.org/blog/?p=1842 Raspberry PiにはRTCが付いていません.なのでシステム停止すると時間情報が飛んでしまいます.fake-hwclockが設定されていたら前回停止時(に近い)時間がファイルに保存されていてその時間に設定されますが,停止時の時間はカウントされないので時間がずれます.ということでネットワークが有効な場合ntpを参照して時計合わせをしたいです.
最近のDebianやRaspbianはsystemdなのでtimesyncd.confでNTP serverを指定してtimedatectlコマンドで有効にする感じだと思うのですが(既定値でそうなっている),Devuanは脱systemdなディストリビューションなのでこの方法は使えません.

$ sudo vi /etc/systemd/timesyncd.conf
$ sudo timedatectl set-ntp true`

詳細はman timesyncd.conf, man timedatectl

ということでntpdateを入れてみました.

$ sudo apt install ntpdate
$ sudo ntpdate 192.168.1.102
$ grep -A1 -B2 ntp /etc/rc.local
if [ "$_IP" ]; then
  printf "My IP address is %s\n" "$_IP"
  /usr/sbin/ntpdate 192.168.1.102
fi

長時間動かすならcrontabで定期的に設定したほうがいいかも?(若しくは何らかのntpd)

$ sudo -u root crontab -l|tail -2
@reboot /usr/sbin/ntpdate 192.168.1.102
3 3 * * *       /usr/sbin/ntpdate 192.168.1.102

追記)
このシステムはRaspbian stretchをDevuan asciiにdist-upgradeしたシステムなのでntpの設定がないだけかもしれません.Devuan asciiをクリーンインストールすれば必要ない設定かも(未確認)

]]>
https://matoken.org/blog/2018/02/20/devuan-ascii-armhf-raspberry-pi-set-time/feed/ 0
Raspbian stretch イメージを Devuan ascii にしてみる https://matoken.org/blog/2018/01/23/raspbian-stretch-imag-to-devuan-ascii/ https://matoken.org/blog/2018/01/23/raspbian-stretch-imag-to-devuan-ascii/#respond Mon, 22 Jan 2018 23:05:29 +0000 http://matoken.org/blog/?p=1799 DevuanというDebianからのフォークディストリビューションがあります.

これは脱SystemdなLinuxディストリビューションで,Raspberry Pi等のarmhfにも対応しています.そしてDebianからDevuanに移行することが出来ます.(Debian jessie -> Devuan jessie)
DebianベースのRaspbianからも同様に移行できるというmailを見かけたので試してみます.

SD cardでやったほうが手順は少ないのですが,遅いし寿命も縮むだろうしってことでイメージサイズを拡大したRaspbianを元にchroot + QEMU User EmulatorでArm以外のhostででやってみました.

サイズを拡大したRaspbianイメージをマウント

以下の手順で用意したイメージを元にします.

raspbian-stretch-lite_latest.imgが元のイメージで,今回devuan_ascii.imgとしてコピーしたものを使います.

$ cp ./raspbian-stretch-lite_latest.img ./devuan_ascii.img
$ sudo kpartx -av ./devuan_ascii.img
add map loop0p1 (253:4): 0 85045 linear 7:0 8192
add map loop0p2 (253:5): 0 8129 linear 7:0 63
$ sudo mount /dev/mapper/loop0p2 /mnt
$ sudo mount /dev/mapper/loop0p1 /mnt/boot

QEMU User Emulatorが使えるようにqemu-user-staticをcp

これでQEMU User Emulatorが透過的に利用できます.

$ sudo cp -p /usr/bin/qemu-arm-static /mnt/usr/bin/

chroot用に/devと/procをbind mountしてchroot

$ sudo mount --bind /dev /mnt/dev
$ sudo mount --bind /dev/pts /mnt/dev/pts
$ sudo mount --bind /proc /mnt/proc
$ sudo chroot /mnt /bin/bash

Raspbian stretchを最新の状態にする

# apt update
# apt upgrade -y

Devuanリポジトリの鍵をインポート

Devuanリポジトリの鍵をインポートする.そのために必要なdirmngrpkgも導入.

# apt install dirmngr
# apt-key adv --recv-keys 94532124541922FB
Executing: /tmp/apt-key-gpghome.zqL0gcSbes/gpg.1.sh --recv-keys 94532124541922FB
gpg: key 94532124541922FB: public key "Devuan Repository (Primary Devuan signing key) <repository@devuan.org>" imported
gpg: Total number processed: 1
gpg:               imported: 1

source.listをDevuanのものに書き換え

Devuanのstableはjessieですが,元のRaspbianがstretchなのでそれに対応するAsciiを指定しています.
Devuan jessieを使いたい場合は,Raspbian jessieを元にするといいと思います.

Devuan Debian
Jessie(stable) Jessie(oldstable)
Ascii(development) Stretch(stable)
Beowulf(-) Buster(testing)
Ceres(unstable) Sid(unstable)
# vi /etc/apt/sources.list
# cat /etc/apt/sources.list|grep -v ^#
deb http://mirrordirector.raspbian.org/raspbian/ stretch rpi
deb http://auto.mirror.devuan.org/merged ascii main contrib non-free
deb http://auto.mirror.devuan.org/merged ascii-updates  main contrib non-free
deb http://auto.mirror.devuan.org/merged ascii-security main contrib non-free

Devuanのパッケージにupgrade

# apt update && apt upgrade
  :
274 upgraded, 7 newly installed, 0 to remove and 3 not upgraded.
Need to get 115 MB of archives.
After this operation, 25.0 MB disk space will be freed.
Do you want to continue? [Y/n] Y
  :
# apt dist-upgrade
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Calculating upgrade... Done
The following packages were automatically installed and are no longer required:
  bluez bluez-firmware cgmanager libcgmanager0 systemd-shim
Use 'sudo apt autoremove' to remove them.
The following packages will be REMOVED:
  libpam-systemd mountall pi-bluetooth plymouth raspberrypi-sys-mods systemd systemd-sysv
The following NEW packages will be installed:
  eudev libeudev1 sysvinit-core
The following packages will be upgraded:
  init libudev1 udev
3 upgraded, 3 newly installed, 7 to remove and 0 not upgraded.
Need to get 1162 kB of archives.
After this operation, 9431 kB disk space will be freed.
Do you want to continue? [Y/n] Y
  :

chrootから抜けてイメージアンマウント

#念の為kpartx -dの前にfsckしておくといいかも?

# exit
$ sudo umount /mnt/proc
$ sudo umount /mnt/dev/pts
$ sudo umount /mnt/dev
$ sudo umount /mnt/boot
$ sudo umount /mnt
$ sudo kpartx -d /dev/mapper/loop0p1
$ sudo kpartx -d /dev/mapper/loop0p2
$ sync

SD cardにイメージを書き込んでRaspberry Piで起動

普通にddとかEtcherとかでSD cardに書き込みます.

$ time sudo dcfldd if=./devuan_ascii.img of=/dev/sdd;sync;sync
128000 blocks (4000Mb) written.
128000+0 records in
128000+0 records out

real    7m13.207s
user    0m0.823s
sys     0m9.211s

後はRaspberry Piで起動すればOK.今回はRaspberry Pi 2 Bで試しました.

Systemdとか居ません.

RAMの利用状況はこんな感じ

$ free
              total        used        free      shared  buff/cache   available
Mem:         949584       21916      879120         188       48548      879976
Swap:        102396           0      102396

しかしneofetchとかではRaspbianのままですね.該当pkgのreinstallとかで更新できそうな気がしますが未検証.

IMG_20180123_001641

イメージ操作めんどくさいのでdebootstrapの方が楽かもしれない?

いやそれなら公式イメージのほうがいいか

]]>
https://matoken.org/blog/2018/01/23/raspbian-stretch-imag-to-devuan-ascii/feed/ 0
Raspbianイメージを任意の広さに拡大する https://matoken.org/blog/2018/01/21/resize-partition-in-a-images-file/ https://matoken.org/blog/2018/01/21/resize-partition-in-a-images-file/#comments Sat, 20 Jan 2018 23:19:01 +0000 http://matoken.org/blog/?p=1793 Raspbian はSD cardに書き込んでRaspberry Piで起動するとraspi-configから簡単にパーティションサイズを拡大できます.しかし,パッケージのアップデートや導入に時間がかかるのでSD cardに書き込む前にこの辺りの処理は済ませておきたいです. chrootとQEMU User Emulatorを使えば出来るのですが,今度はDisk fullに……. ということでraspbianイメージを広げてみます.
※速度の速いストレージだと必要ない処理かもしれませんが,カスタマイズしたイメージを用意するとかにも使えます.
※ここではRaspbian Lite stretch 2017-11-29のイメージを元にしていますが,最終パーティションを広げるのであれば他の各種イメージでもほぼそのまま,途中のパーティションサイズを変更するのも応用でいけます.

今回は広げると行ってもオリジナルのファイルはそのままに,4GBほどのサイズのイメージを作ってそちらにデータをコピーしてそのイメージのサイズを広げることにします.

今回の環境は Debian sid amd64 環境です.Linux環境であればほぼ同じ手順で行けると思います.

4GBイメージを作成

4GBほどの容量のイメージを作成します.もっと大きい容量がいい人はcountを増やしましょう.
<追記>4GBにしてはちょっと大きかったかも.手持ちにカードの容量より少し小さいサイズにすると良いです.</追記>

$ dd if=/dev/zero of=./4gb.img bs=1M count=4000
$ ls -l ./4gb.img
-rw-r--r-- 1 mk mk 4194304000 Jan 19 21:28 ./4gb.img

losetupでデバイスマッピングをする

/dev/loop0に割り当てられた.

$ sudo losetup -f --show ./4gb.img
/dev/loop0

Raspbianイメージの用意とデバイスマッピング

/dev/loop1に割り当てられた.

$ unzip 2017-11-29-raspbian-stretch-lite.zip
$ sudo losetup -f --show ./2017-11-29-raspbian-stretch-lite.img 
/dev/loop1

Raspbianイメージを4GBのイメージにコピー

loop1(Raspbian)のイメージをloop0(4GB)にコピーしている.

$ sudo dd if=/dev/loop1 of=/dev/loop0 bs=1M
1772+0 records in
1772+0 records out
1858076672 bytes (1.9 GB, 1.7 GiB) copied, 161.929 s, 11.5 MB/s

Raspbianイメージを片付ける

$ sudo losetup -d /dev/loop1
$ rm ./2017-11-29-raspbian-stretch-lite.img

コピーしたイメージをfdiskで確認

Raspbianのパーティション情報が見えます.

$ sudo fdisk -l /dev/loop0 
Disk /dev/loop0: 3.9 GiB, 4194304000 bytes, 8192000 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: 0x37665771

Device       Boot Start     End Sectors  Size Id Type
/dev/loop0p1       8192   93236   85045 41.5M  c W95 FAT32 (LBA)
/dev/loop0p2      94208 3629055 3534848  1.7G 83 Linux

fdiskでパーテションサイズを変更する

ここはわかりづらいですが,以下のような操作をしています.

  • d コマンドで 2つ目のパーテションを削除
  • n コマンドで 2つ目のパーテションを最大容量で作り直し
    • この時 First sector を削除前のものと合わせること
  • p コマンドで確認
  • w コマンドで書き込み
    • w コマンドで書き込むまではファイルシステムは変更されないので間違ってもやり直しできます.
$ sudo fdisk /dev/loop0

Welcome to fdisk (util-linux 2.30.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Command (m for help): d
Partition number (1,2, default 2): 2

Partition 2 has been deleted.

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): 2
First sector (2048-8191999, default 2048): 94208
Last sector, +sectors or +size{K,M,G,T,P} (94208-8191999, default 8191999): 8191999

Created a new partition 2 of type 'Linux' and of size 3.9 GiB.  
Partition #2 contains a ext4 signature.

Do you want to remove the signature? [Y]es/[N]o: N

Command (m for help): p

Disk /dev/loop0: 3.9 GiB, 4194304000 bytes, 8192000 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: 0x37665771

Device       Boot Start     End Sectors  Size Id Type
/dev/loop0p1       8192   93236   85045 41.5M  c W95 FAT32 (LBA)
/dev/loop0p2      94208 8191999 8097792  3.9G 83 Linux

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Re-reading the partition table failed.: 無効な引数です                                                                         

The kernel still uses the old table. The new table will be used at the next reboot or after you run partprobe(8) or kpartx(8).

fdiskに慣れていない場合はgparted等でGUIで操作したほうが直感的で解りやすいかもしれません(未検証) -> gksudo gparted /dev/loop0
20180121_07:01:45-6347

kpartxでパーティションをマッピングする

上で使ったlosetupでも出来るのですが,オフセットを自分で計算して指定する必要がある

losetupを使う場合はfdiskのpコマンドの対象パーティーションの Start * Sector sizeをlosetupの-oに指定します.今回の例だと2つ目のパーティーションは 94208 * 512 になります.(未検証)

$ losetup -f –show -o `expr 94208 \* 512` /dev/loop0

ので今回はそのあたりを自動で行ってくれるkpartxを利用します.大抵は標準では入っていないので以下のエントリを参考に導入してから実行してください.

1つ目のパーティションが /dev/mapper/loop0p1 2つ目のパーティションが /dev/mapper/loop0p2 として設定されました.

$ sudo kpartx -av /dev/loop0
add map loop0p1 (253:4): 0 85045 linear 7:0 8192
add map loop0p2 (253:5): 0 8129 linear 7:0 63

ファイルシステムの修正

ファイルシステムが壊れているのでfsckで修正します.しかし,cleanと言われてしまうので,

$ sudo fsck -n /dev/mapper/loop0p2
fsck from util-linux 2.30.2
e2fsck 1.43.8 (1-Jan-2018)
rootfs: clean, 39394/110656 files, 256435/441856 blocks

一回resize2fsを叩いて怒られてから

$ sudo resize2fs /dev/mapper/loop0p2
resize2fs 1.43.8 (1-Jan-2018)
Please run 'e2fsck -f /dev/mapper/loop0p2' first.

fsckを実行し直します.

$ sudo e2fsck -f /dev/mapper/loop0p2
e2fsck 1.43.8 (1-Jan-2018)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
rootfs: 39394/110656 files (0.1% non-contiguous), 256435/441856 blocks

パーティーションリサイズ

fsckが通ったら今度こそリサイズです.これで最大サイズに変更されます.

$ sudo resize2fs /dev/mapper/loop0p2
resize2fs 1.43.8 (1-Jan-2018)
Resizing the filesystem on /dev/mapper/loop0p2 to 1012224 (4k) blocks.

mountしてみる

広くなっているのがわかります :)

$ sudo mount -o ro /dev/mapper/loop0p2 /mnt
$ df /mnt
ファイルシス        1K-ブロック   使用  使用可 使用% マウント位置                                                              
/dev/mapper/loop0p2     3954560 966004 2769736   26% /mnt

後片付け

アンマウントしてloopデバイスも解除します.

$ sudo umount /mnt
$ sudo kpartx -d /dev/mapper/loop0p?
$ sudo losetup -d /dev/loop0 

QEMU User EmulatorでArm以外でapt upgradeする

この辺はまた別のエントリで書くつもりですがこんな感じでupgradeしたりしています.

$ sudo mount /dev/mapper/loop0p2 /mnt
$ sudo mount /dev/mapper/loop0p1 /mnt/boot
$ sudo mount --bind /dev /mnt/dev
$ sudo mount --bind /dev/pts /mnt/dev/pts
$ sudo mount --bind /proc /mnt/proc
$ sudo cp -p /usr/bin/qemu-arm-static /mnt/usr/bin/
$ sudo chroot /mnt /bin/bash
# apt update && apt upgrade -y

このイメージはオリジナルのRaspbianイメージと同じようにSD cardに書き込んで利用できます.

]]>
https://matoken.org/blog/2018/01/21/resize-partition-in-a-images-file/feed/ 1
RaspberryPi向けのサービス公開サービスPiTunnelを試そうとした https://matoken.org/blog/2017/12/08/i-attempted-to-try-pitunnel-a-service-publishing-service-for-raspberrypi/ https://matoken.org/blog/2017/12/08/i-attempted-to-try-pitunnel-a-service-publishing-service-for-raspberrypi/#respond Thu, 07 Dec 2017 23:16:13 +0000 http://matoken.org/blog/?p=1732 PiTunnelをちょっと試そうとする.
Raspberry Pi向けのngrok的なもののよう.家庭内のLAN内のRaspberry Piのサービスを外部に公開しようと思うとルーターのポートを開けたりDDNS設定したりとちょっと面倒.これをお手軽に公開できるようになるサービス.

PiTunnelでアカウント登録をすると,Device管理画面に遷移するのでここでAdd Devides ボタンでinstall scriptのコマンドが表示される.

こんな感じだけど XXXXXXXX 部分はtokenのようなので注意.

curl https://pitunnel.com/install/XXXXXXXX | sudo python

とりあえずダウンロードして中見てから実行.

$ wget https://pitunnel.com/install/XXXXXXXXXX
$ lv XXXXXXXXXX
$ sudo python XXXXXXXXXX
   :
Configuring Startup   
Register the device   
OK
Starting PiTunnel


## All done!! ##
Please visit www.pitunnel.com to access your device!

www.pitunnel.comにアクセスしてねって見に行くと,

STATUS: Due to unprecedented high demand, we're currently having connection issues. Please sit tight and we'll have this resolved within the next 24 hours.

とかなっている.今使えなくなっているようです.

とりあえず少し叩いてみます.

$ pitunnel -h
usage: pitunnel [-h] [--port PORT] [--host HOST] [--name NAME] [--token TOKEN]
                [--http] [--register] [--type TYPE] [--private]
                [--http-auth HTTP_AUTH] [--quiet]

optional arguments:
  -h, --help            show this help message and exit
  --port PORT           Port Number
  --host HOST           Hostname or IP Address (default: localhost)
  --name NAME           Display name, for reference and subdomain creation.
  --token TOKEN         Optinal user tunnel token. Not required if installed
                        from website.
  --http                Indicates that a tunnel is for a HTTP service. Will
                        create http links on tunnels list and subdomains for
                        named tunnels.
  --register            Register a new device. Only needs to be called on
                        first use by install script.
  --type TYPE           Used to identify system tunnels like device_monitor.
  --private             Specifies that the tunnel wont except external
                        connections. It can only receive connections from
                        localhost. E.g. for device_monitor.
  --http-auth HTTP_AUTH
                        Add HTTP authorization to external access for this
                        tunnel: 'user:pass'
  --quiet               Quite Mode. Doesn't output messages to standard out.
$ pitunnel --register
OK
$ pitunnel --port 22
Trying to connect to pitunnel.com
Trying to connect to pitunnel.com
Trying to connect to pitunnel.com
Trying to connect to pitunnel.com
Trying to connect to pitunnel.com
^CTraceback (most recent call last):
  File "tunnelling/python/tunnel_client.py", line 139, in <module>
KeyboardInterrupt
[9305] Failed to execute script tunnel_client

て感じでやっぱ動かないようですね.1,2日待ちましょう.

今のところRaspbian最新用だけど,Ubuntu 16.04 TLS aarch64にも入った.
まだPiTunnelは使えてませんが,無料で1ポートだけだとバイナリ一個でokだしngrokの方がいいかなて感じがします.
でも少なくとも機能の多さはこっちが上そう.

]]>
https://matoken.org/blog/2017/12/08/i-attempted-to-try-pitunnel-a-service-publishing-service-for-raspberrypi/feed/ 0
Raspbian jessieのntp設定 https://matoken.org/blog/2017/10/25/raspbian-jessie-ntp-setting/ https://matoken.org/blog/2017/10/25/raspbian-jessie-ntp-setting/#respond Tue, 24 Oct 2017 17:47:45 +0000 http://matoken.org/blog/?p=1694 Raspbianにntpdやchronyやntpdateとか居ないけど何が面倒見てるんだろうてことで確認.
systemdが面倒見ててtimeatectlコマンドで確認設定ができるらしい.

$ dpkg -l|egrep -i "ntp|chrony"
$ systemctl -a | grep -i ntp

今の状態を確認

$ timedatectl status
      Local time: Wed 2017-10-25 02:01:14 JST
  Universal time: Tue 2017-10-24 17:01:14 UTC
        RTC time: n/a
       Time zone: Asia/Tokyo (JST, +0900)
 Network time on: yes
NTP synchronized: yes
 RTC in local TZ: no

NTP同期を無効にしてみる

$ sudo timedatectl set-ntp false

無効になった( Network time on: no )
再起動すると NTP synchronizedno にもなる.

$ timedatectl status
      Local time: Wed 2017-10-25 02:01:39 JST
  Universal time: Tue 2017-10-24 17:01:39 UTC
        RTC time: n/a
       Time zone: Asia/Tokyo (JST, +0900)
 Network time on: no
NTP synchronized: yes
 RTC in local TZ: no

おまけ

タイムゾーンの確認

$ timedatectl list-timezones | grep -i tokyo
Asia/Tokyo

タイムゾーンの設定

$ sudo timedatectl set-timezone

任意のntp serverの指定

dhcpdから渡ってきたもの.

hdcpdに無い場合 /etc/systemd/timesyncd.conf
NTPFallbackNTP

環境

Raspbian stretch lite 2017-09-07(未update)

$ lsb_release -a
No LSB modules are available.
Distributor ID: Raspbian
Description:    Raspbian GNU/Linux 9.1 (stretch)
Release:        9.1
Codename:       stretch
$ uname -a
Linux raspberrypi 4.9.41+ #1023 Tue Aug 8 15:47:12 BST 2017 armv6l GNU/Linux

]]>
https://matoken.org/blog/2017/10/25/raspbian-jessie-ntp-setting/feed/ 0
Raspberry Pi Zero Wのbluetoothを無効にする https://matoken.org/blog/2017/09/13/disable-raspberry-pi-zero-w-bluetooth/ https://matoken.org/blog/2017/09/13/disable-raspberry-pi-zero-w-bluetooth/#respond Wed, 13 Sep 2017 14:42:58 +0000 http://matoken.org/blog/?p=1662
  • Bluetooth経由でスマホからPCまで乗っ取れる攻撃手法が発覚 ~Bluetoothがオンになっているだけで攻撃可能 – PC Watch

  • てことでRaspberry Pi Zero WのBluetoothも無効にしたいなと.
    環境はRaspbian stretch lite 2017-09-07で確認しました.

    PCで設定した以下のblacklistの手順でもokなはずですが,config.txtで無効にする方法がありそうだと調べてみました.

    まずは定番のeLinux

    • RPiconfig – eLinux.org

      There's lots more documentation of available overlays in /boot/config/README. See source on Github for more.

    てことでGithubを見に行きます.

    それらしいものがありました :)

    Name:   pi3-disable-bt
    Info:   Disable Pi3 Bluetooth and restore UART0/ttyAMA0 over GPIOs 14 & 15
            N.B. To disable the systemd service that initialises the modem so it
            doesn't use the UART, use 'sudo systemctl disable hciuart'.
    Load:   dtoverlay=pi3-disable-bt
    Params: <None>

    早速設定してみます.

    $ echo 'dtoverlay=pi3-disable-bt' | sudo tee -a /boot/config.txt
    dtoverlay=pi3-disable-bt

    な感じで /boot/config.txt に追記して再起動しました.
    lsmodを設定前と比較するとこんな感じで居なくなっています.

    $ diff lsmod lsmod_pi3-disable-bt
    2,6d1
    < cmac                    3134  1
    < bnep                   11949  2
    < hci_uart               21190  1
    < btbcm                   7885  1 hci_uart
    < bluetooth             374820  24 hci_uart,bnep,btbcm
    9d3
    < snd_bcm2835            23131  0
    10a5,6
    > snd_bcm2835            23131  0
    > rfkill                 21373  4 cfg80211
    12d7
    < rfkill                 21373  6 bluetooth,cfg80211
    16d10
    < fixed                   3029  0
    18a13
    > fixed                   3029  0

    moduleのblacklistを設定するよりお手軽ですね :)

    恐らくRaspberry Pi 3 Bでも同様の設定は使えると思います.(持ってないので未確認)

    ]]>
    https://matoken.org/blog/2017/09/13/disable-raspberry-pi-zero-w-bluetooth/feed/ 0
    Raspbian stretch 2017-09-07 https://matoken.org/blog/2017/09/09/raspbian-stretch-2017-09-07/ https://matoken.org/blog/2017/09/09/raspbian-stretch-2017-09-07/#respond Fri, 08 Sep 2017 17:58:35 +0000 http://matoken.org/blog/?p=1643 DebianベースのRaspberry Pi向けのOSイメージの最新版Raspbian stretch 2017-09-07が出ている

    http://downloads.raspberrypi.org/raspbian/release_notes.txt

    2017-09-07:
    * Disable predictable network interface names for Ethernet devices
    * Bug fix for keyboard settings dialog in Raspberry Pi Configuration
    * Bug fix for crash on some videos and animations in Chromium
    * Bug fix for taskbar crash when running RealVNC server
    * Bug fix for reloading projects with extensions in Scratch 2
    * Bug fix for MAC address problem in Bluetooth
    * Simple mode and new icons in Thonny
    * New Japanese translations in Raspberry Pi Configuration
    * Install fonts-droid-fallback for international fonts

    先月の 2017-08-16 からDebian stretchベースになっています.今回は主にバグフィクスな感じ?

    New Japanese translations in Raspberry Pi Configuration

    は恐らくあっきーのrc_guiの翻訳かな?

    Disable predictable network interface names for Ethernet devices

    はwlan0とかがstretchからの新しい命名規則になる?

    Install fonts-droid-fallback for international fonts

    は自分は消して日本語フォント入れるかな?

    とりあえずダウンロードが終わったら試してみます.

    ]]>
    https://matoken.org/blog/2017/09/09/raspbian-stretch-2017-09-07/feed/ 0