--- tags: raspberry-pi --- # ② ラズパイのInstall後の処理 # パッケージ更新 NOTE: - コメントアウトの所はやってもいいが、怖いのでやらない。(mmal serviceの恐怖) - Archみたいなローリング・リリースモデルじゃないんだから、わざwざ更新する必要はない ```shell= sudo apt update # package情報を最新にする # sudo apt upgrade # packageを最新に # sudo rpi-update # firmwareを最新に sudo reboot ``` # VIMをデフォルトEDITORにする ```shell= $ sudo apt install vim -y $ sudo update-alternatives --config editor # vim.basic ``` https://askubuntu.com/questions/454649/how-can-i-change-the-default-editor-of-the-sudoedit-command-to-be-vim # capslockの無効化 HHKBの場合は、fn + shift + tabでCAPSLOCKがかかってしまうため。 ```shell $ sudoedit /etc/default/keyboard XKBOPTIONS="ctrl:nocaps" ``` ref https://l-w-i.net/t/raspbian/key_001.txt # Docker周り Dockerのインストール ```shell= curl -sSL https://get.docker.com | sh ``` Pi UserのDockerへの追加 ```shell= sudo usermod -a -G docker pi $ id pi uid=1000(pi) gid=1000(pi) groups=1000(pi),4(adm),20(dialout),24(cdrom),27(sudo),29(audio),44(video),46(plugdev),60(games),100(users),105(input),109(netdev),999(spi),998(i2c),997(gpio),117(lpadmin),995(docker) ``` ggc_userのDockerへの追加 ```shell= $ sudo useradd -m ggc_user $ # sudo mkhomedir_helper ggc_user # this will make user directory $ sudo groupadd ggc_group $ id ggc_user uid=1001(ggc_user) gid=1001(ggc_user) groups=1001(ggc_user) $ sudo usermod -aG docker ggc_user $ id ggc_user uid=1001(ggc_user) gid=1001(ggc_user) groups=1001(ggc_user),995(docker) ``` # Java周り Confirm Java Versions ```shell= $ java --version openjdk 11.0.9.1 2020-11-04 OpenJDK Runtime Environment (build 11.0.9.1+1-post-Raspbian-1deb10u2) OpenJDK Server VM (build 11.0.9.1+1-post-Raspbian-1deb10u2, mixed mode) ``` # Python周り Confirm Python Versions ```shell= $ python3 --version Python 3.7.3 $ python --version Python 2.7.16 $ pip3 --version pip 18.1 from /usr/lib/python3/dist-packages/pip (python 3.7) $ pip --version pip 18.1 from /usr/lib/python2.7/dist-packages/pip (python 2.7) ``` Greengrassのコンポーネント(awsiotsdk)に必要なapt系libのパッケージのインストール ```shell= $ sudo apt-get install cmake -y $ sudo apt-get install libssl-dev -y ``` Python version up ```shell= $ pip install --upgrade pip $ pip -V WARNING: pip is being invoked by an old script wrapper. This will fail in a future version of pip. Please see https://github.com/pypa/pip/issues/5599 for advice on fixing the underlying issue. To avoid this problem you can invoke Python with '-m pip' instead of running pip directly. pip 20.3.4 from /home/pi/.local/lib/python2.7/site-packages/pip (python 2.7) $ pip3 install --upgrade pip $ pip3 -V WARNING: pip is being invoked by an old script wrapper. This will fail in a future version of pip. Please see https://github.com/pypa/pip/issues/5599 for advice on fixing the underlying issue. To avoid this problem you can invoke Python with '-m pip' instead of running pip directly. pip 21.0.1 from /home/pi/.local/lib/python3.7/site-packages/pip (python 3.7) ``` update setuptools also ```shell= $ pip install --upgrade setuptools $ pip show setuptools Name: setuptools Version: 56.0.0 Summary: Easily download, build, install, upgrade, and uninstall Python packages Home-page: https://github.com/pypa/setuptools Author: Python Packaging Authority Author-email: distutils-sig@python.org License: UNKNOWN Location: /home/pi/.local/lib/python3.7/site-packages Requires: Required-by: $ pip3 install --upgrade setuptools $ pip3 show setuptools pip3 show setuptools WARNING: pip is being invoked by an old script wrapper. This will fail in a future version of pip. Please see https://github.com/pypa/pip/issues/5599 for advice on fixing the underlying issue. To avoid this problem you can invoke Python with '-m pip' instead of running pip directly. Name: setuptools Version: 56.0.0 Summary: Easily download, build, install, upgrade, and uninstall Python packages Home-page: https://github.com/pypa/setuptools Author: Python Packaging Authority Author-email: distutils-sig@python.org License: UNKNOWN Location: /home/pi/.local/lib/python3.7/site-packages Requires: Required-by: ``` # Install OpenCV-Python ref: https://stackoverflow.com/questions/53347759/importerror-libcblas-so-3-cannot-open-shared-object-file-no-such-file-or-dire ```shell= sudo apt-get install libcblas-dev -y sudo apt-get install libhdf5-dev -y sudo apt-get install libhdf5-serial-dev -y sudo apt-get install libatlas-base-dev -y sudo apt-get install libjasper-dev -y sudo apt-get install libqtgui4 -y sudo apt-get install libqt4-test -y pip3 install opencv-python ``` # スワップファイルの無効化 ```shell= pi@raspberrypi:~ $ free total used free shared buff/cache available Mem: 3919128 575484 2490584 251988 853060 2963372 Swap: 102396 0 102396 ``` コマンドで無効化する ref: https://qiita.com/homelan/items/62a09aa0d0586d0280a2 ```shell= $ sudo swapoff --all $ sudo systemctl stop dphys-swapfile $ sudo systemctl disable dphys-swapfile $ systemctl status dphys-swapfile ``` SWAPファイルがなくなったことを確認 ```shell $ free total used free shared buff/cache available Mem: 3919128 584308 2414812 249176 920008 2955180 Swap: 0 0 0 ``` ※ スワップファイルの有効化 ```shell $ sudo systemctl start dphys-swapfile $ sudo systemctl enable dphys-swapfile $ systemctl status dphys-swapfile ``` # Ramdiskを作る `/tmp/log/`にRamdiskを作る (https://www.rickmakes.com/setting-up-a-ram-disk-on-a-raspberry-pi-4/) ```shell= $ sudo mkdir -p /tmp/log $ sudo chown -R ggc_user:ggc_group /tmp/log $ sudo mount -osize=2G -t tmpfs tmpfs /tmp/log $ cd /tmp/log ``` ベンチマークを取る。書き込み317MB、読み込み500MBの速さ。 ```shell # bench mark pi@raspberrypi:/tmp/log $ dd if=/dev/zero of=temp.txt bs=1M count=1024 1024+0 records in 1024+0 records out 1073741824 bytes (1.1 GB, 1.0 GiB) copied, 3.38299 s, 317 MB/s pi@raspberrypi:/tmp/log $ dd if=temp.txt of=/dev/null bs=1M count=1024 1024+0 records in 1024+0 records out 1073741824 bytes (1.1 GB, 1.0 GiB) copied, 2.05276 s, 523 MB/s ``` 起動時にマウントする 3行目当たりに次を追加する。 ```shell $ sudoedit /etc/fstab tmpfs /tmp/log tmpfs defaults,noatime,mode=755,uid=ggc_user,gid=ggc_group,size=2g 0 0 ``` 一応確認 ``` $ reboot $ df -h /dev/root 29G 7.5G 20G 28% / devtmpfs 1.8G 0 1.8G 0% /dev tmpfs 1.9G 0 1.9G 0% /dev/shm tmpfs 1.9G 8.7M 1.9G 1% /run tmpfs 5.0M 4.0K 5.0M 1% /run/lock tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup tmpfs 2.0G 0 2.0G 0% /tmp/log ``` # 設定ファイルを作る ``` pi@raspberrypi:~ $ sudo mkdir /etc/lm-tokyo pi@raspberrypi:~ $ sudo chown ggc_user:ggc_group -R /etc/lm-tokyo/ pi@raspberrypi:/home $ sudo su ggc_user ggc_user@raspberrypi:~ $ touch /etc/lm-tokyo/settings.json ``` `settings.json`の中身 ```json {"camera_id": 1} ``` # ggc_userのHOMEにworkspaceを作る ``` pi@raspberrypi:/home $ sudo su ggc_user ggc_user@raspberrypi:~ $ pwd /home/ggc_user ggc_user@raspberrypi:~ $ mkdir workspace ``` https://www.filemail.com/d/zjhjdgqofbxphva # 権限について Dockerが`root`で、Greengrassの実行ユーザーが`ggc_user`で、権限的に問題ないようにする。 次のようにする: - ggc_userのユーザーディレクトリは`ggc_user:ggc_user`にする - `/etc/lm-tokyo/`ディレクトリは`ggc_user:ggc_group`にする - `/tmp/log/` ディレクトrは`ggc_user:ggc_group`にする # ref https://qiita.com/ryo-a/items/2edabbbe2b67654e29c9