
NanoPi M4 Metal Case w/ Cooling Fan その2
ファンの設定
とりあえず以下のコマンドでファンが動作することを確認
前準備
root@kodi-pi-m4:~# echo 0 > /sys/class/pwm/pwmchip1/export
root@kodi-pi-m4:~# echo 50000 > /sys/class/pwm/pwmchip1/pwm0/period
root@kodi-pi-m4:~# echo 1 > /sys/class/pwm/pwmchip1/pwm0/enable
実際にファンをコントロール(動作させる)するコマンド
まずは強めに
root@kodi-pi-m4:~# echo 45000 > /sys/class/pwm/pwmchip1/pwm0/duty_cycle
次は弱く
root@kodi-pi-m4:~# echo 49200 > /sys/class/pwm/pwmchip1/pwm0/duty_cycle
echoの値を45000から49300ぐらいに変化させることでファンの回転数がかわることがわかったので以下のような簡単なスクリプトを作る
#! /bin/bash
echo 0 > /sys/class/pwm/pwmchip1/export
echo 50000 > /sys/class/pwm/pwmchip1/pwm0/period
echo 1 > /sys/class/pwm/pwmchip1/pwm0/enable
temp=`cat /sys/class/thermal/thermal_zone0/temp`
echo $temp
if [ ${temp} -lt 32000 ]; then
echo 49200 > /sys/class/pwm/pwmchip1/pwm0/duty_cycle
elif [ 35000 -lt $temp ]; then
echo 49100 > /sys/class/pwm/pwmchip1/pwm0/duty_cycle
elif [ 40000 -lt $temp ]; then
echo 48000 > /sys/class/pwm/pwmchip1/pwm0/duty_cycle
elif [ 45000 -lt $temp ]; then
echo 47000 > /sys/class/pwm/pwmchip1/pwm0/duty_cycle
elif [ 50000 -lt $temp ]; then
echo 45000 > /sys/class/pwm/pwmchip1/pwm0/duty_cycle
fi
cat /sys/class/thermal/thermal_zone0/tempより現在温度をみてそれに応じたファンの回転数にするという感じ
このシェルをcronに2分毎に起動でちゃんと制御されているっぽいことがわかった。
NVMEのrootfs化
大まかな流れ的には パーテーション作成しフォーマット後、マウント。
その後/(ルート)をrsyncでコピーしroot(/)のマウントポイントをnvmeに変えて起動
まずは必要そうなものをINSTALL
root@kodi-pi-m4:~# apt install rsync hdparm u-boot-tools
fdiskする
root@kodi-pi-m4:~# fdisk -l
Disk /dev/ram0: 4 MiB, 4194304 bytes, 8192 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk /dev/nvme0n1: 931.5 GiB, 1000204886016 bytes, 1953525168 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
Disk /dev/mmcblk1: 14.6 GiB, 15634268160 bytes, 30535680 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: 0x625397d5
Device Boot Start End Sectors Size Id Type
/dev/mmcblk1p1 32768 278527 245760 120M 83 Linux
/dev/mmcblk1p2 278528 30535679 30257152 14.4G 83 Linux
Disk /dev/mmcblk1boot1: 4 MiB, 4194304 bytes, 8192 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
Disk /dev/mmcblk1boot0: 4 MiB, 4194304 bytes, 8192 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
/dev/nvme0n1: 931.5 GiBがあるのがわかる
パーテション設定
root@kodi-pi-m4:~# fdisk /dev/nvme0n1
Welcome to fdisk (util-linux 2.31.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Device does not contain a recognized partition table.
Created a new DOS disklabel with disk identifier 0xc4bbab93.
Command (m for help): p
Disk /dev/nvme0n1: 931.5 GiB, 1000204886016 bytes, 1953525168 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: 0xc4bbab93
Command (m for help):
つぎに n[ENTER] , p[ENTER] , 1[ENTER], [ENTER], [ENTER]の順でパーテーションを作成
Command (m for help): n
Partition type
p primary (0 primary, 0 extended, 4 free)
e extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-1953525167, default 2048):
Last sector, +sectors or +size{K,M,G,T,P} (2048-1953525167, default 1953525167):
Created a new partition 1 of type 'Linux' and of size 931.5 GiB.
Command (m for help):
最後にwで設定反映
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
確認
root@kodi-pi-m4:~# fdisk -l
Disk /dev/ram0: 4 MiB, 4194304 bytes, 8192 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk /dev/nvme0n1: 931.5 GiB, 1000204886016 bytes, 1953525168 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: 0x29d4746f
:
:
ファイルシステムを決める
root@kodi-pi-m4:~# mkfs.ext4 /dev/nvme0n1p1
mke2fs 1.44.1 (24-Mar-2018)
Discarding device blocks: done
Creating filesystem with 244190646 4k blocks and 61054976 inodes
Filesystem UUID: 4a0347ba-d421-4347-872e-9cf02cf7c562
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,
102400000, 214990848
Allocating group tables: done
Writing inode tables: done
Creating journal (262144 blocks): done
Writing superblocks and filesystem accounting information: done
息抜き 性能調査(hdparmコマンドより)
root@kodi-pi-m4:~# hdparm -Tt --direct /dev/nvme0n1p1
/dev/nvme0n1p1:
Timing O_DIRECT cached reads: 702 MB in 2.00 seconds = 350.79 MB/sec
Timing O_DIRECT disk reads: 1090 MB in 3.00 seconds = 362.76 MB/sec
はやい...
気を取り直してマウントする
root@kodi-pi-m4:~# mkdir /media/newdrive
root@kodi-pi-m4:~# mount /dev/nvme0n1p1 /media/newdrive/
rsyncでコピー
root@kodi-pi-m4:~# rsync -avx / /media/newdrive
それなりに時間経過..
:
:
sent 3,034,177,769 bytes received 1,376,528 bytes 23,808,268.00 bytes/sec
total size is 3,028,606,746 speedup is 1.00
root@kodi-pi-m4:~#
どうやら終わったようだ(5分もかからなかったか
出来上がりを確認
root@nanopi-m4:~# ll /media/newdrive/
total 100
drwxr-xr-x 22 root root 4096 Dec 2 2018 ./
drwxr-xr-x 3 root root 4096 Oct 12 02:56 ../
drwxr-xr-x 2 root root 4096 Dec 22 2018 bin/
drwxr-xr-x 2 root root 4096 Jan 1 2019 boot/
drwxr-xr-x 2 root root 4096 Oct 12 02:55 dev/
drwxr-xr-x 88 root root 4096 Oct 12 02:58 etc/
drwxr-xr-x 3 root root 4096 Dec 2 2018 home/
drwxr-xr-x 15 root root 4096 Oct 12 02:58 lib/
drwx------ 2 root root 16384 Dec 2 2018 lost+found/
drwxr-xr-x 3 root root 4096 Oct 12 02:56 media/
drwxr-xr-x 2 root root 4096 Oct 11 2018 mnt/
drwxr-xr-x 2 root root 4096 Oct 11 2018 opt/
dr-xr-xr-x 2 root root 4096 Jan 1 1970 proc/
drwx------ 3 root root 4096 Dec 29 2018 root/
drwxr-xr-x 2 root root 4096 Oct 12 02:55 run/
drwxr-xr-x 2 root root 4096 Oct 12 02:58 sbin/
drwxr-xr-x 2 root root 4096 Oct 11 2018 srv/
dr-xr-xr-x 2 root root 4096 Jan 18 2013 sys/
drwxr-xr-x 5 root root 4096 Oct 15 2018 system/
drwxrwxrwt 10 root root 4096 Oct 12 02:58 tmp/
drwxr-xr-x 11 root root 4096 Dec 22 2018 usr/
drwxr-xr-x 11 root root 4096 Oct 11 2018 var/
NVME SSDをunmount
root@kodi-pi-m4:~# umount /dev/nvme0n1p1
boot.cmdを編集
#setenv bootargs "earlyprintk root=/dev/mmcblk1p2 rw rootfstype=ext4 rootwait fsck.repair=${fsck.repair} panic=10 ${extra}"
↓
setenv bootargs "earlyprintk root=/dev/nvme0n1 rw rootfstype=ext4 rootwait fsck.repair=${fsck.repair} panic=10 ${extra}"
/dev/mmcblk1p2をコメントアウトして新たに/dev/nvme0n1を追記
boot反映コマンド
root@kodi-pi-m4:~# cd /boot
root@kodi-pi-m4:~# mkimage -C none -A arm -T script -d boot.cmd boot.scr
そして再起動
root@kodi-pi-m4:~# sync && reboot
起動後にdf
root@kodi-pi-m4:~# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/nvme0n1p1 916G 3.0G 867G 1% /
devtmpfs 963M 0 963M 0% /dev
tmpfs 964M 0 964M 0% /dev/shm
tmpfs 964M 8.6M 955M 1% /run
tmpfs 5.0M 4.0K 5.0M 1% /run/lock
tmpfs 964M 0 964M 0% /sys/fs/cgroup
/dev/mmcblk1p1 113M 21M 84M 20% /boot
tmpfs 193M 0 193M 0% /run/user/1000
うおおおお!!できたああああああ