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

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

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

pdfファイルから画像を抜き出し( pdfimages or LibreOffice )

ここ2,3日で数回使ったのでメモしておきます.

poppler-utilsのpdfimagesを使う

概要
$ apt show poppler-utils | grep Description: -A99

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

Description: PDF 向けユーティリティ (Poppler ベース)
 Poppler は xpdf PDF ビューアを基に作られた PDF 描画ライブラリです。
 .
 本パッケージには (Poppler ベースの) コマンドラインユーティリティが含まれ、
 PDF 文書の情報の取得、他の形式への変換、編集ができます。
  * pdfdetach -- 埋め込みファイル (添付ファイル) の一覧出力または抽出
  * pdffonts -- フォント分析ツール
  * pdfimages -- 画像抽出ツール
  * pdfinfo -- 文書情報
  * pdfseparate -- ページ抽出ツール
  * pdfsig -- デジタル署名の検証
  * pdftocairo -- PDF から PNG/JPEG/PDF/PS/EPS/SVG への Cairo を使った変換ツール
  * pdftohtml -- PDF から HTML への変換ツール
  * pdftoppm -- PDF から PPM/PNG/JPEG 画像への変換ツール
  * pdftops -- PDF から PostScript (PS) への変換ツール
  * pdftotext -- テキストの抽出
  * pdfunite -- 文書の併合ツール
導入
$ sudo apt install poppler-utils
usage
$ pdfimages
pdfimages version 0.69.0
Copyright 2005-2018 The Poppler Developers - http://poppler.freedesktop.org
Copyright 1996-2011 Glyph & Cog, LLC
Usage: pdfimages [options] <PDF-file> <image-root>
  -f <int>       : first page to convert
  -l <int>       : last page to convert
  -png           : change the default output format to PNG
  -tiff          : change the default output format to TIFF
  -j             : write JPEG images as JPEG files
  -jp2           : write JPEG2000 images as JP2 files
  -jbig2         : write JBIG2 images as JBIG2 files
  -ccitt         : write CCITT images as CCITT files
  -all           : equivalent to -png -tiff -j -jp2 -jbig2 -ccitt
  -list          : print list of images instead of saving
  -opw <string>  : owner password (for encrypted files)
  -upw <string>  : user password (for encrypted files)
  -p             : include page numbers in output file names
  -q             : don't print any messages or errors
  -v             : print copyright and version info
  -h             : print usage information
  -help          : print usage information
  --help         : print usage information
  -?             : print usage information
pdfファイル内の画像リスト確認
$ pdfimages ./bicycle_parking.pdf -list
page   num  type   width height color comp bpc  enc interp  object ID x-ppi y-ppi size ratio
--------------------------------------------------------------------------------------------
   1     0 image     340   120  rgb     3   8  image  no         5  0   221   221 9576B 7.8%
   1     1 image     960   720  rgb     3   8  jpeg   yes       14  0   170   170 64.2K 3.2%
pdfファイルから画像抜き出し既定値では.ppm形式
$ pdfimages ./bicycle_parking.pdf ./bicycle_parking-images
$ ls -l ./bicycle_parking-images*
-rw-r--r-- 1 matoken matoken  122415 11月 12 21:40 ./bicycle_parking-images-000.ppm
-rw-r--r-- 1 matoken matoken 2073615 11月 12 21:40 ./bicycle_parking-images-001.ppm
$ identify ./bicycle_parking-images-000.ppm
./bicycle_parking-images-000.ppm PPM 340x120 340x120+0+0 8-bit sRGB 122415B 0.000u 0:00.000
png形式に変換して保存
$ pdfimages ./bicycle_parking.pdf ./bicycle_parking-images -png
$ ls -l ./bicycle_parking-images*
-rw-r--r-- 1 matoken matoken  10274 11月 12 21:46 ./bicycle_parking-images-000.png
-rw-r--r-- 1 matoken matoken 321115 11月 12 21:46 ./bicycle_parking-images-001.png
$ identify ./bicycle_parking-images-000.png
./bicycle_parking-images-000.png PNG 340x120 340x120+0+0 8-bit sRGB 10274B 0.000u 0:00.000
jpegファイルはjpegとして保存(それ以外はppm)
$ pdfimages ./bicycle_parking.pdf ./bicycle_parking-images -j
$ ls -l ./bicycle_parking-images*
-rw-r--r-- 1 matoken matoken 122415 11月 12 21:48 ./bicycle_parking-images-000.ppm
-rw-r--r-- 1 matoken matoken  65695 11月 12 21:48 ./bicycle_parking-images-001.jpg

