RaspberryPiのSDカード書き込みを抑制

### swapファイルを無効に
```
$ sudo swapoff --all
$ sudo systemctl stop dphys-swapfile
$ sudo systemctl disable dphys-swapfile
Synchronizing state of dphys-swapfile.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install disable dphys-swapfile
Removed "/etc/systemd/system/multi-user.target.wants/dphys-swapfile.service".
$ systemctl status dphys-swapfile
○ dphys-swapfile.service - dphys-swapfile - set up, mount/unmount, and delete a swap file
     Loaded: loaded (/lib/systemd/system/dphys-swapfile.service; disabled; preset: enabled)
     Active: inactive (dead)
       Docs: man:dphys-swapfile(8)

Apr 01 05:20:09 raspberrypi systemd[1]: Starting dphys-swapfile.service - dphys-swapfile - set up, mount/unmount, and delete a swap fil>
Apr 01 05:20:10 raspberrypi dphys-swapfile[430]: want /var/swap=100MByte, checking existing: keeping it
Apr 01 05:20:10 raspberrypi systemd[1]: Finished dphys-swapfile.service - dphys-swapfile - set up, mount/unmount, and delete a swap fil>
Apr 01 05:39:35 raspberrypi systemd[1]: Stopping dphys-swapfile.service - dphys-swapfile - set up, mount/unmount, and delete a swap fil>
Apr 01 05:39:35 raspberrypi systemd[1]: dphys-swapfile.service: Deactivated successfully.
Apr 01 05:39:35 raspberrypi systemd[1]: Stopped dphys-swapfile.service - dphys-swapfile - set up, mount/unmount, and delete a swap file.
```
### もしswapファイルを有効にするなら
```
$ sudo systemctl start dphys-swapfile
$ sudo systemctl enable dphys-swapfile
$ systemctl status dphys-swapfile
```
### ファイルシステムにramdiskを追加
```
$ sudo vi /etc/fstab
以下を追加
tmpfs /tmp tmpfs defaults,size=256m,noatime,mode=1777 0 0
tmpfs /var/tmp tmpfs defaults,size=256m,noatime,mode=1777 0 0
tmpfs /var/log tmpfs defaults,size=256m,noatime,mode=755 0 0
```
### 起動時に/var/logの必要ファイルを作成
```
$ sudo vi /etc/rc.local
以下を追加
mkdir -p /var/log/apt
mkdir -p /var/log/journal
mkdir -p /var/log/private
mkdir -p /var/log/runit
chmod 755 /var/log/apt
chmod 755 /var/log/journal
chmod g+s /var/log/journal
chmod 700 /var/log/private
chmod 755 /var/log/runit
chown root.systemd-journal /var/log/journal
touch /var/log/btmp
touch /var/log/dpkg.log
touch /var/log/faillog
touch /var/log/lastlog
touch /var/log/wtmp
chmod 660 /var/log/btmp
chmod 644 /var/log/dpkg.log
chmod 644 /var/log/faillog
chmod 664 /var/log/lastlog
chmod 664 /var/log/wtmp
chown root.utmp /var/log/btmp
chown root.utmp /var/log/lastlog
chown root.utmp /var/log/wtmp
exit 0
```
### インストール直後のディレクトリ構造
参考ページに記載された/etc/rsyslog.confは無い
```
$ ls -al /tmp
total 40
drwxrwxrwt 10 root root 4096 Apr  1 05:25 .
drwxr-xr-x 18 root root 4096 Mar 16 00:09 ..
drwxrwxrwt  2 root root 4096 Mar 16 00:09 .font-unix
drwxrwxrwt  2 root root 4096 Mar 16 00:09 .ICE-unix
drwx------  3 root root 4096 Mar 16 00:09 systemd-private-2b7882d3c28d429fb71123afc3078205-bluetooth.service-fvkHtS
drwx------  3 root root 4096 Mar 16 00:09 systemd-private-2b7882d3c28d429fb71123afc3078205-ModemManager.service-3B3AMc
drwx------  3 root root 4096 Mar 16 00:09 systemd-private-2b7882d3c28d429fb71123afc3078205-systemd-logind.service-y43yev
drwx------  3 root root 4096 Mar 16 00:09 systemd-private-2b7882d3c28d429fb71123afc3078205-systemd-timesyncd.service-9xwxUX
drwxrwxrwt  2 root root 4096 Mar 16 00:09 .X11-unix
drwxrwxrwt  2 root root 4096 Mar 16 00:09 .XIM-unix
$ ls -al /var/tmp
total 24
drwxrwxrwt  6 root root 4096 Apr  1 05:25 .
drwxr-xr-x 11 root root 4096 Mar 16 00:09 ..
drwx------  3 root root 4096 Mar 16 00:09 systemd-private-2b7882d3c28d429fb71123afc3078205-bluetooth.service-BaTP1w
drwx------  3 root root 4096 Mar 16 00:09 systemd-private-2b7882d3c28d429fb71123afc3078205-ModemManager.service-gDkVIJ
drwx------  3 root root 4096 Mar 16 00:09 systemd-private-2b7882d3c28d429fb71123afc3078205-systemd-logind.service-2LFwmH
drwx------  3 root root 4096 Mar 16 00:09 systemd-private-2b7882d3c28d429fb71123afc3078205-systemd-timesyncd.service-45REQZ
$ ls -al /var/log
total 32
drwxr-xr-x   6 root root              4096 Mar 19 15:35 .
drwxr-xr-x  11 root root              4096 Mar 16 00:09 ..
drwxr-xr-x   2 root root              4096 Mar 19 15:35 apt
-rw-rw----   1 root utmp                 0 Mar 19 15:35 btmp
-rw-r--r--   1 root root                 0 Mar 19 15:35 faillog
drwxr-sr-x+  3 root systemd-journal   4096 Mar 16 00:08 journal
-rw-rw-r--   1 root utmp            296296 Apr  1 05:26 lastlog
drwx------   2 root root              4096 Mar 15 23:59 private
lrwxrwxrwx   1 root root                39 Mar 15 23:59 README -> ../../usr/share/doc/systemd/README.logs
drwxr-xr-x   3 root root              4096 Mar 16 00:01 runit
-rw-rw-r--   1 root utmp              3200 Apr  1 05:26 wtmp
$ ls -l /etc/rsyslog.conf
ls: cannot access '/etc/rsyslog.conf': No such file or directory
```

