特定グループでのみ dmesg command を有効にする

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

Debian buster/sid でdmesgを一般ユーザで実行

※この方法だと全ユーザで 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

Raspberry Pi 3 Model B の USB起動で Debian buster arm64 を動かす

最近入手した(遅) 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

Nextcloudの公開リンクURLをカスタマイズできるShareRenamerを試す

NextcloudでURLで共有を行うと,ランダムな文字列のURLが生成されます.これは第三者が推測しにくいようになっています.
しかし,印刷物などでURLを教える際には入力するのがとても面倒です.

ShareRenamerを使うとURLを任意の文字列に変更できるようになるのでこの問題が解決できそうです.

ShareRenamerを導入した後にURLで共有を行うと,rename用のテキストボックスるが現れます.このテキストボックスに任意の文字列を入力して「Rename」ボタンを押すと好きな文字列に変更できます.

20190115-21-01-54-25819.jpg

20190115-21-01-52-26787.jpg

一般公開してはいけない場合はパスワードで保護するようにしましょう.

JoyfullのWi-Fiの接続方法が変わっていた

ファミリーレストランのJoyfullに2017年から無料Wi-Fiが利用できるようになっていました.
これまではWi-Fiはopenで,接続後にWeb認証が必要でちょっと面倒でした.

2019年01月01日にジョイフル鹿児島高山店で食事を摂ったときに接続方法が変更になっているのに気づきました.
一般的な事前共有鍵方式になっていました.

IMG-20190101-083134

$ /sbin/iwlist wlan0 scanning | grep -A17 joyfull-wifi
                    ESSID:"joyfull-wifi"
                    Protocol:IEEE 802.11bgn
                    Mode:Master 
                    Frequency:2.452 GHz (Channel 9)
                    Encryption key:on
                    Bit Rates:144 Mb/s
                    Extra:wpa_ie=dd1a0050f20101000050f20202000050f2020050f20401000050f202
                    IE: WPA Version 1
                        Group Cipher : TKIP
                        Pairwise Ciphers (2) : TKIP CCMP
                        Authentication Suites (1) : PSK
                    Extra:
                    IE: IEEE 802.11i/WPA2 Version 1
                        Group Cipher : TKIP
                        Pairwise Ciphers (2) : TKIP CCMP
                        Authentication Suites (1) : PSK
                    Quality=100/100  Signal level=-41 dBm  
                    Extra:fm=0003

回線は変わらずAsahi Netのようです.

$ speedtest 
Retrieving speedtest.net configuration...
Testing from Asahi Net (203.189.61.188)...
Retrieving speedtest.net server list...
Selecting best server based on ping...
Hosted by extride inc (Hitoyoshi) [74.79 km]: 47.434 ms
Testing download speed................................................................................
Download: 4.90 Mbit/s
Testing upload speed......................................................................................................
Upload: 23.25 Mbit/s

これまではユーザ登録が必要で1アカウントで同時接続は1端末までだったのでスマホとPCのように複数台使おうとすると困ったり.そもそもユーザ登録に失敗したりとちょっと面倒だったので助かります :)

Windows 7 Pro 64bit環境の LIFEBOOK A574/MW で Windows Update を実行するとBSoD画面になる

Windows 7 Pro 64bit環境の LIFEBOOK A574/MW で Windows Update を実行するとアップデート後の再起動時にBSoD画面になるとのことで相談を受けた.
Restoreしてもこの状態になるとのこと.

IMG-20181226-160747

WindowsUpdateの累積パッチをばらしてとか遠回りなことをしていたけれど以下のBIOS書き換えツールにてBIOSをアップデートすることで解決した.

2019年1月の定例アップデートもOKだった.

GARMIN OREGON 300のログがおかしくなる

GPSロガーにGARMIN OREGON 300を使っています.大分前に販売は終了していて,バッテリーボックスや外装がへたっていますが未だ使えています.単3電池2本で12〜16時間程は動作するしいざとなったらUSB経由でも動作します.防水(手持ちのは外装が破損してもう防水ではない)で雨の中も普通に使えるし,地図にOpenStreetMapのデータを使うことも出来ます.
これを主に自転車のハンドルにマウントして使っています.
知らない道路を走るときなどはトラックログを前もって作成しておいて参照しながら走ると迷わず時間もロスせず走れていい感じです.(ブルベなどに最適)

