Let’s Encryptの更新に失敗する

最近はこんな感じでLet’s Encryptの証明書の更新を更新しているのですが今回失敗しました.
(DocumenteRootをFQDNにしている前提)

$ sudo /bin/sh -c "/usr/bin/find /etc/letsencrypt/renewal/*.conf -type f | /usr/bin/xargs /usr/bin/basename -s .conf | xargs -n1 -I{} /usr/bin/letsencrypt renew --webroot -w /var/www/{}/ -d {}"

こんなふうに怒られます.
(仕様が変わった?)

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Currently, the renew verb is capable of either renewing all installed certificates that are due to be renewed or renewing a single certificate specified by its name. If you would like to renew specific certificates by their domains, use the certonly command. The renew verb may provide other options for selecting certificates to renew in the future.

とりあえずはletsencrypt renewletsencrypt certonlyにしたら通りました.

$ sudo /bin/sh -c "/usr/bin/find /etc/letsencrypt/renewal/*.conf -type f | /usr/bin/xargs /usr/bin/basename -s .conf | xargs -n1 -I{} /usr/bin/letsencrypt certonly --webroot -w /var/www/{}/ -d {}"

これで更新できたと思ったら1つのドメインで失敗しています.

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Cert is due for renewal, auto-renewing...
Renewing an existing certificate
Performing the following challenges:
http-01 challenge for files.matoken.org
Using the webroot path /var/www/files.matoken.org for all unmatched domains.
Waiting for verification...
Cleaning up challenges
Failed authorization procedure. files.matoken.org (http-01): urn:acme:error:unauthorized :: The client lacks sufficient authorization :: Invalid response from http://files.matoken.org/.well-known/acme-challenge/Be7Aiai4UH9CDqacTaEZOMH4SxSQbtFqxFcPXcCtJEs: "<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>404 Not Found</title>  
</head><body>
<h1>Not Found</h1>
<p"

IMPORTANT NOTES:
 - The following errors were reported by the server:

   Domain: files.matoken.org  
   Type:   unauthorized
   Detail: Invalid response from
   http://files.matoken.org/.well-known/acme-challenge/Be7Aiai4UH9CDqacTaEZOMH4SxSQbtFqxFcPXcCtJEs:
   "<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
   <html><head>
   <title>404 Not Found</title>
   </head><body>
   <h1>Not Found</h1>
   <p"

   To fix these errors, please make sure that your domain name was
   entered correctly and the DNS A record(s) for that domain
   contain(s) the right IP address.

ファイルをDoumentRootに置いてLet’s Encryptからアクセスされるのですがそこでそのファイルが見つからないと失敗しています.このドメインはhttpを設定していませんでした.
てことでapacheでRewriteの設定をしてあげると

RewriteEngine On
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,QSA,R=permanent]

通りました.

$ sudo /usr/bin/letsencrypt certonly --webroot -w /var/www/files.matoken.org/ -d files.mato
ken.org
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Cert is due for renewal, auto-renewing...
Renewing an existing certificate
Performing the following challenges:
http-01 challenge for files.matoken.org
Using the webroot path /var/www/files.matoken.org for all unmatched domains.
Waiting for verification...
Cleaning up challenges
Generating key (2048 bits): /etc/letsencrypt/keys/0003_key-certbot.pem
Creating CSR: /etc/letsencrypt/csr/0003_csr-certbot.pem

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at
   /etc/letsencrypt/live/files.matoken.org/fullchain.pem. Your cert
   will expire on 2018-05-31. To obtain a new or tweaked version of
   this certificate in the future, simply run certbot again. To
   non-interactively renew *all* of your certificates, run "certbot
   renew"
 - If you like Certbot, please consider supporting our work by:

   Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
   Donating to EFF:                    https://eff.org/donate-le

certbotのversionがかなり古いですね…….

$ dpkg -l|grep -i certbot
ii  certbot                               0.10.2-1                          all          automatically configure HTTPS using Let's Encrypt
ii  python-certbot                        0.10.2-1                          all          main library for certbot

