πŸ’£ Как ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚ΡŒ tmpfs для Π²Ρ€Π΅ΠΌΠ΅Π½Π½ΠΎΠ³ΠΎ ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³Π°

by itisgood

Как ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚ΡŒ tmpfs для Π²Ρ€Π΅ΠΌΠ΅Π½Π½ΠΎΠ³ΠΎ ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³Π° (/tmp).

ΠŸΡ€ΠΎΡΠΌΠΎΡ‚Ρ€ΠΈΡ‚Π΅ Π²Ρ€Π΅ΠΌΠ΅Π½Π½Ρ‹ΠΉ ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³ (/tmp) systemd mount.

$ cat  /usr/share/systemd/tmp.mount 
#  SPDX-License-Identifier: LGPL-2.1-or-later
#
#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation; either version 2.1 of the License, or
#  (at your option) any later version.

[Unit]
Description=Temporary Directory (/tmp)
Documentation=https://systemd.io/TEMPORARY_DIRECTORIES
Documentation=man:file-hierarchy(7)
Documentation=https://www.freedesktop.org/wiki/Software/systemd/APIFileSystems
ConditionPathIsSymbolicLink=!/tmp
DefaultDependencies=no
Conflicts=umount.target
Before=local-fs.target umount.target
After=swap.target

[Mount]
What=tmpfs
Where=/tmp
Type=tmpfs
Options=mode=1777,strictatime,nosuid,nodev,size=50%,nr_inodes=400k

[Install]
WantedBy=local-fs.target

Π‘ΠΊΠΎΠΏΠΈΡ€ΡƒΠΉΡ‚Π΅ Ρ„Π°ΠΉΠ» tmp.mount:

$ sudo cp  /usr/share/systemd/tmp.mount /etc/systemd/system/

ΠŸΠ΅Ρ€Π΅Π·Π°Π³Ρ€ΡƒΠ·ΠΈΡ‚Π΅ ΠΊΠΎΠ½Ρ„ΠΈΠ³ΡƒΡ€Π°Ρ†ΠΈΡŽ systemd.

$ sudo systemctl daemon-reload

ΠŸΡ€ΠΎΠ²Π΅Ρ€ΡŒΡ‚Π΅ состояниС монтирования tmp.

$ sudo systemctl status tmp.mount 
● tmp.mount - Temporary Directory (/tmp)
     Loaded: loaded (/etc/systemd/system/tmp.mount; disabled; vendor preset: enabled)
     Active: inactive (dead)
      Where: /tmp
       What: tmpfs
       Docs: https://systemd.io/TEMPORARY_DIRECTORIES
             man:file-hierarchy(7)
             https://www.freedesktop.org/wiki/Software/systemd/APIFileSystems

Π’ΠΊΠ»ΡŽΡ‡ΠΈΡ‚Π΅ ΠΌΠΎΠ½Ρ‚ΠΈΡ€ΠΎΠ²Π°Π½ΠΈΠ΅ tmp, Π½ΠΎ Π½Π΅ сСйчас, Ρ‚Π°ΠΊ ΠΊΠ°ΠΊ это ΠΌΠΎΠΆΠ΅Ρ‚ Π½Π°Ρ€ΡƒΡˆΠΈΡ‚ΡŒ Ρ€Π°Π±ΠΎΡ‚Ρƒ Π·Π°ΠΏΡƒΡ‰Π΅Π½Π½Ρ‹Ρ… ΠΏΡ€ΠΈΠ»ΠΎΠΆΠ΅Π½ΠΈΠΉ.

$ sudo systemctl enable tmp.mount 
Created symlink /etc/systemd/system/local-fs.target.wants/tmp.mount β†’ /etc/systemd/system/tmp.mount.

ΠŸΠ΅Ρ€Π΅Π·Π°Π³Ρ€ΡƒΠ·ΠΈΡ‚Π΅ систСму.

$ sudo reboot

ΠŸΡ€ΠΎΠ²Π΅Ρ€ΡŒΡ‚Π΅ состояниС монтирования tmp.

$ sudo systemctl status tmp.mount 
● tmp.mount - Temporary Directory (/tmp)
     Loaded: loaded (/etc/systemd/system/tmp.mount; enabled; vendor preset: enabled)
     Active: active (mounted) since Tue 2021-06-22 07:12:27 UTC; 1min 13s ago
      Where: /tmp
       What: tmpfs
       Docs: https://systemd.io/TEMPORARY_DIRECTORIES
             man:file-hierarchy(7)
             https://www.freedesktop.org/wiki/Software/systemd/APIFileSystems
      Tasks: 0 (limit: 1123)
     Memory: 4.0K
        CPU: 2ms
     CGroup: /system.slice/tmp.mount

Warning: journal has been rotated since unit was started, output may be incomplete.

ΠŸΡ€ΠΎΠ²Π΅Ρ€ΡŒΡ‚Π΅ Ρ€Π°Π·ΠΌΠ΅Ρ€ монтирования tmp.

$ df -h /tmp/
Filesystem      Size  Used Avail Use% Mounted on
tmpfs           485M     0  485M   0% /tmp

ΠŸΡ€ΠΎΠ²Π΅Ρ€ΡŒΡ‚Π΅ ΠΏΠ°Ρ€Π°ΠΌΠ΅Ρ‚Ρ€Ρ‹ монтирования tmp.

$ cat /proc/mounts | awk '$2 == "/tmp" {print}'
tmpfs /tmp tmpfs rw,nosuid,nodev,size=496024k,nr_inodes=409600 0 0

см. Ρ‚Π°ΠΊΠΆΠ΅:

 

Loading

You may also like

2 коммСнтария

Marat 13.12.2021 - 10:23

ΠšΠ°ΠΆΠ΅Ρ‚ΡΡ, systemd ΠΈ Ρ‚Π°ΠΊ ΠΏΠΎ ΡƒΠΌΠΎΠ»Ρ‡Π°Π½ΠΈΡŽ ΠΌΠΎΠ½Ρ‚ΠΈΡ€ΡƒΠ΅Ρ‚ /tmp Ρ‡Π΅Ρ€Π΅Π· tmpfs, ΠΈΠ»ΠΈ я ошибаюсь?

Reply
itisgood 14.12.2021 - 06:54

всС Ρ‚Π°ΠΊ, Ρ‚Π°ΠΊΠΆΠ΅ systemd ΠΏΠ΅Ρ€Π΅Π·Π°Ρ‚ΠΈΡ€Π°Π΅Ρ‚ tmp ΠΏΡ€ΠΈ ΠΏΠ΅Ρ€Π΅Π·Π°Π³Ρ€ΡƒΠ·ΠΊΠ΅

Reply

Leave a Comment