ルートの作成にはJOSMやルートラボを利用しています.

走行後はログからデジタルカメラの写真にジオタグを埋め込んだりログや写真を見ながらOpenStreetMapに情報を入力したりしています.

そんな感じで便利に使っていたのですが,初日の出を見に行ったときのポタリングのデータを見たらデータがおかしいです.電源を入れ直すたびにその場所の標高が-になっているとかもおかしいのですが,日付が1999年05月17〜18日になっています.実際は2019年01月01日です.
GPSの1999年8月21日問題?と思いましたが,次は4月なので多分違う.

もしかしてOREGON 300は2019年のデータを扱えない?

20190105-03-01-15-1953320190105-03-01-23-19610

データはこんな感じで年月日と標高はおかしいですが,位置情報と時分秒は正しそうです.

$ grep trkpt ~/Nextcloud_files.matoken.org/GPS/2019-01-01.gpx |head
<trkpt lat="31.254590" lon="130.854801"><ele>28.50</ele><time>1999-05-17T20:55:26Z</time></trkpt>
<trkpt lat="31.254776" lon="130.854894"><ele>29.46</ele><time>1999-05-17T20:55:31Z</time></trkpt>
<trkpt lat="31.254912" lon="130.854996"><ele>31.38</ele><time>1999-05-17T20:55:36Z</time></trkpt>
<trkpt lat="31.254953" lon="130.855057"><ele>31.38</ele><time>1999-05-17T20:55:39Z</time></trkpt>
<trkpt lat="31.255113" lon="130.855215"><ele>33.30</ele><time>1999-05-17T20:55:46Z</time></trkpt>
<trkpt lat="31.255165" lon="130.855251"><ele>33.30</ele><time>1999-05-17T20:55:48Z</time></trkpt>
<trkpt lat="31.255219" lon="130.855322"><ele>34.26</ele><time>1999-05-17T20:55:51Z</time></trkpt>
<trkpt lat="31.255249" lon="130.855343"><ele>35.23</ele><time>1999-05-17T20:55:54Z</time></trkpt>
<trkpt lat="31.255276" lon="130.855375"><ele>34.74</ele><time>1999-05-17T20:55:56Z</time></trkpt>
<trkpt lat="31.255384" lon="130.855460"><ele>35.71</ele><time>1999-05-17T20:56:01Z</time></trkpt>
$ grep trkpt ~/Nextcloud_files.matoken.org/GPS/2019-01-01.gpx |tail
<trkpt lat="31.253258" lon="130.851111"><ele>138.09</ele><time>1999-05-18T03:57:15Z</time></trkpt>
<trkpt lat="31.253231" lon="130.851065"><ele>137.61</ele><time>1999-05-18T03:57:16Z</time></trkpt>
<trkpt lat="31.253209" lon="130.851040"><ele>136.64</ele><time>1999-05-18T03:57:17Z</time></trkpt>
<trkpt lat="31.253189" lon="130.851033"><ele>135.68</ele><time>1999-05-18T03:57:19Z</time></trkpt>
<trkpt lat="31.253162" lon="130.851021"><ele>137.13</ele><time>1999-05-18T03:57:22Z</time></trkpt>
<trkpt lat="31.253105" lon="130.850987"><ele>136.64</ele><time>1999-05-18T03:57:30Z</time></trkpt>
<trkpt lat="31.253046" lon="130.850972"><ele>136.64</ele><time>1999-05-18T03:57:36Z</time></trkpt>
<trkpt lat="31.253009" lon="130.850969"><ele>136.16</ele><time>1999-05-18T03:57:41Z</time></trkpt>
<trkpt lat="31.252981" lon="130.850972"><ele>136.64</ele><time>1999-05-18T03:57:48Z</time></trkpt>
<trkpt lat="31.252978" lon="130.850982"><ele>136.64</ele><time>1999-05-18T03:57:54Z</time></trkpt>