参考
https://curecode.jp/tech/raspberrypi-ramdisk/
https://qiita.com/girlfellfromsky/items/953ad71ad6ed09a97dfe
https://qiita.com/s8ta/items/9e08242e30ec7929fa89
https://yueno.net/xoops/modules/xpwiki/?PC%2FRaspberryPi%2FRAM%E3%83%87%E3%82%A3%E3%82%B9%E3%82%AF%E3%81%AE%E5%88%A9%E7%94%A8
https://gris-et-blanc.net/raspi/841/
https://el.jibun.atmarkit.co.jp/pythonlove/2022/05/2564sd.html
https://www.my-hacks.info/2021/07/01/post-1746/
http://siroshitsuji.blog.fc2.com/blog-entry-28.html
https://raspi-katsuyou.com/index.php/2020/06/24/17/00/37/366/
https://forum.digikey.com/t/raspberry-pi-os-rootfs-rom-ram/34528
https://y-naito.ddo.jp/index.php?id=1416793317
https://netlog.jpn.org/r271-635/2013/04/raspberry_pi_tmp_ramdisk.html
https://www.bluehall.jp/2014/10/15/%E3%83%A9%E3%82%BA%E3%83%99%E3%83%AA%E3%83%BC%E3%83%91%E3%82%A4%E3%82%92%E3%81%8A%E3%81%84%E3%81%97%E3%81%8F%E6%96%99%E7%90%86%E3%81%97%E3%81%A6%E3%81%BF%E3%82%8B%EF%BC%88%EF%BC%96%EF%BC%89/
https://arakoki70.com/?p=921
https://itemy.net/?p=501
https://maausa.marurm.com/raspi-sd-setting/