てことでbackportのものに入れ替え.

$ sudo apt remove certbot
$ sudo apt install python-certbot-apache -t stretch-backports
$ apt show certbot
Package: certbot
Version: 0.21.1-1~bpo9+1
Priority: optional
Section: web
Source: python-certbot
Maintainer: Debian Let's Encrypt <letsencrypt-devel@lists.alioth.debian.org>
Installed-Size: 53.2 kB
Provides: letsencrypt
Depends: python3-certbot (= 0.21.1-1~bpo9+1), python3:any
Suggests: python3-certbot-apache, python3-certbot-nginx, python-certbot-doc
Breaks: letsencrypt (<= 0.6.0)
Replaces: letsencrypt
Homepage: https://certbot.eff.org/
Download-Size: 20.4 kB
APT-Manual-Installed: no
APT-Sources: http://ftp.jp.debian.org/debian stretch-backports/main amd64 Packages
Description: automatically configure HTTPS using Let's Encrypt
 The objective of Certbot, Let's Encrypt, and the ACME (Automated
 Certificate Management Environment) protocol is to make it possible
 to set up an HTTPS server and have it automatically obtain a
 browser-trusted certificate, without any human intervention. This is
 accomplished by running a certificate management agent on the web
 server.
 .
 This agent is used to:
 .
   - Automatically prove to the Let's Encrypt CA that you control the website
   - Obtain a browser-trusted certificate and set it up on your web server
   - Keep track of when your certificate is going to expire, and renew it
   - Help you revoke the certificate if that ever becomes necessary.
 .
 This package contains the main application, including the standalone
 and the manual authenticators.

N: There is 1 additional record. Please use the '-a' switch to see it

てことでclientが古かったのであまり参考になら無さそうなメモでした.

Devuan ascii armhf(Raspberry Pi)で時計合わせ

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をクリーンインストールすれば必要ない設定かも(未確認)

mysqlのdatadirを変更したらapparmorに怒られて起動しなくなった

ディスクの都合でmysqlのデータの置き場所を変更しました.
mysqldを停止して,データを移動して,シンボリックリンクも一応貼っておく.
/etc/mysql/mysql.conf.d/mysqld.cnfでdatadirを変更.

[mysqld]
datadir         = /export/data/var/lib/mysql

この状態でmysqlを起動するとこんな感じのエラーで起動しなくなってしまいました.

2018-02-17T16:12:54.184655Z 0 [ERROR] InnoDB: The innodb_system data file 'ibdata1' must be writable
2018-02-17T16:12:54.184718Z 0 [ERROR] InnoDB: The innodb_system data file 'ibdata1' must be writable
2018-02-17T16:12:54.184734Z 0 [ERROR] InnoDB: Plugin initialization aborted with error Generic error
2018-02-17T16:12:54.785643Z 0 [ERROR] Plugin 'InnoDB' init function returned error.
2018-02-17T16:12:54.786151Z 0 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
2018-02-17T16:12:54.786272Z 0 [ERROR] Failed to initialize builtin plugins.
2018-02-17T16:12:54.786415Z 0 [ERROR] Aborting

該当ファイルは一見問題無さそうに見えます.

$ sudo ls -la /export/data/var/lib/mysql/ibdata1
-rw-rw---- 1 mysql mysql 102760448  2月 18 05:15 /export/data/var/lib/mysql/ibdata1
$ sudo -u mysql dd if=/export/data/var/lib/mysql/ibdata1 bs=10 count=1|od -xc
1+0 レコード入力
1+0 レコード出力
10 bytes copied, 9.8366e-05 s, 102 kB/s
0000000    2214    405b    0000    0000    0000
        024   "   [   @  \0  \0  \0  \0  \0  \0
0000012

何でだ?と思ったらkernel logにこんなログが.apparmorで引っかかっているようです.

Feb 18 00:35:26 micro kernel: [ 3569.631324] audit: type=1400 audit(1518881726.300:24): apparmor="DENIED" operation="open" prof
ile="/usr/sbin/mysqld" name="/proc/18795/status" pid=18795 comm="mysqld" requested_mask="r" denied_mask="r" fsuid=114 ouid=114