LibreOfficeでOpenDocumentFormatに変換して画像だけ抜き出し

OpenDocumentFormatはzip形式で圧縮されてその中に画像ファイルも含まれるのでDraw形式に変換して画像ディレクトリの格納されている Pictures だけ展開すると画像が取り出せる.

導入はディストリビューションのほかFlatpack, snapなども公式で配布されているのでお好みで.今回は Debian sid amd64 でapt installしたもの.

$ libreoffice --headless --nologo --nofirststartwizard --convert-to odg ./bicycle_parking.pdf
convert /home/matoken/Downloads/bicycle_parking.pdf -> /home/matoken/Downloads/bicycle_parking.odg using filter : draw8
$ unzip ./bicycle_parking.odg Pictures/*
Archive:  ./bicycle_parking.odg
 extracting: Pictures/10000000000003C0000002D0136E1A08DF8E2B28.jpg
 extracting: Pictures/100000000000015400000078BA7345C344D8D008.png
$ ls -lA Pictures/
合計 80
-rw-r--r-- 1 matoken matoken 10812 11月 12 12:56 100000000000015400000078BA7345C344D8D008.png
-rw-r--r-- 1 matoken matoken 65695 11月 12 12:56 10000000000003C0000002D0136E1A08DF8E2B28.jpg
$ identify Pictures/*
Pictures/100000000000015400000078BA7345C344D8D008.png PNG 340x120 340x120+0+0 8-bit sRGB 10812B 0.000u 0:00.000
Pictures/10000000000003C0000002D0136E1A08DF8E2B28.jpg JPEG 960x720 960x720+0+0 8-bit sRGB 65695B 0.000u 0:00.000

環境

$ dpkg-query -W poppler-utils unzip libreoffice imagemagick
imagemagick     8:6.9.10.14+dfsg-7
libreoffice     1:6.1.3-1
poppler-utils   0.69.0-2
unzip   6.0-21
$ lsb_release -d
Description:    Debian GNU/Linux unstable (sid)
$ uname -m
x86_64

Googleの社名変更で apt update エラー

パッケージ情報更新のために apt update 中にエラーが発生しました.Googleのアプリケーション(Google Chrome等)を導入ししたときに入るGoogleのリポジトリで Google, Inc.Google LLC に変わったためのようです.

E: Repository 'http://dl.google.com/linux/chrome/deb stable Release' changed its 'Origin' value from 'Google, Inc.' to 'Google LLC'
N: This must be accepted explicitly before updates for this repository can be applied. See apt-secure(8) manpage for details.
Do you want to accept these changes and continue updating from this repository? [y/N]

Google LCCには去年変わっていてこのリポジトリにもやっと修正が入ったということのようです.(Androidアプリなどはもっと早かったですね)

ここで y で受け入れると次からこのエラーは現れません.

ヒット:4 http://dl.google.com/linux/chrome/deb stable Release
環境1
$ dpkg-query -W apt
apt     1.7.0
$ lsb_release -d
Description:    Debian GNU/Linux unstable (sid)
$ uname -m
x86_64
環境2
$ dpkg-query -W apt
apt     1.7.0
$ lsb_release -d
Description:    Parrot 4.3
$ uname -m
x86_64

壊れたzipファイルからデータを復旧する

Flickrからダウンロードしたアーカイブがダウンロードに失敗したのか内容が見られないです.
アーカイブが壊れている場合 -F でどうにかなりそう?

$ zip -l data-download-1.zip
		zip warning: missing end signature--probably not a zip file (did you
		zip warning: remember to use binary mode when you transferred it?)
		zip warning: (if you are trying to read a damaged archive try -F)

zip error: Zip file structure invalid (data-download-1.zip)

-F では駄目で -FF を試してみる

$ zip -F data-download-1.zip --out data-download-1_fix.zip
Fix archive (-F) - assume mostly intact archive
		zip warning: bad archive - missing end signature
		zip warning: (If downloaded, was binary mode used?  If not, the
		zip warning:  archive may be scrambled and not recoverable)
		zip warning: Can't use -F to fix (try -FF)

zip error: Zip file structure invalid (data-download-1.zip)

-FF である程度救える感じ

$ zip -FF data-download-1.zip --out data-download-1_fix.zip
Fix archive (-FF) - salvage what can
		zip warning: Missing end (EOCDR) signature - either this archive
					 is not readable or the end is damaged
Is this a single-disk archive?  (y/n): y
  Assuming single-disk archive
Scanning for entries...
 copying: img_20140426_180357_13952989767_o.jpg  (1935629 bytes)
 copying: img_20140723_180327_14575993850_o.jpg  (2639807 bytes)
 copying: img_20140723_180323_14576035839_o.jpg  (3302817 bytes)
 copying: img_20140723_180400_14576043890_o.jpg  (3611376 bytes)
   :
 copying: imgp1491_15854514735_o.jpg
		zip warning: no end of stream entry found: imgp1491_15854514735_o.jpg
		zip warning: rewinding and scanning for later entries

こういう耐障害性は非圧縮tarやafioとかのほうが強いでしょうがWindowsなんかでは多分標準で扱えないしダウンロードに失敗した場合は再度試みることが出来るのでやっぱzipでいいのかな.

ちなみに今回はFlickrから同じファイルを3回ダウンロードしても全部同じ内容で壊れていたので恐らくFlickr側で壊れているなてことでデータを再リクエストしました…….

環境
$ dpkg-query -W zip tar afio
afio    2.5.1.20160103+gitc8e4317-1
tar     1.30+dfsg-2
zip     3.0-11+b1
$ lsb_release -d
Description:    Debian GNU/Linux unstable (sid)
$ uname -m
x86_64

Googleドライブにコマンドラインでアクセスするskickaを試す

Googleドライブにコマンドラインでアクセスできる skicka を少し試してみました.

GOPATHを設定していない場合設定
$ GOPATH=~/go
$ PATH=${PATH}:~/go/bin
skickaの導入
$ go get github.com/google/skicka

skickaの設定を行います.
init コマンドで設定ファイルを生成します.
設定ファイルは ~/.skicka.config として作れれます.
次にlsコマンドを発行します.初回実行時にはウェブブラウザが起動して認証処理が走ります.許可すると自動的に認証が完了してls処理が走ります.
認証情報は`~/.skicka.tokencache.json` に保存されます.
ls実行時に次回以降のためにメタデータを作成します.ファイルが多いと時間がかかります.プログレスが表示されるのでしばらく待ちましょう.
メタデータは ~/.skicka.metadata.cache に保存されます.

skickaの初期設定
$ skicka init
$ skicka ls

サーバなどでウェブブラウザを起動するのが難しい場合は -no-browser-authls コマンドの に付けて起動すると認証URLが表示されるのでそれを操作PCなどで開いて認証を行い,表示された認証コードをコマンドラインに貼り付けます.

$ skicka -no-browser-auth ls
Go to the following link in your browser:
https://accounts.google.com/o/oauth2/auth?client_id=952283912845-sjotrejbktpinel08hrnspl33d8gho1e.apps.googleusercontent.com&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&response_type=code&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive&state=st1541320926479298710
Enter verification code: 4/iwBrjQFEvm2p0nQGXJuRQgTZFZZ6BmXkT7Up7Wl3UYS7NWEyiltTc6E
Usage
$ ~/go/bin/skicka
usage: skicka [skicka options] <command> [command options]

Supported commands are:
  cat       Print the contents of the given file
  download  Download a file or folder hierarchy from Drive to the local disk
  df        Display free space on Drive
  du        Report disk usage for a folder hierarchy on Drive
  fsck      Check consistency of files in Drive and local metadata cache
  genkey    Generate a new encryption key
  init      Create an initial skicka configuration file
  ls        List the contents of a folder on Google Drive
  mkdir     Create a new folder or folder hierarchy on Drive
  rm        Remove a file or folder on Google Drive
  upload    Upload a local file or directory hierarchy to Drive

'skicka help' prints more detailed documentation.
help
$ ~/go/bin/skicka help                                                                                                             [45/2151]
skicka is a tool for working with files and folders on Google Drive.
See http://github.com/google/skicka/README.md for information about getting started.

usage: skicka [common options] <command> [command options]

Commands and their options are:
  cat        Print the contents of the Google Drive file to standard output.
             Arguments: drive_path ...

  download   Recursively download either a single file, or all files from a
             Google Drive folder to a local directory. If the corresponding
             local file already exists and has the same contents as the its
             Google Drive file, the download is skipped.
             Arguments: [-ignore-times] [-download-google-apps-files]
                        drive_path local_path

  df         Prints the total space used and amount of available space on
             Google Drive.

  du         Print the space used by the Google Drive folder and its children.
             Arguments: [drive_path ...]

  fsck       [EXPERIMENTAL/NEW] Use at your own risk.
             Perform a number of consistency checks on files stored in Google
             Drive, including verifying metadata and removing duplicate files
             with the same name.
             Arguments: [--trash-duplicates] [drive_path]

  help       Print this help text.

  genkey     Generate a new key for encrypting files.

  init       Create an initial ~/.skicka.config configuration file. (You
             will need to edit it before using skicka; see comments in the
             configuration file for details.)

  ls         List the files and directories in the given Google Drive folder.                                                                          [8/2151]
             Arguments: [-d, -l, -ll, -r] [drive_path ...],
             where -l and -ll specify long (including sizes and update
             times) and really long output (also including MD5 checksums),
             respectively.  The -r argument causes ls to recursively list
             all files in the hierarchy rooted at the base directory, and
             -d causes directories specified on the command line to be
             listed as files (i.e., their contents aren't listed.)

  mkdir      Create a new directory (folder) at the given Google Drive path.
             Arguments: [-p] drive_path ...,
             where intermediate directories in the path are created if -p is
             specified.

  rm         Remove a file or directory at the given Google Drive path.
             Arguments: [-r, -s] drive_path ...,
             where files and directories are recursively removed if -r is
             specified and the google drive trash is skipped if -s is
             specified. The default behavior is to fail if the drive path
             specified is a directory and -r is not specified, and to send
             files to the trash instead of permanently deleting them.

  upload     Uploads all files in the local directory and its children to the
             given Google Drive path. Skips files that have already been
             uploaded.
             Arguments: [-ignore-times] [-encrypt] [-follow-symlinks <maxdepth>]
                        local_path drive_path

Options valid for both "upload" and "download":
  -dry-run         Don't actually upload or download, but print the paths of
                   all files that would be transferred.
  -ignore-times    Normally, skicka assumes that if the timestamp of a local
                   file matches the timestamp of the file on Drive and the
                   files have the same size, then it isn't necessary to
                   confirm that the file contents match. The -ignore-times
                   flag can be used to force checking file contents in this
                   case.

General options valid for all commands:
  -config <filename>     General skicka configuration file. Default: ~/.skicka.config.
  -debug                 Enable debugging output.
  -dump-http             Dump http traffic.
  -metadata-cache-file <filename>
                         File to store metadata about Google Drive contents.
                         Default: ~/.skicka.metadata.cache
  -no-browser-auth       Disables attempting to open the authorization URL in a web
                         browser when initially authorizing skicka to access Google Drive.
  -quiet                 Suppress non-error messages.
  -tokencache <filename> OAuth2 token cache file. Default: ~/.skicka.tokencache.json.
  -verbose               Enable verbose output.
ファイルのアップロード
$ skicka upload ~/Pictures/$(ls -tr1 ~/Pictures/|tail -1) /
Files:  14.41 KiB / 14.41 KiB [====================================================================================================================] 100.00% 3s
2018/11/04 17:45:32 Preparation time 1s, sync time 3s
2018/11/04 17:45:32 Updated 1 Drive files, 0 local files
2018/11/04 17:45:32 14.41 kiB read from disk, 0 B written to disk
2018/11/04 17:45:32 14.41 kiB uploaded (3.98 kiB/s), 0 B downloaded (0 B/s)
2018/11/04 17:45:32 52.08 MiB peak memory used
ファイルを確認
$ skicka ls|grep jpg
20180307_23:03:21-10889.jpg
20180307_23:03:21-10889.jpg
20181104_17:11:45-30082.jpg
ファイルのダウンロード
$ skicka rm 20181104_17:11:45-30082.jpg
$ diff ~/Pictures/20181104_17:11:45-30082.jpg /tmp/20181104_17:11:45-30082.jpg
$ ls -l ~/Pictures/20181104_17:11:45-30082.jpg /tmp/20181104_17:11:45-30082.jpg
-rw-r--r-- 1 matoken matoken 14760 11月  4 17:41 /home/matoken/Pictures/20181104_17:11:45-30082.jpg
-rw-r--r-- 1 matoken matoken 14760 11月  4 17:41 /tmp/20181104_17:11:45-30082.jpg
ファイルの削除
$ skicka rm /20181104_17:11:45-30082.jpg

skickaには暗号化機能があります.upload時に -encrypt オプションを付与することによりファイルを暗号化してGoogleドライブに保存できます.そのためには準備が必要です.
SKICKA_PASSPHRASE という環境変数にパスフレーズを設定した状態で,skicka genkey を実行して生成された情報を設定ファイルの ~/.skicka.config に書き込みます.

暗号化のためのkey等を生成する(環境変数はexportしないと認識しなかった)
$ read -sp "skicka pass: " SKICKA_PASSPHRASE && export SKICKA_PASSPHRASE && skicka genkey
skicka pass: ; Add the following lines to the [encryption] section
; of your ~/.skicka.config file.
        salt=62cd4c08693c935f35c45be5261907127ef14055f197bb19bae36616fedecb54
        passphrase-hash=23f702efce4fe7bf775d3bc80f07e2a765589016b537bf322ed5e0c8f2f6ce90
        encrypted-key=463c9c75b3aa98e5401bb5fde6d681f8053d39d3e5ce49ef22bcc58977736162
        encrypted-key-iv=d2533e58f6c9bb976a66d499280ce8c2
設定ファイルに暗号化情報を書き込む(コメントを外すのを忘れずに)
$ vi ~/.skicka.config
$ grep -A5 encryption ~/.skicka.config
[encryption]
        ; Run 'skicka genkey' to generate an encyption key.
        salt=62cd4c08693c935f35c45be5261907127ef14055f197bb19bae36616fedecb54
        passphrase-hash=23f702efce4fe7bf775d3bc80f07e2a765589016b537bf322ed5e0c8f2f6ce90
        encrypted-key=463c9c75b3aa98e5401bb5fde6d681f8053d39d3e5ce49ef22bcc58977736162
        encrypted-key-iv=d2533e58f6c9bb976a66d499280ce8c2

upload時に -encrypt を指定すると暗号化され,.aes256 という拡張子付きで保存されます.

暗号化しながら保存する
$ skicka mkdir encryption
$ skicka upload -encrypt ~/Pictures/20181105_19\:11\:18-8911.jpg /encryption/
$ skicka ls /encryption/
20181105_19:11:18-8911.jpg.aes256

元のファイル名ではダウンロードできず,.aes256 拡張子付きのファイル名ではダウンロードできた.このファイルは .aes256 の拡張子付きのままだが,復号されている.

ダウンロード
$ skicka download /encryption/20181105_19:11:18-8911.jpg ./
skicka: /encryption/20181105_19:11:18-8911.jpg: not found on Drive
$ skicka download /encryption/20181105_19:11:18-8911.jpg.aes256 ./
$ file ./20181105_19\:11\:18-8911.jpg.aes256
./20181105_19:11:18-8911.jpg.aes256: JPEG image data, JFIF standard 1.01, aspect ratio, density 1x1, segment length 16, baseline, precision 8, 933x600, frames
3
$ identify ./20181105_19\:11\:18-8911.jpg.aes256
./20181105_19:11:18-8911.jpg.aes256 JPEG 933x600 933x600+0+0 8-bit sRGB 92988B 0.000u 0:00.000
$ display ./20181105_19\:11\:18-8911.jpg.aes256

ウェブブラウザからダウンロードしたファイルは暗号化されている.データ量は少し増えている.

$ file 20181105_19_11_18-8911.jpg.aes256.jpg.aes256
20181105_19_11_18-8911.jpg.aes256.jpg.aes256: data
$ ls -la 201811*
-rw-r--r-- 1 matoken matoken 92988 11月  5 19:30 20181105_19:11:18-8911.jpg.aes256
-rw-r--r-- 1 matoken matoken 93004 11月  5 21:46 20181105_19_11_18-8911.jpg.aes256.jpg.aes256
環境
$ dpkg-query -W golang git bash
bash    4.4.18-3.1
git     1:2.19.1-1
golang  2:1.10~5
$ lsb_release -d
Description:    Debian GNU/Linux unstable (sid)
$ uname -m
x86_64

特定プロセスのcpu利用率を制限するcpulimitを試す

先日mysqldump + xz 圧縮の間に pv を挟んで帯域制限をして xz の負荷を下げました.

しかしこの方法ではそんなに負荷がない mysqldump もずっと動かしっぱなしで db にもよろしく無いです.mysqldump は先に済ませて xz だけを制限することにします.

before
umask 0266 && nice -n 19 ionice -c 3 /usr/bin/mysqldump --defaults-file=/mnt/backup/micro/.my-backup.cnf --single-transaction --quick --all-databases --events | pv -L 128k 2>/dev/null | nice -n 19 ionice -c 3 /usr/bin/xz -9 > /mnt/backup/micro/`date +\%F_\%T_$$`.sql.xz
after
DUMP="/mnt/backup/micro/`date +\%F_\%T_$$`.sql"; umask 0266 && nice -n 19 ionice -c 3 /usr/bin/mysqldump --defaults-file=/mnt/backup/micro/.my-backup.cnf --single-transaction --quick --all-databases --events > ${DUMP} && pv -L 128k nice -n 19 ionice -c 3 /usr/bin/xz -9 > ${DUMP}.xz && rm ${DUMP}

一応動くけどcrontabなので1行で書いてあって見にくいしあまりいけてないですね.
せめてファイルに分けたほうが良さそう.

LimitCPU

pvでもいいのですが,cpu利用率を制限できないかなと思いました.xzのオプションでは見当たらずLinux環境なので cgroups で制限しようかとも思ったのですが, LimitCPU というものを見つけました.これは SIGSTOPSIGCONT のPOSIXシグナルをプロセスに送信することにより実現しているので,POSIX環境ならどこでも動きそうなのでこちらを試してみました.

LimitCPUはメンテされなくなったCPUlimitのフォークでコマンドやパッケージ名は cpulimit です.(混乱する><)

導入
$ sudo apt install cpulimit
usage
$ cpulimit -h
CPUlimit version 2.1
Usage: cpulimit TARGET [OPTIONS...] [-- PROGRAM]
   TARGET must be exactly one of these:
      -p, --pid=N        pid of the process
      -e, --exe=FILE     name of the executable program file
                         The -e option only works when
                         cpulimit is run with admin rights.
      -P, --path=PATH    absolute path name of the
                         executable program file
   OPTIONS
      -b  --background   run in background
      -c  --cpu=N        override the detection of CPUs on the machine.
      -l, --limit=N      percentage of cpu allowed from 1 up.
                         Usually 1 - 200, but can be higher
                         on multi-core CPUs (mandatory)
      -q, --quiet        run in quiet mode (only print errors).
      -k, --kill         kill processes going over their limit
                         instead of just throttling them.
      -r, --restore      Restore processes after they have
                         been killed. Works with the -k flag.
      -s, --signal=SIG   Send this signal to the watched process when cpulimit exits.
                         Signal should be specificed as a number or
                         SIGTERM, SIGCONT, SIGSTOP, etc. SIGCONT is the default.
      -v, --verbose      show control statistics
      -z, --lazy         exit if there is no suitable target process,
                         or if it dies
          --             This is the final CPUlimit option. All following
                         options are for another program we will launch.
      -h, --help         display this help and exit

制限はプロセスIDでの制限,プログラム名での制限,指定したプログラムを制限することが可能です.
cpuが複数ある場合は -l の値はcpu 1つあたり100として,100 * cpu数 を元に指定します.cpu 2つで 50% 利用したい場合は -l 100 になると思います.

プロセスID 1234 のプログラムをcpuを2つ利用,cpuを50%(2コアなので実際は100%分)
$ cpulimit -c 2 -p 1234 -l 50
xzというプログラムをcpu利用率を25%に制限
$ cpulimit -c 2 -l 50 - xz

※xzの前の - はなくてもいいが cpulimit のオプションの最後を示す.

cpuを1つだけ利用.cpu利用率を25%に制限しつつxzを実行できます.
$ cpulimit -c 1 -l 25 -z -  xz -9 datafile
  • -c : 利用するcpu数

  • -p : 制限するプロセスID

  • -l : 制限するcpu利用率

  • -z : 指定したプロセスが完了したらcpulimitも終了する(通常は関しを続けて同じ条件に一致するプロセスが現れたら制限する)

今回はxzを制限したいのでこんな感じに.
あまり変わりませんね…….

DUMP="/mnt/backup/micro/`date +\%F_\%T_$$`.sql"; umask 0266 && nice -n 19 ionice -c 3 /usr/bin/mysqldump --defaults-file=/mnt/backup/micro/.my-backup.cnf --single-transaction --quick --all-databases --events > ${DUMP} && nice -n 19 ionice -c 3 cpulimit -c1 -l 25 - /usr/bin/xz -9 ${DUMP}

バックアップ専用ユーザとして分けてあるのでそのユーザで cpulimit -c 1 -l 25 - xz とかしてxzという名前のプロセスを全部制限してしまうのもありかもしれません.monit とかで監視させればいい感じかも?そうすると,

DUMP="/mnt/backup/micro/`date +\%F_\%T_$$`.sql"; umask 0266 && nice -n 19 ionice -c 3 /usr/bin/mysqldump --defaults-file=/mnt/backup/micro/.my-backup.cnf --single-transaction --quick --all-databases --events > ${DUMP} && /usr/bin/xz -9 ${DUMP}

あまり変わりませんね…….

環境
$ dpkg-query -W cpulimit xz-utils
cpulimit        2.2-1
$ lsb_release -d
Description:    Ubuntu 16.04.5 LTS
$ uname -m
x86_64