両方とも前のリビジョン 前のリビジョン 次のリビジョン | 前のリビジョン |
hardware:raspberry_pi:dietpi:zram_swap [2022/06/16 00:46] – [dietpi-set_swapfile] ともやん | hardware:raspberry_pi:dietpi:zram_swap [2022/08/10 00:49] (現在) – [ZRAM の他にさらに Swap を 3072MB 追加する] ともやん |
---|
===== dietpi-set_swapfile 編 ===== | ===== dietpi-set_swapfile 編 ===== |
| |
==== ZRAM (428MB) + Swap (3072MB) を設定する方法 ==== | ==== ZRAM (476MB) + Swap (3072MB) を設定する方法 ==== |
| |
=== ZRAM スワップを 428MB に設定する === | === ZRAM スワップを 476MB に設定する === |
**free** コマンドで RAM サイズを調べる🤔\\ | **free** コマンドで RAM サイズを調べる🤔\\ |
<WRAP color_term> | <WRAP color_term> |
<WRAP color_result><html><pre> | <WRAP color_result><html><pre> |
total used free shared buff/cache available | total used free shared buff/cache available |
<b class=GRN>Mem: 429</b> 109 20 233 299 37 | <b class=GRN>Mem: 477</b> 30 411 1 34 404 |
Swap: 0 0 0 | Swap: 0 0 0 |
</pre></html></WRAP> | </pre></html></WRAP> |
</WRAP> | </WRAP> |
| |
現在の **dietpi-set_swapfile** では ZRAM のサイズは RAM サイズ (429MB) -1 の 428MB まで設定できる😉\\ | 現在の **dietpi-set_swapfile** では ZRAM のサイズは RAM サイズ (477MB) -1 の 476MB まで設定できる😉\\ |
<WRAP color_term> | <WRAP color_term> |
<WRAP color_command><html><pre> | <WRAP color_command><html><pre> |
$ sudo /boot/dietpi/func/dietpi-set_swapfile 428 zram | $ sudo /boot/dietpi/func/dietpi-set_swapfile 476 zram |
</pre></html></WRAP> | </pre></html></WRAP> |
<WRAP color_result><html><pre> | <WRAP color_result><html><pre> |
<b class=HIK>[</b> <b class=GRN>OK</b> <b class=HIK>] DietPi-Set_swapfile |</b> swapoff -a | <b class=HIK>[</b> <b class=GRN>OK</b> <b class=HIK>] DietPi-Set_swapfile |</b> swapoff -a |
<b class=HIK>[</b> <b class=GRN>OK</b> <b class=HIK>] DietPi-Set_swapfile |</b> Generating new swap space | <b class=HIK>[</b> <b class=GRN>OK</b> <b class=HIK>] DietPi-Set_swapfile |</b> Generating new swap space |
<b class=HIK>[</b> INFO <b class=HIK>] DietPi-Set_swapfile | Size = 428 MiB</b> | <b class=HIK>[</b> INFO <b class=HIK>] DietPi-Set_swapfile | Size = 476 MiB</b> |
<b class=HIK>[</b> INFO <b class=HIK>] DietPi-Set_swapfile | Path = /dev/zram0</b> | <b class=HIK>[</b> INFO <b class=HIK>] DietPi-Set_swapfile | Path = /dev/zram0</b> |
<b class=HIK>[</b> <b class=GRN>OK</b> <b class=HIK>] DietPi-Set_swapfile |</b> eval echo 1 > /sys/block/zram0/reset | <b class=HIK>[</b> <b class=GRN>OK</b> <b class=HIK>] DietPi-Set_swapfile |</b> eval echo 1 > /sys/block/zram0/reset |
<b class=HIK>[</b> <b class=GRN>OK</b> <b class=HIK>] DietPi-Set_swapfile |</b> eval echo '428M' > /sys/block/zram0/disksize | <b class=HIK>[</b> <b class=GRN>OK</b> <b class=HIK>] DietPi-Set_swapfile |</b> eval echo '476M' > /sys/block/zram0/disksize |
<b class=HIK>[</b> <b class=GRN>OK</b> <b class=HIK>] DietPi-Set_swapfile |</b> chmod 0600 /dev/zram0 | <b class=HIK>[</b> <b class=GRN>OK</b> <b class=HIK>] DietPi-Set_swapfile |</b> chmod 0600 /dev/zram0 |
<b class=HIK>[</b> <b class=GRN>OK</b> <b class=HIK>] DietPi-Set_swapfile |</b> mkswap /dev/zram0 | <b class=HIK>[</b> <b class=GRN>OK</b> <b class=HIK>] DietPi-Set_swapfile |</b> mkswap /dev/zram0 |
<b class=HIK>[</b> <b class=GRN>OK</b> <b class=HIK>] DietPi-Set_swapfile |</b> swapon /dev/zram0 | <b class=HIK>[</b> <b class=GRN>OK</b> <b class=HIK>] DietPi-Set_swapfile |</b> swapon /dev/zram0 |
<b class=HIK>[</b> <b class=GRN>OK</b> <b class=HIK>] DietPi-Set_swapfile |</b> eval echo 'zram' > /etc/modules-load.d/dietpi-zram-swap.conf | <b class=HIK>[</b> <b class=GRN>OK</b> <b class=HIK>] DietPi-Set_swapfile |</b> eval echo 'zram' > /etc/modules-load.d/dietpi-zram-swap.conf |
<b class=HIK>[</b> <b class=GRN>OK</b> <b class=HIK>] DietPi-Set_swapfile |</b> eval echo 'SUBSYSTEM=="block", KERNEL=="zram0", ACTION=="add", ATTR{disksize}="428M", RUN+="chmod 0600 /dev/zram0", RUN+="/sbin/mkswap /dev/zram0", RUN+="/sbin/swapon /dev/zram0"' > /etc/udev/rules.d/98-dietpi-zram-swap.rules | <b class=HIK>[</b> <b class=GRN>OK</b> <b class=HIK>] DietPi-Set_swapfile |</b> eval echo 'SUBSYSTEM=="block", KERNEL=="zram0", ACTION=="add", ATTR{disksize}="476M", RUN+="chmod 0600 /dev/zram0", RUN+="/sbin/mkswap /dev/zram0", RUN+="/sbin/swapon /dev/zram0"' > /etc/udev/rules.d/98-dietpi-zram-swap.rules |
<b class=HIK>[</b> <b class=GRN>OK</b> <b class=HIK>] DietPi-Set_swapfile |</b> eval echo 'swappiness=50' > /etc/sysctl.d/98-dietpi-zram-swap.conf | <b class=HIK>[</b> <b class=GRN>OK</b> <b class=HIK>] DietPi-Set_swapfile |</b> eval echo 'swappiness=50' > /etc/sysctl.d/98-dietpi-zram-swap.conf |
<b class=HIK>[</b> <b class=GRN>OK</b> <b class=HIK>] DietPi-Set_swapfile |</b> Setting in <b class=YEL>/boot/dietpi.txt</b> adjusted: <b class=YEL>AUTO_SETUP_SWAPFILE_SIZE=428</b> | <b class=HIK>[</b> <b class=GRN>OK</b> <b class=HIK>] DietPi-Set_swapfile |</b> Setting in <b class=YEL>/boot/dietpi.txt</b> adjusted: <b class=YEL>AUTO_SETUP_SWAPFILE_SIZE=476</b> |
<b class=HIK>[</b> <b class=GRN>OK</b> <b class=HIK>] DietPi-Set_swapfile |</b> Desired setting in <b class=YEL>/boot/dietpi.txt</b> was already set: <b class=YEL>AUTO_SETUP_SWAPFILE_LOCATION=zram</b> | <b class=HIK>[</b> <b class=GRN>OK</b> <b class=HIK>] DietPi-Set_swapfile |</b> Desired setting in <b class=YEL>/boot/dietpi.txt</b> was already set: <b class=YEL>AUTO_SETUP_SWAPFILE_LOCATION=zram</b> |
<b class=HIK>[</b> INFO <b class=HIK>] DietPi-Set_swapfile | Setting /tmp tmpfs size: 428 MiB</b> | <b class=HIK>[</b> INFO <b class=HIK>] DietPi-Set_swapfile | Setting /tmp tmpfs size: 476 MiB</b> |
<b class=HIK>[</b> <b class=GRN>OK</b> <b class=HIK>] DietPi-Set_swapfile |</b> mount -o remount /tmp | <b class=HIK>[</b> <b class=GRN>OK</b> <b class=HIK>] DietPi-Set_swapfile |</b> mount -o remount /tmp |
</pre></html></WRAP> | </pre></html></WRAP> |
</WRAP> | </WRAP> |
| |
=== さらに Swap を 3072MB 追加する === | === ZRAM の他にさらに Swap を 3072MB 追加する === |
<WRAP color_term> | <WRAP color_term> |
<WRAP color_command><html><pre> | <WRAP color_command><html><pre> |
$ sudo fallocate -l 3072M /var/swap | $ sudo fallocate -l 3072M /var/swap |
$ sudo chmod 0600 /var/swap | $ sudo chmod 0600 /var/swap |
| $ sudo mkswap /var/swap |
</pre></html></WRAP> | </pre></html></WRAP> |
<WRAP color_result><html><pre> | <WRAP color_result><html><pre> |
</pre></html></WRAP> | </pre></html></WRAP> |
<WRAP color_command><html><pre> | <WRAP color_command><html><pre> |
$ sudo swapon /var/swap | $ sudo swapon -v /var/swap |
$ sudo swapon -s | $ sudo swapon -s |
</pre></html></WRAP> | </pre></html></WRAP> |
<WRAP color_result><html><pre> | <WRAP color_result><html><pre> |
Filename Type Size Used Priority | Filename Type Size Used Priority |
/dev/zram0 partition 438268 56152 -2 | /dev/zram0 partition 487420 0 -2 |
/var/swap file 3145724 0 -3 | /var/swap file 3145724 0 -3 |
</pre></html></WRAP> | </pre></html></WRAP> |
<WRAP color_result><html><pre> | <WRAP color_result><html><pre> |
total used free shared buff/cache available | total used free shared buff/cache available |
Mem: 429 141 43 192 244 46 | Mem: 477 29 405 1 42 402 |
Swap: 3499 55 3444 | Swap: 3499 55 3444 |
</pre></html></WRAP> | </pre></html></WRAP> |
<WRAP color_term> | <WRAP color_term> |
<WRAP color_command><html><pre> | <WRAP color_command><html><pre> |
$ echo '/var/swap none swap sw' | sudo tee -a /etc/fstab | $ echo '/var/swap none swap sw 0 0' | sudo tee -a /etc/fstab |
</pre></html></WRAP> | </pre></html></WRAP> |
<WRAP color_result><html><pre> | <WRAP color_result><html><pre> |
/var/swap none swap sw | /var/swap none swap sw 0 0 |
</pre></html></WRAP> | </pre></html></WRAP> |
</WRAP> | </WRAP> |
| ※[[https://unix.stackexchange.com/questions/365953/what-sw-means-in-the-fstab-swap-entry-for-mount-options-column|What 'sw' means in the fstab swap entry for 'mount options' column]]\\ |
| [[https://forums.ubuntulinux.jp/viewtopic.php?id=20079|Ubuntu日本語フォーラム / swap fileの設定をfstabへの記述するときの設定値の違いについて]]\\ |
| |
==== dietpi-set_swapfile の動作... ==== | ==== dietpi-set_swapfile の動作... ==== |
| |
<b class=DiYE>DietPi-Set_swapfile</b> | <b class=DiYE>DietPi-Set_swapfile</b> |
───────────────────────────────────────────────────── | <b class=BoHIK>─────────────────────────────────────────────────────</b> |
Mode: Applying 1 /var/swap | <b class=HIK>Mode:</b> Applying 1 /var/swap |
| |
<b class=HIK>[</b> INFO <b class=HIK>] DietPi-Set_swapfile | Disabling and deleting all existing swap files</b> | <b class=HIK>[</b> INFO <b class=HIK>] DietPi-Set_swapfile | Disabling and deleting all existing swap files</b> |
| |
<b class=DiYE>DietPi-Set_swapfile</b> | <b class=DiYE>DietPi-Set_swapfile</b> |
───────────────────────────────────────────────────── | <b class=BoHIK>─────────────────────────────────────────────────────</b> |
Mode: Applying 3072 /var/swap | <b class=HIK>Mode:</b> Applying 3072 /var/swap |
| |
<b class=HIK>[</b> INFO <b class=HIK>] DietPi-Set_swapfile | Disabling and deleting all existing swap files</b> | <b class=HIK>[</b> INFO <b class=HIK>] DietPi-Set_swapfile | Disabling and deleting all existing swap files</b> |
429 | 429 |
</code> | </code> |
| </WRAP> |
| |
| === ZRAM にさらに Swap を 3072MB 追加する === |
| <WRAP color_term> |
| <WRAP color_command><html><pre> |
| $ sudo fallocate -l 3072M /var/swap |
| $ sudo chmod 0600 /var/swap |
| $ sudo mkswap /var/swap |
| </pre></html></WRAP> |
| <WRAP color_result><html><pre> |
| Setting up swapspace version 1, size = 3 GiB (3221221376 bytes) |
| no label, UUID=9239781e-559a-47a4-b17c-f9f359004181 |
| |
| </pre></html></WRAP> |
| <WRAP color_command><html><pre> |
| $ sudo swapon /var/swap |
| $ sudo swapon -s |
| </pre></html></WRAP> |
| <WRAP color_result><html><pre> |
| Filename Type Size Used Priority |
| /dev/zram0 partition 438268 56152 -2 |
| /var/swap file 3145724 0 -3 |
| </pre></html></WRAP> |
| <WRAP color_command><html><pre> |
| $ free -m |
| </pre></html></WRAP> |
| <WRAP color_result><html><pre> |
| total used free shared buff/cache available |
| Mem: 429 141 43 192 244 46 |
| Swap: 3499 55 3444 |
| </pre></html></WRAP> |
| </WRAP> |
| |
| <WRAP color_term> |
| <WRAP color_command><html><pre> |
| $ echo '/var/swap none swap sw' | sudo tee -a /etc/fstab |
| </pre></html></WRAP> |
| <WRAP color_result><html><pre> |
| /var/swap none swap sw |
| </pre></html></WRAP> |
| </WRAP> |
| |
| 再起動すると...😱 zram が優先されない😥\\ |
| <WRAP color_term> |
| <WRAP color_command><html><pre> |
| $ sudo reboot |
| $ sudo swapon -s |
| </pre></html></WRAP> |
| <WRAP color_result><html><pre> |
| Filename Type Size Used Priority |
| /var/swap file 3145724 256 -2 |
| /dev/zram0 partition 438268 0 -3 |
| </pre></html></WRAP> |
| </WRAP> |
| |
| <WRAP color_term> |
| <WRAP color_command><html><pre> |
| $ sudo nano /etc/udev/rules.d/98-dietpi-zram-swap.rules |
| </pre></html></WRAP> |
| <WRAP color_result><html><pre> |
| </pre></html></WRAP> |
| </WRAP> |
| |
| <WRAP mincode> |
| 修正前🤔\\ |
| <code autoconf /etc/udev/rules.d/98-dietpi-zram-swap.rules> |
| SUBSYSTEM=="block", KERNEL=="zram0", ACTION=="add", ATTR{disksize}="428M", RUN+="chmod 0600 /dev/zram0", RUN+="/sbin/mkswap /dev/zram0", RUN+="/sbin/swapon /dev/zram0" |
| </code> |
| |
| **swapon** に priority **100** を指定する🤤 (大きい priority が優先される🤔ここでは 100 の zram0 から優先して使われる😻)\\ |
| <code autoconf /etc/udev/rules.d/98-dietpi-zram-swap.rules> |
| SUBSYSTEM=="block", KERNEL=="zram0", ACTION=="add", ATTR{disksize}="428M", RUN+="chmod 0600 /dev/zram0", RUN+="/sbin/mkswap /dev/zram0", RUN+="/sbin/swapon -p 100 /dev/zram0" |
| </code> |
| </WRAP> |
| |
| 再起動すると...😱 zram が優先される🥰\\ |
| <WRAP color_term> |
| <WRAP color_command><html><pre> |
| $ sudo reboot |
| $ sudo swapon -s |
| Filename Type Size Used Priority |
| /var/swap file 3145724 0 -2 |
| /dev/zram0 partition 438268 256 100 |
| </pre></html></WRAP> |
</WRAP> | </WRAP> |
| |
</WRAP> | </WRAP> |
| |
===== Zram-swap-config ===== | ===== Zram-swap-config 編 ===== |
| |
==== git のインストール ==== | ==== git のインストール ==== |
[[qita>wnoguchi/items/2fc3ec11043d139dc6bb|teeコマンドの使い方 - Qiita (swappiness の設定)]]\\ | [[qita>wnoguchi/items/2fc3ec11043d139dc6bb|teeコマンドの使い方 - Qiita (swappiness の設定)]]\\ |
[[https://atmarkit.itmedia.co.jp/ait/articles/1611/16/news022.html|【 tee 】コマンド――標準出力とファイルの両方に出力する]]\\ | [[https://atmarkit.itmedia.co.jp/ait/articles/1611/16/news022.html|【 tee 】コマンド――標準出力とファイルの両方に出力する]]\\ |
| [[https://www.digitalocean.com/community/tutorials/how-to-add-swap-space-on-ubuntu-20-04-ja|Ubuntu 20.04にスワップ領域を追加する方法 | DigitalOcean]]\\ |
| [[https://ja.stackoverflow.com/questions/21468/1gb%E3%81%AE%E3%83%80%E3%83%9F%E3%83%BC%E3%83%95%E3%82%A1%E3%82%A4%E3%83%AB%E3%82%92%E4%BD%9C%E6%88%90%E3%81%99%E3%82%8B%E3%82%B3%E3%83%9E%E3%83%B3%E3%83%89%E3%81%AF|1GBのダミーファイルを作成するコマンドは?]]\\ |
| [[https://qiita.com/hana_shin/items/53c3c78525c9c758ae7c|すぐ忘れてしまう、仕事で使う技 - Qiita]]\\ |
| [[https://community.clearlinux.org/t/how-to-make-zram-swap-persistent-with-higher-priority/3641/2|How to make zram swap persistent with higher priority? - Q&A - Clear Linux OS Forum]]\\ |
| [[https://superuser.com/questions/173353/how-permanently-change-linux-swap-disk-priority|How permanently change Linux swap disk priority]]\\ |
| [[https://kazmax.zpp.jp/linux_beginner/mkswap.html|linux スワップ(swap)領域の作成]]\\ |
| [[https://kazmax.zpp.jp/cmd/s/swapon.8.html|swapon - システム管理コマンドの説明 - Linux コマンド集 一覧表]]\\ |
| |