/etc/apparmor.d/usr.sbin.mysqldでパスを変更します.

diff --git a/apparmor.d/usr.sbin.mysqld b/apparmor.d/usr.sbin.mysqld
index 2619e7d..adb8259 100644
--- a/apparmor.d/usr.sbin.mysqld   
+++ b/apparmor.d/usr.sbin.mysqld
@@ -46,16 +46,16 @@
   /usr/share/mysql/** r,  

 # Allow data dir access   
-  /var/lib/mysql/ r,
-  /var/lib/mysql/** rwk,  
+  /export/data/var/lib/mysql/ r,  
+  /export/data/var/lib/mysql/** rwk,

 # Allow data files dir access
-  /var/lib/mysql-files/ r,
-  /var/lib/mysql-files/** rwk,
+  /export/data/var/lib/mysql-files/ r,
+  /export/data/var/lib/mysql-files/** rwk,

 # Allow keyring dir access
-  /var/lib/mysql-keyring/ r,
-  /var/lib/mysql-keyring/** rwk, 
+  /export/data/var/lib/mysql-keyring/ r,
+  /export/data/var/lib/mysql-keyring/** rwk,

 # Allow log file access 
   /var/log/mysql.err rw,

この状態でapparmorを再起動して設定を反映してからmysqlを起動でOKでした.

$ sudo service apparmor restart
$ sudo service mysql start

この後iostat -xを眺めて大丈夫そうかなーって思ったのですがディスクアクセス音が大きくなったのでまた別の場所に移動するかも…….

環境

$ dpkg-query -W mysql-server
mysql-server    5.7.21-0ubuntu0.16.04.1
$ lsb_release -a
Distributor ID: Ubuntu
Description:    Ubuntu 16.04.3 LTS
Release:        16.04
Codename:       xenial
$ uname -m
x86_64

Debian sidのkernel.sysrqの値が変わった?

先日Debian sid amd64環境でprocpsの更新がありました.

$ apt show procps
Package: procps
Version: 2:3.3.12-4
Priority: important
Section: admin
Maintainer: Craig Small <csmall@debian.org>
Installed-Size: 712 kB
Provides: watch
Depends: libc6 (>= 2.15), libncurses5 (>= 6), libncursesw5 (>= 6), libprocps6, libtinfo5 (>= 6), lsb-base (>= 3.0-10), init-system-helpers (>= 1.29~)
Recommends: psmisc
Conflicts: pgrep (<< 3.3-5), w-bassman (<< 1.0-3)
Breaks: guymager (<= 0.5.9-1), open-vm-tools (<= 2011.12.20-562307-1)
Homepage: https://gitlab.com/procps-ng/procps
Tag: admin::monitoring, implemented-in::c, interface::commandline,
 interface::text-mode, role::program, scope::utility,
 uitoolkit::ncurses, use::checking, use::monitor,
 works-with::software:running
Download-Size: 251 kB
APT-Manual-Installed: yes
APT-Sources: http://ftp.jp.debian.org/debian sid/main amd64 Packages
Description: /proc ファイルシステムユーティリティ
 本パッケージは procfs を閲覧するためのコマンドラインおよび全画面のユーティ
 リティを提供します。procfs とは "擬似的な" ファイルシステムで、カーネルによ
 り動的に生成されます。カーネルのプロセステーブル内のエントリの状態に関する
 情報 (例えば、プロセスが稼働中、停止中、または "ゾンビ" である、など) が提
 供されます。
 .
 本パッケージには次のものが含まれます: free, kill, pkill, pgrep, pmap, ps,
 pwdx, skill, slabtop, snice, sysctl, tload, top, uptime, vmstat, w, watch。

更新に伴い/etc/sysctl.confの更新がありました.

設定ファイル '/etc/sysctl.conf'
 ==> これはインストールしてから (あなたかスクリプトによって) 変更されています。
 ==> パッケージ配布元が更新版を提供しています。
   どうしますか? 以下の選択肢があります:
    Y か I  : パッケージメンテナのバージョンをインストールする
    N か O  : 現在インストールされている自分のバージョンを残す
      D     : 両バージョンの差異を表示する
      Z     : 状況を調査するためにシェルを開始する
 デフォルトでは現在使っている自分のバージョンを残します。
*** sysctl.conf (Y/I/N/O/D/Z) [デフォルト=N] ? D

差分を見ると自分で編集した部分以外はコメントだけだったのですが,気になる項目が.

@@ -61,18 +61,13 @@

 ###################################################################
 # Magic system request Key
-# 0=disable, 1=enable all
-# Debian kernels have this set to 0 (disable the key)
-# See https://www.kernel.org/doc/Documentation/sysrq.txt
+# 0=disable, 1=enable all, >1 bitmask of sysrq functions
+# Debian kernels have this set to 438 which is the OR of:
+#  64 = enable signalling of processes
+#  128 = allow reboot/poweroff
+#  256 = allow nicing of all RT tasks
+#
+# See https://www.kernel.org/doc/html/latest/admin-guide/sysrq.html
 # for what other values do
-#kernel.sysrq=1
+#kernel.sysrq=438

Magic system request Keyの項目が以前は0 or 1で有効か無効化のみだったと思うのですが,細かく指定できるようになっているようです.

0 – disable sysrq completely
1 – enable all functions of sysrq
>1 – bitmask of allowed sysrq functions (see below for detailed function description):

てことでkernel.sysrq=438は16進数で0x1B6なので

$bc
obase=16
438
1B6

以下が有効ということのようです.

2 = 0x2 – enable control of console logging level
4 = 0x4 – enable control of keyboard (SAK, unraw)
16 = 0x10 – enable sync command
32 = 0x20 – enable remount read-only
128 = 0x80 – allow reboot/poweroff
256 = 0x100 – allow nicing of all RT tasks

無効になっているのは以下の項目.

8 = 0x8 – enable debugging dumps of processes etc.
64 = 0x40 – enable signalling of processes (term, kill, oom-kill)

kernel configを見るとこの項目になっています.少なくとも4.13.0-1〜4.14.13-1以降は同じみたい.

$ zgrep ONFIG_MAGIC_SYSRQ /boot/config-`uname -r`
CONFIG_MAGIC_SYSRQ=y
CONFIG_MAGIC_SYSRQ_DEFAULT_ENABLE=0x01b6
CONFIG_MAGIC_SYSRQ_SERIAL=y

ということでコメントが実際のkernelの項目と同じになったということみたいなので動作は変わらないようです.

追記)

昔使い方を知りたくて調べたときに見つけた文章は@miurahrさん翻訳のものでした.その後 で本人に遭遇.

porgを一般ユーザで利用する

porgを一般ユーザで利用するメモ

一般ユーザで普通に使おうとするとログ保存場所の/var/lib/porgへの権限がないと怒られてしまう.

$ porg -D ~/.porg -lp program-0.10.61 make install
porg: /var/lib/porg: Permission denied

ログ保存ディレクトリを指定すると行ける.

$ porg -L ~/.porg -lp program-0.10.61 make install

manより

   -L, --logdir=DIR
          Base log  directory.  The  logs  for  the  installed  packages  are  saved  in  this  directory.  Default  is
          '/var/lib/porg', unless variable LOGDIR is set in the configuration file (type 'man porgrc' for more informa‐
          tion).

--PREFIX=${HOME}/usrみたいな時向けに

version等

$ porg -V
porg-0.10 (17 May 2016)
Written by David Ricart <http://porg.sourceforge.net>
$ dpkg-query -W porg
porg    2:0.10-1.1

Btrfsでdfで空き容量があるように見えるのに容量が無いと言われてreadonlyにされてしまう

最近Btrfsで利用中にroにされてしまうという症状が起きます.
こんな感じで怒られてroになる.
dfは87%とかで未だ空きはあるように見える.
/に使ってるとこでremount,rwも効かず再起動しないと戻せず辛い.

[ 2196.878532] BTRFS: error (device dm-1) in btrfs_truncate_inode_items:4647: errno=-28 No space left
[ 2196.878537] BTRFS info (device dm-1): forced readonly
[ 2196.881248] BTRFS error (device dm-1): pending csums is 1241088

FAQだったようでここを参照しながら

別のsystemで確認してbtrfs fi balance start -dusage=5を叩いてみました.

$ sudo btrfs fi show
Label: none uuid: e54de82f-1fdb-4f9a-b529-0952b0ea3454
        Total devices 1 FS bytes used 465.89GiB
        devid 1 size 542.28GiB used 542.28GiB path /dev/mapper/x220--vg-root

$ sudo mount -o ro /dev/mapper/x220--vg-root /mnt
$ sudo btrfs fi df /mnt
Data, single: total=538.27GiB, used=462.41GiB
System, single: total=4.00MiB, used=80.00KiB
Metadata, single: total=4.01GiB, used=3.48GiB
GlobalReserve, single: total=512.00MiB, used=0.00B
$ sudo btrfs fi balance start -dusage=5 /mnt
ERROR: error during balancing '/mnt': Read-only file system
There may be more info in syslog - try dmesg | tail
$ sudo mount -o remount,rw /mnt
$ sudo btrfs fi balance start -dusage=5 /mnt
Done, had to relocate 0 out of 546 chunks

しかしあまり変わらず暫く利用しているとまたエラーに.しかし今度はdisk fullと怒られるけどroにはならなかったです.以下のページによると,

This means the bigger the -dusage value, the more work balance will have to do (i.e. taking fuller and fuller blocks and trying to free them up by putting their data elsewhere). Also, if your FS is 55% full, using -dusage=55 is ok, but there isn’t a 1 to 1 correlation and you’ll likely be ok with a smaller dusage number, so start small and ramp up as needed.

ということで-dusage=90にしてみると結構空いた感じです.
上の方では別systemで起動して実行しましたが,オンラインでも大丈夫でした.但し処理中はかなり重くなります.そして処理に200分程かかりました.

$ sudo btrfs fi balance start -dusage=90 /
Done, had to relocate 186 out of 530 chunks
$ sudo btrfs fi show
Label: none  uuid: e54de82f-1fdb-4f9a-b529-0952b0ea3454
        Total devices 1 FS bytes used 446.08GiB
        devid    1 size 542.28GiB used 449.27GiB path /dev/mapper/x220--vg-root

この後数GBのデータを書いてみたり溜まっていたapt upgradeとかしてみましたが今のところ大丈夫そうです.
ちなみにこのfsがあるSSD(INTEL SSDSA2CW600G3)も長く使っているのでそっちも心配だったのですが,smartctl-t longしたり-aの以下のあたり見る感じでは未だ行けそう?

9 Power_On_Hours 0x0032 100 100 000 Old_age Always – 36565
228 Workload_Minutes 0x0032 100 100 000 Old_age Always – 2193912
232 Available_Reservd_Space 0x0033 100 100 010 Pre-fail Always – 0
233 Media_Wearout_Indicator 0x0032 095 095 000 Old_age Always – 0

#適当なとこでsecure eraseしておきたい…….

Vivaldi 1.14にしたらARM64環境で動かなくなる

Vivaldi 1.14がリリースされました.

Note機能のMarkdown対応とか便利かもと以前の手順で導入しました.

依存関係が増えていたのでこんな感じで.

$ sudo dpkg -i ./vivaldi-stable_1.14.1077.41-1_armhf.deb
$ sudo apt install -f
$ apt show vivaldi-stable
Package: vivaldi-stable:armhf
Version: 1.14.1077.41-1
Status: install ok installed
Priority: optional
Section: web
Maintainer: Vivaldi Package Composer <packager@vivaldi.com>
Installed-Size: 136 MB
Provides: www-browser
Pre-Depends: dpkg (>= 1.14.0)
Depends: ca-certificates, fonts-liberation, gconf-service, libappindicator1, libasound2 (>= 1.0.16), libatk-bridge2.0-0 (>= 2.5.3), libatk1.0-0 (>= 1.12.4), libc6 (>= 2.16), libcairo2 (>= 1.6.0), libcups2 (>= 1.4.0), libdbus-1-3 (>= 1.2.14), libexpat1 (>= 2.0.1), libfontconfig1 (>= 2.11), libgcc1 (>= 1:3.5), libgconf-2-4 (>= 3.2.5), libgdk-pixbuf2.0-0 (>= 2.22.0), libglib2.0-0 (>= 2.31.8), libgtk-3-0 (>= 3.9.10), libnspr4 (>= 2:4.9-2~), libnss3 (>= 2:3.22), libpango-1.0-0 (>= 1.14.0), libpangocairo-1.0-0 (>= 1.14.0), libx11-6 (>= 2:1.4.99.1), libx11-xcb1, libxcb1 (>= 1.6), libxcomposite1 (>= 1:0.3-1), libxcursor1 (>> 1.1.2), libxdamage1 (>= 1:1.1), libxext6, libxfixes3, libxi6 (>= 2:1.2.99.4), libxrandr2 (>= 2:1.2.99.3), libxrender1, libxss1, libxtst6, wget, xdg-utils (>= 1.0.2)
Recommends: adobe-flashplugin, chromium-codecs-ffmpeg-extra
Homepage: https://vivaldi.com
Download-Size: 不明
APT-Manual-Installed: yes
APT-Sources: /var/lib/dpkg/status
Description: A new browser for our friends
 Vivaldi browser is made with power users in mind by people who love the Web.

N: 追加レコードが 2 件あります。表示するには '-a' スイッチを付けてください。

早速起動しましたが動きません.

$ vivaldi
ERROR: ld.so: object '/usr/lib/chromium-browser/libffmpeg.so' from LD_PRELOAD cannot be preloaded (wrong ELF class: ELFCLASS64): ignored.
/usr/bin/vivaldi: error while loading shared libraries: libffmpeg.so: cannot open shared object file: No such file or directory

Vivaldiはarmhfですが,aarch64の/usr/lib/chromium-browser/libffmpeg.soを読み込もうとしてコケているようです.
libffmpeg.soはVivaldiにもいるよう?

$ dpkg-query -S libffmpeg.so
chromium-codecs-ffmpeg-extra: /usr/lib/chromium-browser/libffmpeg.so
vivaldi-stable:armhf: /opt/vivaldi/lib/libffmpeg.so
$ ls -l /usr/lib/chromium-browser/libffmpeg.so /opt/vivaldi/lib/libffmpeg.so
-rw-r--r-- 1 root root 1098444  1月 30 17:37 /opt/vivaldi/lib/libffmpeg.so
-rw-r--r-- 1 root root 2428128  1月 27 19:51 /usr/lib/chromium-browser/libffmpeg.so
$ file /opt/vivaldi/lib/libffmpeg.so
/opt/vivaldi/lib/libffmpeg.so: ELF 32-bit LSB shared object, ARM, EABI5 version 1 (SYSV), dynamically linked, BuildID[sha1]=a0c7e5c04798cdb9469a869e0b87dfe80fa85f30, stripped

LD_LIBRARY_PATHに指定してみましたがダメでした.

$ LD_LIBRARY_PATH=/opt/vivaldi/lib:$LD_LIBRARY_PATH vivaldi

chromium-codecs-ffmpeg-extra:armhfを入れればいいのではと思ったけど排他でaarch64版が消されるのでやめました.

$ sudo apt install chromium-codecs-ffmpeg-extra:armhf
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています
状態情報を読み取っています... 完了
以下のパッケージが自動でインストールされましたが、もう必要とされていません:
  libido-0.1-0
これを削除するには 'sudo apt autoremove' を利用してください。
以下のパッケージは「削除」されます:
  chromium-browser chromium-browser-l10n chromium-codecs-ffmpeg-extra
以下のパッケージが新たにインストールされます:
  chromium-codecs-ffmpeg-extra:armhf
アップグレード: 0 個、新規インストール: 1 個、 削除: 3 個、保留: 0 個。
891 kB のアーカイブを取得する必要があります。
この操作後に 192 MB のディスク容量が解放されます。
続行しますか? [Y/n] 

/opt/vivaldi/vivaldiの中を見るとファイルの存在チェックをしているのだけど,/usr/lib/$DEBARCH/oxide-qt/libffmpeg.soとかも見ている.
これのarmhf版(oxideqt-codecs-extra:armhf)を入れてLD_LIBRARY_PATHに指定したら警告が出るけど起動した.(Youtubeを試すと動画を再生しようとするとエラーとなった.1.13の頃はYoutubeが見られていたのは何を使っていたのだろう?)

$ sudo apt install oxideqt-codecs-extra:armhf
$ LD_LIBRARY_PATH=/usr/lib/arm-linux-gnueabihf/oxide-qt:$LD_LIBRARY_PATH vivaldi

No suitable library for HTML5 MP4 (H.264/AAC) video and MP3 audio was
found, therefore only open codecs will play.

For assistance on how to enable proprietary media, visit:

https://help.vivaldi.com/article/html5-mp4-h-264aac-video-and-mp3-audio-support-under-linux/

[32501:32501:0201/063045.261665:ERROR:gl_implementation.cc(292)] Failed to load libGL.so.1: libGL.so.1: 共有オブジェクトファイルを開けません: そのようなファイルやディレクトリはありません
 :

後ろのFailed to load libGL.so.1も気になるので,libgl1-mesa-glx:armhfを入れてとりあえず解消.

$ dpkg-query -S libGL.so.1
libgl1-mesa-glx:arm64: /usr/lib/aarch64-linux-gnu/mesa/libGL.so.1
libgl1-mesa-glx:arm64: /usr/lib/aarch64-linux-gnu/mesa/libGL.so.1.2.0
$ sudo apt install libgl1-mesa-glx:armhf

なんか1.13より動作が重くなったような気がしますがとりあえず動くようになりました.

Byobu + GNU screen でFunction Key割り当てを無効にする

Byobuの既定値ではFunction Keyに機能が割り当てられています.

/usr/share/byobu/keybindings/f-keys.screen

自分は使わないし,別のFunction Keyを利用するアプリケーションで利用できなくなるので無効にしています.
無効にする方法をメモしておきます.

適当なテキストエディタで~/.byobu/keybindingsを開きます.viなどの編集モードのあるエディタの場合は編集モードにして,Ctrl+a !(aは設定してあるescape key)を押すと以下のラインが出てくるので頭の:を消して保存します.他にsourceの行がある場合はそれよりも下に書かないと上書きされるので注意.

:source /usr/share/byobu/keybindings/f-keys.screen.disable

環境(Ubuntu 16.04 LTS arm64)によってはこうなりました.$BYOBU_PREFIX/usrだったので実態は同じですね.

:source $BYOBU_PREFIX/share/byobu/keybindings/f-keys.screen.disable

Byobuを起動し直すと反映されているはずです.
Ctrl+a !を使わず同じテキストを書いても問題ないようでした.

Tmuxは利用してないので未検証ですが以下のあたりのファイルで同じような設定ができそうな気がします.

~/.byobu/keybindings.tmux
/usr/share/byobu/keybindings/f-keys.tmux.disable

以下の環境で確認しました.

  • Debian sid amd64
  • Debian stretch armhf/arm64
  • Ubuntu 16.04 LTS amd64/arm64
  • Ubuntu 17.10 amd64
追記)この記事はByobu GNU screenで,以下はByobu Tmux

Raspbian stretch イメージを Devuan ascii にしてみる

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を元にするといいと思います.

DevuanDebian
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の方が楽かもしれない?

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

Raspbianイメージを任意の広さに拡大する

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に書き込んで利用できます.