標高はとりあえず置いておいてsedで年月日差し替えでとりあえず写真にジオタグを付けたりするのに使えました.

$ sed -e "s/1999-05-1[7|8]/2018-12-31/g" 2019-01-01.gpx > 2019-01-01-tr.gpx

10年前の機械だからもう駄目なんだろうかと思いながらOREGON 300のFirmwareのバージョンを見ると3.01でした.

83

最新のFirmwareを確認すると4.20のようです.今回の件は見当たりませんがいろいろと改善されているようなので今回の件が治らないにしてもアップデートしておいたほうが良さそうです.

Changes made from version 4.10 to 4.20:
Updated magnetic Earth data
Improved GPS performance
Improved support for BirdsEye™ Satellite Imagery (each provider's imagery can be configured independently)
Increased the maximum number of supported JNX files to 250 from 200
Fixed issues with WAAS/EGNOS
Fixed issue with track navigation sometimes not adding waypoints to the Active Route list
Fixed issue with MPC map labels disappearing
Fixed shutdown on the map page when you have a geocache dashboard active and return after pressing the geocache name
Fixed issue with photo viewer not displaying correctly
Fixed issue with 3D view
Fixed issue with track navigation not adding waypoints to the Active Route list when they are exactly equal to a track point
Fixed shutdown when the device had more than the maximum number of JNX files on it
Fixed shutdown related to topographical maps and land cover text size
Fixed shutdown associated with certain custom POI files
Fixed Glide Ratio to Destination field
Fixed an issue related to adding a geocache as a point in a route
Fixed an issue with magnetic north reference and waypoint headings
Modified the 'Arriving at Destination' message banner so that it no longer appears when navigating to a geocache
Changes made from version 4.00 to 4.10:
Added support for chirp™ (Oregon 300, Oregon 400).
Fixed problem with certain custom maps.
Changes made from version 3.90 to 4.00:
Fixed issue on 3D View where vehicle could move after using the map.
Fixed issue on map page where back button would jump to the main menu.
Fixed issues with odometer distance.
Fixed shutdown while panning the map for extended periods of time.
Changes made from version 3.80 to 3.90:
Added ability to set user declination direction
Added Automatic Shaded Relief option
Added brightness adjustments for BirdsEye imagery
Added Geocache filtering. Select Setup > Geocaches to add custom filters
Added multicaching support
Improved WAAS performance
Fixed elevation profiles to always use the most detailed DEM data loaded
Fixed issue with calculator % function
Fixed issue with map POI's showing twice for a single point
Fixed issue with Oblique Mercator User grid
Fixed occasional shutdowns
Fixed spot sounding display on certain maps
Changes made from version 3.70 to 3.80:
Added BirdsEye control to profiles.
Added screen calibration option to Oregon 200.
Fixed issue changing marine modes.
Fixed map display problems.
Changes made from version 3.60 to 3.70:
Added support for Garmin BirdsEye.
Added mmHg pressure units.
Added ability to change active track color.
Added option to calibrate screen under Setup->Display.
Changes made from version 3.50 to 3.60:
Increased the map drawing range to allow maps to draw farther south.
Corrected issue with route line sometimes not drawing.
Corrected issues with marine POI.
Corrected issues with GB Discoverer maps.
Corrected issue with project waypoint bearing sometimes not showing the input value.
Changes made from version 3.40 to 3.50:
Added ability to view elevation plot of upcoming active route or currently navigated track in blue.
Added display of icons to the lists in Where To? > Waypoints and the Geocaching application.
Added phone numbers when available to POI review pages.
Added Compass, Stopwatch, Active Geocache, and Elevation Plot dashboard options.
Introduced dashboard options to the Compass and Map pages.
Improved track navigation.Visit http://garmin.blogs.com/softwareupdates/trail-tech/ for more information.
Changes made from version 3.30 to 3.40:
Added profile support for Garmin Custom Maps
Fixed lockup while using GB Discoverer maps
Changes made from version 3.20 to 3.30:
Added support for Garmin Custom Maps
Improved along road routing performance
Changes made from version 3.10 to 3.20:
Added LKS92 map datum
Added support for GPS firmware 3.70
Added support for GPI routes
Improved compass responsiveness
Fixed potential shutdown related to drawing 32-bit map points
Fixed potential issues during power on.
Changes made from version 2.80 to 3.10:
Added Waypoint Averaging application (For more information visit our new Trail Tech website at http://garmin.blogs.com/softwareupdates/trail-tech/)
Added Sight 'N Go application for the Oregon 300/400i/400c/400t
Added Man Overboard application
Added big numbers option to the trip computer
Added customizable text to unit power-on screen (see \Garmin\startup.txt)
Added ability to load maps from any img file in the Garmin directory
Added new trip computer dashboards
Added option to display four configurable data fields on the map
Added 'search near' option to Geocaches search
Added the ability to view geocache logs separate from the description
Added ability to see a list of points from the map when several points are at the same location
Added ability to edit a waypoint from the waypoint review
Added support for Custom POI database and category selection
Added distance and bearing to point when reviewing a Custom POI
Added POI subcategories
Added change location to Sun and Moon
Added change location to Hunt and Fish
Added ability to force the Oregon into mass storage mode by holding the power button for 30 seconds while plugged into a USB cable
Added NMEA 9600 baud
Improved render quality of GB Discoverer maps and maps with satellite imagery
Improved map zooming
Improved map draw speed
Improved map panning and zooming when shaded relief is turned on
Improved automatic route recalculation
Improved Custom POI spell search
Improved Main Menu setup and added option to add and remove items
Improved readability of configurable data fields
Improved display of numeric degrees and mils
Improved GPS performance at slow speeds in tree cover
Improved compass responsiveness in challenging GPS environments
Improved battery gage for NiMH batteries
Improved stability when changing profiles
Improved Wherigo stability
Improved connection reliability with Spanner
Improved Spanish keyboard
Fixed airport points not displaying on the map
Fixed lockup when a search returns no results
Fixed elevation errors when reviewing a point other than a waypoint
Increased the number of waypoints viewable from the Waypoint Manager and Where To?>Waypoints

しかしアップデートにはWindows端末が必要で今まともな実機がないので面倒…….
仮想環境のWindows 10 Pro 64bitを使ってアップデートできました.

20190106-17-01-39-2952720190106-17-01-36-10392

120

ちなみに今 $11.80 でWindows 10 Pro OEM ライセンスがセールしてたりするので環境がない人はこれを買って仮想環境に入れとくと今回みたいなときに便利です.

そして庭に出て測位してログを確認したら正しい日付のログが録れていました :)

20190106-17-01-14-2114220190106-17-01-19-21289

しかし大分古いので新しいQZSS対応あたりの世代のOREGONとか欲しいですね.
OREGON だと600以降かな?カメラはいらないので600/600t/700?

環境

$ uname -m
x86_64
$ lsb_release -rd
Description:    Debian GNU/Linux buster/sid
Release:        unstable
$ dpkg-query -W gpsprune gpsbabel
gpsbabel        1.5.4-2
gpsprune        19.2-1

GNOME Terminalの設定を初期化

GNOME 環境での標準端末の GNOME Terminal の設定の初期化をしました.~/.local あたりに設定ファイルがあるのかと思ったら dconfデータベースの中にあるようです.

場所は /org/gnome/terminal/ で,dconf コマンドなどで確認できます.

$ dconf dump /org/gnome/terminal/
[legacy/profiles:/:b1dcc9dd-5262-4d8d-a863-c897e6d979b9]
background-color='rgb(0,0,0)'
use-theme-colors=false
foreground-color='rgb(0,255,0)'
use-system-font=false
font='Fira Code 11'

このように reset すると設定が初期化されます.

$ dconf reset -f /org/gnome/terminal/

設定の反映は即時でGNOME Terminal 上で実行するとちょっとびっくりします.

#Youtube BAN されたのでBitChuteを試してみる.

環境

$ uname -m
x86_64
$ lsb_release -dr
Description: Ubuntu Disco Dingo (development branch)
Release: 19.04
$ dpkg-query -W gnome-terminal xterm dconf-cli
dconf-cli 0.30.1-2
gnome-terminal 3.30.1-1ubuntu1
xterm 330-1ubuntu3

Nextcloud を 15 にアップグレードしようとしてコケる

20181212_05:12:42-18746

Nextcloud 15 がリリースされました.

14.0.4 からアップグレードしようとしましたが失敗しました.そのメモです.

$ sudo -u www-data php7.0 ./occ upgrade
Nextcloud or one of the apps require upgrade - only a limited number of commands are available
You may use your browser or the occ upgrade command to do the upgrade
Set log level to debug
Updating database schema
Updated database
UnexpectedValueException: The files of the app "user_external" were not correctly replaced before running the update
Update failed
Maintenance mode is kept active
Reset log level

整合性が保たれていないようなので手動でアーカイブを入手して比較すると同じに見える

$ wget https://download.nextcloud.com/server/releases/nextcloud-15.0.0.tar.bz2 https://download.nextcloud.com/server/releases/nextcloud-15.0.0.tar.bz2.asc
$ gpg --verify ./nextcloud-15.0.0.tar.bz2.asc
gpg: 署名されたデータが'./nextcloud-15.0.0.tar.bz2'にあると想定します 
gpg: 2018年12月10日 19時27分11秒 JSTにRSA鍵ID A724937Aで施された署名
gpg: "Nextcloud Security <security@nextcloud.com>"からの正しい署名
gpg: *警告*: この鍵は信用できる署名で証明されていません!
gpg:          この署名が所有者のものかどうかの検証手段がありません。 
主鍵フィンガー・プリント: 2880 6A87 8AE4 23A2 8372  792E D758 99B9 A724 937A
$ tar tvf ./nextcloud-15.0.0.tar.bz2 | lv
$ tar xf ./nextcloud-15.0.0.tar.bz2
$ sudo -u www-data rsync -acvvn ./nextcloud/apps/user_external /var/www/home.matoken.org/nextcloud/apps/
sending incremental file list
delta-transmission disabled for local transfer or --whole-file
user_external/
user_external/appinfo/app.php is uptodate
user_external/appinfo/database.xml is uptodate
user_external/appinfo/info.xml is uptodate
user_external/appinfo/signature.json is uptodate
user_external/img/app.svg is uptodate
user_external/lib/base.php is uptodate
user_external/lib/ftp.php is uptodate
user_external/lib/imap.php is uptodate
user_external/lib/smb.php is uptodate
user_external/lib/webdavauth.php is uptodate
total: matches=0  hash_hits=0  false_alarms=0 data=0

sent 515 bytes  received 587 bytes  2,204.00 bytes/sec
total size is 19,690  speedup is 17.87 (DRY RUN)

このあたりのバグぽい

ちなみに user_external はFTP, IMAP, SMB の認証周りのよう.

Authenticate user login against FTP, IMAP or SMB.

とりあえず該当の user_external を無効にしてアップグレードは通った

$ sudo -u www-data php7.0 ./occ app:disable user_external
$ sudo -u www-data php7.0 ./occ upgrade

通ったけど無効にしていても怒られる

Some files have not passed the integrity check. Further information on how to resolve this issue can be found in the documentation. (List of invalid files… / Rescan…)

Technical information
=====================
The following list covers which files have failed the integrity check. Please read
the previous linked documentation to learn more about the errors and how to fix
them.

Results
=======
- user_external
    - EXTRA_FILE
        - user_external/appinfo/signature.json

Raw output
==========
Array
(
    [user_external] => Array
        (
            [EXTRA_FILE] => Array
                (
                    [user_external/appinfo/signature.json] => Array
                        (
                            [expected] => 
                            [current] => 37efcee67605ab01a595df9b8e37a63f0260a8d795cb4af9b1b40e137ace928193747445954b22455fcbfd1758ea9b663153afc73438f5370725682e344c8723
                        )

                )

        )

)

まだ非対応アプリも多いしメイン環境は暫く待ったほうが良さそうな感じです.

環境

$ sudo -u www-data php7.0 ./occ status -v
  - installed: true
  - version: 15.0.0.10
  - versionstring: 15.0.0
  - edition: 
$ lsb_release -d
Description:    Ubuntu 16.04.5 LTS
$ uname -m
x86_64