2
4

More than 5 years have passed since last update.

TinkerBoard  Armbian インストール+初期設定メモ

Last updated at Posted at 2018-10-07

TinkerBoard を当初 TinkerOSを使用していたが、GUIいらない環境で使いたい+その他のシングルボードコンピュータ に互換性もあるということで代わりにArmbianを入れた初期設定の記録です

注意 ここの記述内容は記録で 必ずしも正しい設定ではないのでご注意ください。

主な引用元
https://docs.armbian.com/
https://forum.armbian.com/

要求内容

  • 最低限の設定(FW/ロケール/armbian-config使用しないなど)
  • 可能なら延命処理(SDカード)
  • SSHの設定(ルートログインなし、ポート、認証方式の変更)
  • デスクトップ(GUI環境)はいらない
  • IPv6使用しない
  • (オプション)ユーザーログインはSSH接続のみ (次回以降掲載)
  • (オプション)Python環境の整備 (次回以降掲載)

1 SDカードにimgデータ書き込み

Armbian Stretch (mainline kernel 4.14.y)
https://www.armbian.com/tinkerboard/

  1. SDカードに上記URLよりダウンロード・解凍(*7z対応解凍ソフトが必要)
  2. imgデータ(Armbian_5.59_Tinkerboard_Debian_stretch_next_4.14.67)を書き込み (Mac環境 Etcher https://etcher.io/ ) 

2 TinkerBoard起動

  1. 書き込みしたSDカードを入れて起動・
  2. SSHもしくは直接接続にて操作する
  3. アカウント(root),パスワード(1234)を入力
  4. パスワードの変更+ 管理者アカウント(sudo)の作成をする(強制)
  5. ログアウト 、管理者アカウントでログインし直します。

例:SSH接続

You are required to change your password immediately (root enforced)
 _____ _       _             _                         _ 
|_   _(_)_ __ | | _____ _ __| |__   ___   __ _ _ __ __| |
  | | | | '_ \| |/ / _ \ '__| '_ \ / _ \ / _` | '__/ _` |
  | | | | | | |   <  __/ |  | |_) | (_) | (_| | | | (_| |
  |_| |_|_| |_|_|\_\___|_|  |_.__/ \___/ \__,_|_|  \__,_|


Welcome to ARMBIAN 5.59 stable Debian GNU/Linux 9 (stretch) 4.14.67-rockchip   
System load:   0.04 0.04 0.01   Up time:       4:02 hours       
Memory usage:  3 % of 2005MB    IP:            XXX.XXX.XXX.XXX
CPU temp:      55°C            
Usage of /:    6% of 15G        

Last login: Thu Oct  4 05:56:49 2018 from XXX.XXX.XXX.XXX
Changing password for root.
(current) UNIX password: (1234)
Enter new UNIX password: (root用 新パスワード)
Retype new UNIX password: (root用 新パスワード)


Thank you for choosing Armbian! Support: www.armbian.com

Creating a new user account. Press <Ctrl-C> to abort

Please provide a username (eg. your forename): XXXX(管理者アカウント)
Trying to add user XXXX
Adding user `XXXX' ...
Adding new group `XXXX' (1000) ...
Adding new user `XXXX' (1000) with group `XXXX' ...
Creating home directory `/home/XXXX' ...
Copying files from `/etc/skel' ...
Enter new UNIX password: (管理者アカウント パスワード)
Retype new UNIX password: (管理者アカウント パスワード)
passwd: password updated successfully
Changing the user information for XXXX
Enter the new value, or press ENTER for the default
    Full Name []: 
    Room Number []: 
    Work Phone []: 
    Home Phone []: 
    Other []: 
Is the information correct? [Y/n] Y

Dear XXXX, your account XXXX has been created and is sudo enabled.
Please use this account for your daily work from now on.

root@tinkerboard:~# 

3. 初期設定

初期状態のログ

取っておくと後々、確認に役立つかも

hostnamectl
uname -a
localectl status
locale
timedatectl status
lscpu
cat /etc/os-release
cat /etc/issue
cat /proc/version
dpkg -l
systemctl list-unit-files --type=service
df -h
free -mh
ntpq -p

 SWAP,/var/tmpについて

SDカードの延命にと swapファイルをオフにするとかRaspberryPでよくあった設定、Armbianでは、zram使用、そもそもtmpfsなど特にこだわる必要はなさそう

一応ログのみ取得

$ free -mh
              total        used        free      shared  buff/cache   available
Mem:           2.0G         59M        1.8G         18M        149M        1.8G
Swap:          1.0G          0B        1.0G

(swapon -a  OR cat /proc/swaps)

$ cat /proc/swaps
Filename                Type        Size    Used    Priority
/dev/zram1                              partition   256664  0   5
/dev/zram2                              partition   256664  0   5
/dev/zram3                              partition   256664  0   5
/dev/zram4                   
$ df -h
Filesystem      Size  Used Avail Use% Mounted on
udev           1001M     0 1001M   0% /dev
tmpfs           201M  3.1M  198M   2% /run
/dev/mmcblk0p1   15G  853M   14G   6% /
tmpfs          1003M     0 1003M   0% /dev/shm
tmpfs           5.0M  4.0K  5.0M   1% /run/lock
tmpfs          1003M     0 1003M   0% /sys/fs/cgroup
tmpfs          1003M  4.0K 1003M   1% /tmp
/dev/zram0       49M  3.7M   42M   9% /var/log
tmpfs           201M     0  201M   0% /run/user/1000

/var/tmp は含まれてないので含めたい場合
/etc/fstab に下記追記 
tmpfs /var/tmp tmpfs defaults,nosuid 0 0

留意点 /tmp、/var/tmpの違い(初期設定に含まれていないのはこのためだと思う)
https://ja.wikipedia.org/wiki/Filesystem_Hierarchy_Standard

$ cat /etc/fstab
UUID=24a05491-1fbb-4a44-894d-f3dbef5f721b / ext4 defaults,noatime,nodiratime,commit=600,errors=remount-ro 0 1
tmpfs /tmp tmpfs defaults,nosuid 0 0
tmpfs /var/tmp tmpfs defaults,nosuid 0 0

 ログの整頓

必要があんまりないログを書き込まないようにする

$ sudo vim /etc/rsyslog.conf

このあたりをコメント
#kern.*             -/var/log/kern.log
#lpr.*              -/var/log/lpr.log
#mail.*             -/var/log/mail.log
#user.*             -/var/log/user.log
#mail.info          -/var/log/mail.info
#mail.warn          -/var/log/mail.warn
#mail.err           /var/log/mail.err

armbian-config(GUI)

GUI設定ツールにて各種設定が可能

https://docs.armbian.com/User-Guide_Armbian-Config/

sudo armbian-config にて起動

触ってみた結果、それなりに便利でしたが使用しませんでした。
(RASPBIAN、TikerOSにも同様の機能が設定範囲が異なるなど紛らわしい上、コマンドで対応できるため)

代わりこのタイミングで使用した大項目 Personal部分はコマンドで対応しています。

大項目 System

小項:Install,Freeze,Noghtly,Bootenv,Switch,SSH,Firmware,Minimal,Default
ファームウェア更新・boot環境の設定、デスクトップ環境インストールなど

https://docs.armbian.com/User-Guide_Armbian-Config/#system

大項目 Network

小項:eth0,ip6tnl0,wlan0
各IFの設定及びインストール

https://docs.armbian.com/User-Guide_Armbian-Config/#network

大項目 Personal

小項:Timezone,Locales,Keyboard,Hostname,Miiror,Welcome

小項目 Timezone

NTPまわりです。
Asia/Tokyoに変更

$ sudo timedatectl set-timezone Asia/Tokyo
$ sudo dpkg-reconfigure -f noninteractive tzdata
(オプション)NTPサーバの変更

日本サーバに合わせます+同期間隔を遅めに変更
使用予定の環境で同期はして欲しいけど、あんまり通信して欲しくない デフォルト 64秒〜1024(17分)

現状確認 timedatectl status,ntpq -p

$ timedatectl status
      Local time: 土 2018-10-06 17:37:36 JST
  Universal time: 土 2018-10-06 08:37:36 UTC
        RTC time: 土 2018-10-06 08:37:41
       Time zone: Asia/Tokyo (JST, +0900)
 Network time on: yes
NTP synchronized: no
 RTC in local TZ: no

$ ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 0.debian.pool.n .POOL.          16 p    -   64    0    0.000    0.000   0.000
 1.debian.pool.n .POOL.          16 p    -   64    0    0.000    0.000   0.000
 2.debian.pool.n .POOL.          16 p    -   64    0    0.000    0.000   
・・・省略・・・

/etc/ntp.conf を編集
コメントアウト+server -4 ntp.nict.jp minpoll 8 maxpoll 12を追記
(minpoll 8 => 2^8(256秒 約4分) maxpoll 12 => 2^12(4096秒 約68分 ))

NTPサーバー元
http://jjy.jp/index.html

# You do need to talk to an NTP server or two (or three).
#server ntp.your-provider.example

# pool.ntp.org maps to about 1000 low-stratum NTP servers.  Your server will
# pick a different set every time it starts up.  Please consider joining the
# pool: <http://www.pool.ntp.org/join.html>
#pool 0.debian.pool.ntp.org iburst
#pool 1.debian.pool.ntp.org iburst
#pool 2.debian.pool.ntp.org iburst
#pool 3.debian.pool.ntp.org iburst
server -4 ntp.nict.jp minpoll 8 maxpoll 12

sudo systemctl restart ntp 再起動

$ ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
*ntp-a3.nict.go. .NICT.           1 u  251  256  377   16.546    7.925  10.197

小項目 Locales

言語を日本語に設定

$ localectl set-locale LANG=ja_JP.UTF-8 LANGUAGE="ja_JP:ja" 
$ source /etc/default/locale
$ localectl status
   System Locale: LANG=ja_JP.UTF-8
                  LANGUAGE=ja_JP:ja
       VC Keymap: n/a
      X11 Layout: us
       X11 Model: pc105
$ locale
LANG=ja_JP.UTF-8
LANGUAGE=ja_JP:ja
LC_CTYPE="ja_JP.UTF-8"
LC_NUMERIC="ja_JP.UTF-8"
LC_TIME="ja_JP.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=

(オプション)task-japanese について

task-japaneseはCUI環境では必要ありません
入れる場合は、apt -y install task-japanese

https://packages.debian.org/ja/stretch/task-japanese

小項目 Keyboard

英語キーボードから日本語キーボードへ変更

$ cat /etc/default/keyboard
# KEYBOARD CONFIGURATION FILE

# Consult the keyboard(5) manual page.

XKBMODEL="pc105"
XKBLAYOUT="us"
XKBVARIANT=""
XKBOPTIONS=""

BACKSPACE="guess"

/etc/default/keyboard内の XKBLAYOUT="us" -> jpに変更

$ cat /etc/default/keyboard
# KEYBOARD CONFIGURATION FILE

# Consult the keyboard(5) manual page.

XKBMODEL="pc105"
XKBLAYOUT="jp"
XKBVARIANT=""
XKBOPTIONS=""

BACKSPACE="guess"

最後に反映
sudo dpkg-reconfigure -f noninteractive keyboard-configuration

小項目 Hostname

ホストネーム変更
$ sudo hostnamectl set-hostname (ホストネーム)

hostnamectlで確認

$ hostnamectl 
   Static hostname: (ホストネーム)
         Icon name: computer
        Machine ID: 632bb98e2d2446338a8add88cc6ce478
           Boot ID: 20fa450e05b140199e9c991f67006aea
  Operating System: Debian GNU/Linux 9 (stretch)
            Kernel: Linux 4.14.67-rockchip
      Architecture: arm

(オプション)hostsファイルの変更

$ sudo cat /etc/hosts
127.0.0.1   localhost tinkerboard
::1         localhost tinkerboard ip6-localhost ip6-loopback
fe00::0     ip6-localnet
ff00::0     ip6-mcastprefix
ff02::1     ip6-allnodes
ff02::2     ip6-allrouters

tinkerboard部分を削除

$ sudo cat /etc/hosts
127.0.0.1   localhost
::1         localhost ip6-localhost ip6-loopback
fe00::0     ip6-localnet
ff00::0     ip6-mcastprefix
ff02::1     ip6-allnodes
ff02::2     ip6-allrouters

小項目 Mirror

レポジトリをミラーサーバーに変更する際に使用
/etc/apt/sources.listの編集が可能
今回は変更しませんでした。

小項目 Welcome

Motdにあたります。 Armbianは 自動生成 + /etc/motd の内容が反映されます。
この項目は自動生成内容を制御します
(/etc/update-motd.d ディレクトリ内にあるファイルのパーミッションの実行可、不可で制御)
sudo chmod 644 /etc/update-motd.d/* にて全部不可に設定

上記とは別に/etc/default/armbian-motd にて設定も可能
非表示にしたいものをMOTD_DISABLEに入れるという事だと思う

$ cat /etc/default/armbian-motd
# add space-separated list of MOTD script names (without number) to exclude them from MOTD
# Example:
# MOTD_DISABLE="header tips updates"

MOTD_DISABLE=""

(オプション) アップデート後に表示される

アップデート(apt update)したら更新パッケージに含まれていたらしく更新されました。パーミッションが元に戻り再度表示されるようになりました。

対応方法
/etc/default/armbian-motd ファイルを変更

MOTD_DISABLE="header tips sysinfo armbian-config updates"

98-armbian-autoreboot-warnは無いので表示のまま
これでアップデートしても大丈夫かな(未確認)

項目 Software

3rdパーティのソフト管理
Samba,Docker,VPNなどのソフトウェアからモニタリングなどオプション項目

項目 Help

ヘルプページ

アップデート

パッケージリストの更新、更新可能パッケージの確認

sudo apt update
sudo apt list --upgradable

パッケージのアップデート+ログの確認

sudo apt upgrade
dpkg -l

未使用のパッケージ、アーカイブの削除

sudo apt-get autoremove
sudo apt-get autoclean

4. FW設定(ufw)

ファイアウォールのインストール
sudo apt install ufw

https://help.ubuntu.com/community/UFW

Ipv6の停止

/etc/default/ufwファイルの IPV6をnoに変更

IPV6=no

/etc/sysctl.conf に下記を追記

net.ipv6.conf.all.disable_ipv6 = 1

sudo sysctl -pにて反映、sudo ifconfig 確認

$ sudo sysctl -p
kernel.printk = 3 4 1 3
vm.swappiness = 100
net.ipv6.conf.all.disable_ipv6 = 1

$ sudo ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.184.4  netmask 255.255.255.0  broadcast 192.168.184.255
        ether 88:d7:f6:c2:b6:e4  txqueuelen 1000  (イーサネット)
        RX packets 6594  bytes 441909 (431.5 KiB)
        RX errors 0  dropped 1  overruns 0  frame 0
        TX packets 993  bytes 161636 (157.8 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        device interrupt 45  

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        loop  txqueuelen 1000  (ローカルループバック)
        RX packets 20  bytes 1404 (1.3 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 20  bytes 1404 (1.3 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

wlan0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        ether 40:9f:38:4f:1c:0d  txqueuelen 1000  (イーサネット)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

暗黙のDENY

$ sudo ufw default deny
WARN: / is world writable!
WARN: / is group writable!
Default incoming policy changed to 'deny'
(be sure to update your rules accordingly)
  • WARN: / is world writable!については下記参照

WARN: / is world writable! について

ルートディレクトリ / のパーミッションが777の場合に表示される警告です。

$ ls -ld /
drwxrwxrwx 22 root root 4096  8月 29 22:09 /

sudo chmod 755 /パーミッションを755 に変更します。

SSH(22) のみ許可

$ sudo ufw allow 22/tcp
Rules updated

UFW enable

$ sudo ufw enable
Command may disrupt existing ssh connections. Proceed with operation (y|n)? y
Firewall is active and enabled on system startup

$ sudo ufw status
Status: active

To                         Action      From
--                         ------      ----
22/tcp                     ALLOW       Anywhere       

sudo cat /etc/ufw/user.rulesにてiptablesに反映するルール表示

5.SSHの設定

認証ファイルの作成

(SSHログインしたいユーザーで操作)

ssh-keygen -t rsa にてキー作成+パーミッション変更

$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/XXXX/.ssh/id_rsa):   (空エンター)
Created directory '/home/XXXX/.ssh'.
Enter passphrase (empty for no passphrase):  (秘密鍵パスワード)
Enter same passphrase again:   (秘密鍵パスワード)
Your identification has been saved in /home/XXXX/.ssh/id_rsa.
Your public key has been saved in /home/XXXX/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:XXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXX@xxxxx
The key's randomart image is:
+---[RSA 2048]----+
|                 |
|       略         |
|                 |
+----[SHA256]-----+

$ mv ~/.ssh/id_rsa.pub ~/.ssh/authorized_keys
$ chmod 600 ~/.ssh/authorized_keys
$ ls
authorized_keys  id_rsa

id_rsaファイルをSSHリモートホスト(接続元)にて使用します。

/etc/ssh/sshd-configの変更

最低限以下の部分を変更
#Port 22 -> Port xxxx
PermitRootLogin yes -> PermitRootLogin no
#PasswordAuthentication yes -> PasswordAuthentication no

あとはお好みで変更します。

OpenSSH Manual Pages
https://man.openbsd.org/sshd_config

ufwポートの変更

SSHポート番号の書き換えた場合のポート変更

$ sudo ufw delete allow 22/tcp
Rule deleted
$ sudo ufw allow xxxx/tcp
Rule added
$ sudo ufw reload
Firewall reloaded
$ sudo ufw status
Status: active

To                         Action      From
--                         ------      ----
xxxx/tcp                  ALLOW       Anywhere     

ssh再起動

sudo systemctl restart sshd してログアウト
秘密鍵+変更したポート番号で接続
(mac環境 ~/.ssh/config で作成接続内容作成済)

$ ssh xxxxxx
Enter passphrase for key '/xxxxx/xxxxxx/.ssh/xxxxxx.key': 
Last login: Sun Oct  X 13:13:27 2018 from xxx.xxxx.xxx.xxx

$ 

おわり

以上です。
このあとSDカードをコピーして保存すれば色々試す環境に使えます。

こんな感じでimgファイルの作成(詳細は別途調べてください)

diskutil list
diskutil umountDisk /dev/xxxxxx
sudo dd if=/dev/xxxxxx of=XXXXX.img bs=1m

回り道や余計なことしているかもしれませんがそこまで問題無いとは思います。

2
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
4