オプション1:サービスを恒久的に変更

オプション1:サービスを恒久的に変更

aたとえば、大容量の中間ファイルを作成し、/tmp/aoutputそのbファイルを読み取り、さらに作業を行う2つのステップで構成される長いプロセスを実行するとします。

このステップの実行中にシステムがbクラッシュします。どういうわけかシステムを再起動できますか?いいえまず、完全に実行せずに/tmpすぐに再起動できるように削除する項目(通常は起動時に発生)は何ですか?ba

もちろん/tmpこれはtmpfs

HDD / SSDを物理的に削除したり、ライブUSBメディアから起動したりするソリューションを除外したいと思います。現在、私の特定のケースでは、実際にはフルディスク暗号化機能を備えたSSDですが、暗号化されていないドライブでのみ機能するソリューションにも興味があります。


編集する現時点では質問が残っています。どちらの答えも、ライブメディアや事前設定の調整なしで動作するソリューションを提供しないためです。おそらく他の方法はないかもしれませんが、奇妙に見えます。 GRUBはすでにLinuxを起動するためにパーティションをマウントしませんか?それでは、ファイルを手動で移動する方法はありますか?今後リリースされたことがありますかsystemd?おそらく私が間違っている可能性があり、ブートローダーについてよく知らないかもしれませんが、なぜこれが可能ではないのかを聞きたいです。


systemd構成情報:

$ grep -s . /*/tmpfiles.d/*.conf /*/*/tmpfiles.d/*.conf
/run/tmpfiles.d/kmod.conf:c! /dev/fuse 0600 - - - 10:229
/run/tmpfiles.d/kmod.conf:c! /dev/cuse 0600 - - - 10:203
/run/tmpfiles.d/kmod.conf:c! /dev/btrfs-control 0600 - - - 10:234
/run/tmpfiles.d/kmod.conf:d /dev/net 0755 - - -
/run/tmpfiles.d/kmod.conf:c! /dev/net/tun 0600 - - - 10:200
/run/tmpfiles.d/kmod.conf:c! /dev/ppp 0600 - - - 108:0
/run/tmpfiles.d/kmod.conf:c! /dev/uinput 0600 - - - 10:223
/run/tmpfiles.d/kmod.conf:d /dev/mapper 0755 - - -
/run/tmpfiles.d/kmod.conf:c! /dev/mapper/control 0600 - - - 10:236
/run/tmpfiles.d/kmod.conf:c! /dev/uhid 0600 - - - 10:239
/run/tmpfiles.d/kmod.conf:c! /dev/vhci 0600 - - - 10:137
/run/tmpfiles.d/kmod.conf:d /dev/snd 0755 - - -
/run/tmpfiles.d/kmod.conf:c! /dev/snd/timer 0600 - - - 116:33
/run/tmpfiles.d/kmod.conf:d /dev/snd 0755 - - -
/run/tmpfiles.d/kmod.conf:c! /dev/snd/seq 0600 - - - 116:1
/usr/lib/tmpfiles.d/00rsyslog.conf:# Override systemd's default tmpfiles.d/var.conf to make /var/log writable by
/usr/lib/tmpfiles.d/00rsyslog.conf:# the syslog group, so that rsyslog can run as user.
/usr/lib/tmpfiles.d/00rsyslog.conf:# See tmpfiles.d(5) for details.
/usr/lib/tmpfiles.d/00rsyslog.conf:# Type Path    Mode UID  GID  Age Argument
/usr/lib/tmpfiles.d/00rsyslog.conf:d /var/log 0775 root syslog -
/usr/lib/tmpfiles.d/dbus.conf:# Type Path                     Mode    UID     GID     Age     Argument
/usr/lib/tmpfiles.d/dbus.conf:L /var/lib/dbus/machine-id      -       -       -       -       /etc/machine-id
/usr/lib/tmpfiles.d/debian.conf:#  This file is part of the debianisation of systemd.
/usr/lib/tmpfiles.d/debian.conf:#
/usr/lib/tmpfiles.d/debian.conf:#  systemd is free software; you can redistribute it and/or modify it
/usr/lib/tmpfiles.d/debian.conf:#  under the terms of the GNU General Public License as published by
/usr/lib/tmpfiles.d/debian.conf:#  the Free Software Foundation; either version 2 of the License, or
/usr/lib/tmpfiles.d/debian.conf:#  (at your option) any later version.
/usr/lib/tmpfiles.d/debian.conf:# See tmpfiles.d(5) for details
/usr/lib/tmpfiles.d/debian.conf:# Type Path    Mode UID  GID  Age Argument
/usr/lib/tmpfiles.d/debian.conf:L /run/initctl -    -    -    -   /run/systemd/initctl/fifo
/usr/lib/tmpfiles.d/debian.conf:L /run/shm     -    -    -    -   /dev/shm
/usr/lib/tmpfiles.d/debian.conf:d /run/sendsigs.omit.d 0755 root root -
/usr/lib/tmpfiles.d/debian.conf:L+ /etc/mtab   -    -    -    -  ../proc/self/mounts
/usr/lib/tmpfiles.d/gvfsd-fuse-tmpfiles.conf:# This is a systemd tmpfiles.d configuration file
/usr/lib/tmpfiles.d/gvfsd-fuse-tmpfiles.conf:#
/usr/lib/tmpfiles.d/gvfsd-fuse-tmpfiles.conf:# tmpfiles.d defaults are set to clean /run/user every now and then
/usr/lib/tmpfiles.d/gvfsd-fuse-tmpfiles.conf:# which includes our gvfs-fuse mount being mounted in /run/user/<id>/gvfs
/usr/lib/tmpfiles.d/gvfsd-fuse-tmpfiles.conf:#
/usr/lib/tmpfiles.d/gvfsd-fuse-tmpfiles.conf:# This file adds an exclusion rule so that user data don't get automatically
/usr/lib/tmpfiles.d/gvfsd-fuse-tmpfiles.conf:# cleaned up (i.e. destroyed).
/usr/lib/tmpfiles.d/gvfsd-fuse-tmpfiles.conf:#
/usr/lib/tmpfiles.d/gvfsd-fuse-tmpfiles.conf:# Due to our fuse mount restrictions root can't access nor stat the mountpoint
/usr/lib/tmpfiles.d/gvfsd-fuse-tmpfiles.conf:# resulting in warning spitted out by the systemd-tmpfiles process. Please
/usr/lib/tmpfiles.d/gvfsd-fuse-tmpfiles.conf:# ignore it for the time being until proper solution is found:
/usr/lib/tmpfiles.d/gvfsd-fuse-tmpfiles.conf:# https://bugzilla.gnome.org/show_bug.cgi?id=560658
/usr/lib/tmpfiles.d/gvfsd-fuse-tmpfiles.conf:x /run/user/*/gvfs
/usr/lib/tmpfiles.d/home.conf:#  This file is part of systemd.
/usr/lib/tmpfiles.d/home.conf:#
/usr/lib/tmpfiles.d/home.conf:#  systemd is free software; you can redistribute it and/or modify it
/usr/lib/tmpfiles.d/home.conf:#  under the terms of the GNU Lesser General Public License as published by
/usr/lib/tmpfiles.d/home.conf:#  the Free Software Foundation; either version 2.1 of the License, or
/usr/lib/tmpfiles.d/home.conf:#  (at your option) any later version.
/usr/lib/tmpfiles.d/home.conf:# See tmpfiles.d(5) for details
/usr/lib/tmpfiles.d/home.conf:Q /home 0755 - - -
/usr/lib/tmpfiles.d/home.conf:q /srv 0755 - - -
/usr/lib/tmpfiles.d/journal-nocow.conf:#  This file is part of systemd.
/usr/lib/tmpfiles.d/journal-nocow.conf:#
/usr/lib/tmpfiles.d/journal-nocow.conf:#  systemd is free software; you can redistribute it and/or modify it
/usr/lib/tmpfiles.d/journal-nocow.conf:#  under the terms of the GNU Lesser General Public License as published by
/usr/lib/tmpfiles.d/journal-nocow.conf:#  the Free Software Foundation; either version 2.1 of the License, or
/usr/lib/tmpfiles.d/journal-nocow.conf:#  (at your option) any later version.
/usr/lib/tmpfiles.d/journal-nocow.conf:# See tmpfiles.d(5) for details
/usr/lib/tmpfiles.d/journal-nocow.conf:# Set the NOCOW attribute for directories of journal files. This flag
/usr/lib/tmpfiles.d/journal-nocow.conf:# is inheredited by their new files and sub-directories. Matters only
/usr/lib/tmpfiles.d/journal-nocow.conf:# for btrfs filesystems.
/usr/lib/tmpfiles.d/journal-nocow.conf:#
/usr/lib/tmpfiles.d/journal-nocow.conf:# WARNING: Enabling the NOCOW attribute improves journal performance
/usr/lib/tmpfiles.d/journal-nocow.conf:#     substantially, but also disables the btrfs checksum logic. In
/usr/lib/tmpfiles.d/journal-nocow.conf:#     btrfs RAID filesystems the checksums are needed for rebuilding
/usr/lib/tmpfiles.d/journal-nocow.conf:#     corrupted files. Without checksums such rebuilds are not
/usr/lib/tmpfiles.d/journal-nocow.conf:#     possible.
/usr/lib/tmpfiles.d/journal-nocow.conf:#
/usr/lib/tmpfiles.d/journal-nocow.conf:# In a single-disk filesystem (or a filesystem without redundancy)
/usr/lib/tmpfiles.d/journal-nocow.conf:# enabling the NOCOW attribute for journal files is safe, because
/usr/lib/tmpfiles.d/journal-nocow.conf:# they have their own checksums and a rebuilding wouldn't be possible
/usr/lib/tmpfiles.d/journal-nocow.conf:# in any case.
/usr/lib/tmpfiles.d/journal-nocow.conf:h /var/log/journal - - - - +C
/usr/lib/tmpfiles.d/journal-nocow.conf:h /var/log/journal/%m - - - - +C
/usr/lib/tmpfiles.d/journal-nocow.conf:h /var/log/journal/remote - - - - +C
/usr/lib/tmpfiles.d/legacy.conf:#  This file is part of systemd.
/usr/lib/tmpfiles.d/legacy.conf:#
/usr/lib/tmpfiles.d/legacy.conf:#  systemd is free software; you can redistribute it and/or modify it
/usr/lib/tmpfiles.d/legacy.conf:#  under the terms of the GNU Lesser General Public License as published by
/usr/lib/tmpfiles.d/legacy.conf:#  the Free Software Foundation; either version 2.1 of the License, or
/usr/lib/tmpfiles.d/legacy.conf:#  (at your option) any later version.
/usr/lib/tmpfiles.d/legacy.conf:# See tmpfiles.d(5) for details
/usr/lib/tmpfiles.d/legacy.conf:# These files are considered legacy and are unnecessary on legacy-free
/usr/lib/tmpfiles.d/legacy.conf:# systems.
/usr/lib/tmpfiles.d/legacy.conf:L /var/lock - - - - ../run/lock
/usr/lib/tmpfiles.d/legacy.conf:# /run/lock/subsys is used for serializing SysV service execution, and
/usr/lib/tmpfiles.d/legacy.conf:# hence without use on SysV-less systems.
/usr/lib/tmpfiles.d/legacy.conf:d /run/lock/subsys 0755 root root -
/usr/lib/tmpfiles.d/legacy.conf:# /forcefsck, /fastboot and /forcequotacheck are deprecated in favor of the
/usr/lib/tmpfiles.d/legacy.conf:# kernel command line options 'fsck.mode=force', 'fsck.mode=skip' and
/usr/lib/tmpfiles.d/legacy.conf:# 'quotacheck.mode=force'
/usr/lib/tmpfiles.d/legacy.conf:r! /forcefsck
/usr/lib/tmpfiles.d/legacy.conf:r! /fastboot
/usr/lib/tmpfiles.d/legacy.conf:r! /forcequotacheck
/usr/lib/tmpfiles.d/man-db.conf:d /var/cache/man 2755 man root 1w
/usr/lib/tmpfiles.d/passwd.conf:# If a password operation is in progress and we lose power, stale lockfiles
/usr/lib/tmpfiles.d/passwd.conf:# can be left behind.  Clear them on boot.
/usr/lib/tmpfiles.d/passwd.conf:r! /etc/gshadow.lock
/usr/lib/tmpfiles.d/passwd.conf:r! /etc/shadow.lock
/usr/lib/tmpfiles.d/passwd.conf:r! /etc/passwd.lock
/usr/lib/tmpfiles.d/passwd.conf:r! /etc/group.lock
/usr/lib/tmpfiles.d/passwd.conf:r! /etc/subuid.lock
/usr/lib/tmpfiles.d/passwd.conf:r! /etc/subgid.lock
/usr/lib/tmpfiles.d/samba.conf:d /run/samba 0755 root root -
/usr/lib/tmpfiles.d/sshd.conf:d /var/run/sshd 0755 root root
/usr/lib/tmpfiles.d/sudo.conf:# Create an empty sudo time stamp directory on OSes using systemd.
/usr/lib/tmpfiles.d/sudo.conf:# Sudo will create the directory itself but this can cause problems
/usr/lib/tmpfiles.d/sudo.conf:# on systems that have SELinux enabled since the directories will be
/usr/lib/tmpfiles.d/sudo.conf:# created with the user's security context.
/usr/lib/tmpfiles.d/sudo.conf:d /var/run/sudo 0711 root root
/usr/lib/tmpfiles.d/sudo.conf:D /var/run/sudo/ts 0700 root root
/usr/lib/tmpfiles.d/systemd.conf:#  This file is part of systemd.
/usr/lib/tmpfiles.d/systemd.conf:#
/usr/lib/tmpfiles.d/systemd.conf:#  systemd is free software; you can redistribute it and/or modify it
/usr/lib/tmpfiles.d/systemd.conf:#  under the terms of the GNU Lesser General Public License as published by
/usr/lib/tmpfiles.d/systemd.conf:#  the Free Software Foundation; either version 2.1 of the License, or
/usr/lib/tmpfiles.d/systemd.conf:#  (at your option) any later version.
/usr/lib/tmpfiles.d/systemd.conf:# See tmpfiles.d(5) for details
/usr/lib/tmpfiles.d/systemd.conf:d /run/user 0755 root root -
/usr/lib/tmpfiles.d/systemd.conf:F! /run/utmp 0664 root utmp -
/usr/lib/tmpfiles.d/systemd.conf:d /run/systemd/ask-password 0755 root root -
/usr/lib/tmpfiles.d/systemd.conf:d /run/systemd/seats 0755 root root -
/usr/lib/tmpfiles.d/systemd.conf:d /run/systemd/sessions 0755 root root -
/usr/lib/tmpfiles.d/systemd.conf:d /run/systemd/users 0755 root root -
/usr/lib/tmpfiles.d/systemd.conf:d /run/systemd/machines 0755 root root -
/usr/lib/tmpfiles.d/systemd.conf:d /run/systemd/shutdown 0755 root root -
/usr/lib/tmpfiles.d/systemd.conf:d /run/systemd/netif 0755 systemd-network systemd-network -
/usr/lib/tmpfiles.d/systemd.conf:d /run/systemd/netif/links 0755 systemd-network systemd-network -
/usr/lib/tmpfiles.d/systemd.conf:d /run/systemd/netif/leases 0755 systemd-network systemd-network -
/usr/lib/tmpfiles.d/systemd.conf:d /run/log 0755 root root -
/usr/lib/tmpfiles.d/systemd.conf:z /run/log/journal 2755 root systemd-journal - -
/usr/lib/tmpfiles.d/systemd.conf:Z /run/log/journal/%m ~2750 root systemd-journal - -
/usr/lib/tmpfiles.d/systemd.conf:a+ /run/log/journal/%m - - - - d:group:adm:r-x
/usr/lib/tmpfiles.d/systemd.conf:A+ /run/log/journal/%m - - - - group:adm:r-x
/usr/lib/tmpfiles.d/systemd.conf:z /var/log/journal 2755 root systemd-journal - -
/usr/lib/tmpfiles.d/systemd.conf:z /var/log/journal/%m 2755 root systemd-journal - -
/usr/lib/tmpfiles.d/systemd.conf:z /var/log/journal/%m/system.journal 0640 root systemd-journal - -
/usr/lib/tmpfiles.d/systemd.conf:a+ /var/log/journal    - - - - d:group:adm:r-x
/usr/lib/tmpfiles.d/systemd.conf:a+ /var/log/journal    - - - - group:adm:r-x
/usr/lib/tmpfiles.d/systemd.conf:a+ /var/log/journal/%m - - - - d:group:adm:r-x
/usr/lib/tmpfiles.d/systemd.conf:a+ /var/log/journal/%m - - - - group:adm:r-x
/usr/lib/tmpfiles.d/systemd.conf:a+ /var/log/journal/%m/system.journal - - - - group:adm:r--
/usr/lib/tmpfiles.d/systemd.conf:d /var/lib/systemd 0755 root root -
/usr/lib/tmpfiles.d/systemd.conf:d /var/lib/systemd/coredump 0755 root root 3d
/usr/lib/tmpfiles.d/systemd-nologin.conf:#  This file is part of systemd.
/usr/lib/tmpfiles.d/systemd-nologin.conf:#
/usr/lib/tmpfiles.d/systemd-nologin.conf:#  systemd is free software; you can redistribute it and/or modify it
/usr/lib/tmpfiles.d/systemd-nologin.conf:#  under the terms of the GNU Lesser General Public License as published by
/usr/lib/tmpfiles.d/systemd-nologin.conf:#  the Free Software Foundation; either version 2.1 of the License, or
/usr/lib/tmpfiles.d/systemd-nologin.conf:#  (at your option) any later version.
/usr/lib/tmpfiles.d/systemd-nologin.conf:# See tmpfiles.d(5), systemd-user-session.service(5) and pam_nologin(8).
/usr/lib/tmpfiles.d/systemd-nologin.conf:# This file has special suffix so it is not run by mistake.
/usr/lib/tmpfiles.d/systemd-nologin.conf:F! /run/nologin 0644 - - - "System is booting up. See pam_nologin(8)"
/usr/lib/tmpfiles.d/tmp.conf:#  This file is part of systemd.
/usr/lib/tmpfiles.d/tmp.conf:#
/usr/lib/tmpfiles.d/tmp.conf:#  systemd is free software; you can redistribute it and/or modify it
/usr/lib/tmpfiles.d/tmp.conf:#  under the terms of the GNU Lesser General Public License as published by
/usr/lib/tmpfiles.d/tmp.conf:#  the Free Software Foundation; either version 2.1 of the License, or
/usr/lib/tmpfiles.d/tmp.conf:#  (at your option) any later version.
/usr/lib/tmpfiles.d/tmp.conf:# See tmpfiles.d(5) for details
/usr/lib/tmpfiles.d/tmp.conf:# Clear tmp directories separately, to make them easier to override
/usr/lib/tmpfiles.d/tmp.conf:D /tmp 1777 root root -
/usr/lib/tmpfiles.d/tmp.conf:#q /var/tmp 1777 root root 30d
/usr/lib/tmpfiles.d/tmp.conf:# Exclude namespace mountpoints created with PrivateTmp=yes
/usr/lib/tmpfiles.d/tmp.conf:x /tmp/systemd-private-%b-*
/usr/lib/tmpfiles.d/tmp.conf:X /tmp/systemd-private-%b-*/tmp
/usr/lib/tmpfiles.d/tmp.conf:x /var/tmp/systemd-private-%b-*
/usr/lib/tmpfiles.d/tmp.conf:X /var/tmp/systemd-private-%b-*/tmp
/usr/lib/tmpfiles.d/var.conf:#  This file is part of systemd.
/usr/lib/tmpfiles.d/var.conf:#
/usr/lib/tmpfiles.d/var.conf:#  systemd is free software; you can redistribute it and/or modify it
/usr/lib/tmpfiles.d/var.conf:#  under the terms of the GNU Lesser General Public License as published by
/usr/lib/tmpfiles.d/var.conf:#  the Free Software Foundation; either version 2.1 of the License, or
/usr/lib/tmpfiles.d/var.conf:#  (at your option) any later version.
/usr/lib/tmpfiles.d/var.conf:# See tmpfiles.d(5) for details
/usr/lib/tmpfiles.d/var.conf:q /var 0755 - - -
/usr/lib/tmpfiles.d/var.conf:L /var/run - - - - ../run
/usr/lib/tmpfiles.d/var.conf:d /var/log 0755 - - -
/usr/lib/tmpfiles.d/var.conf:f /var/log/wtmp 0664 root utmp -
/usr/lib/tmpfiles.d/var.conf:f /var/log/btmp 0600 root utmp -
/usr/lib/tmpfiles.d/var.conf:d /var/cache 0755 - - -
/usr/lib/tmpfiles.d/var.conf:d /var/lib 0755 - - -
/usr/lib/tmpfiles.d/var.conf:d /var/spool 0755 - - -
/usr/lib/tmpfiles.d/x11.conf:#  This file is part of systemd.
/usr/lib/tmpfiles.d/x11.conf:#
/usr/lib/tmpfiles.d/x11.conf:#  systemd is free software; you can redistribute it and/or modify it
/usr/lib/tmpfiles.d/x11.conf:#  under the terms of the GNU Lesser General Public License as published by
/usr/lib/tmpfiles.d/x11.conf:#  the Free Software Foundation; either version 2.1 of the License, or
/usr/lib/tmpfiles.d/x11.conf:#  (at your option) any later version.
/usr/lib/tmpfiles.d/x11.conf:# See tmpfiles.d(5) for details
/usr/lib/tmpfiles.d/x11.conf:# Make sure these are created by default so that nobody else can
/usr/lib/tmpfiles.d/x11.conf:d /tmp/.X11-unix 1777 root root 10d
/usr/lib/tmpfiles.d/x11.conf:d /tmp/.ICE-unix 1777 root root 10d
/usr/lib/tmpfiles.d/x11.conf:d /tmp/.XIM-unix 1777 root root 10d
/usr/lib/tmpfiles.d/x11.conf:d /tmp/.font-unix 1777 root root 10d
/usr/lib/tmpfiles.d/x11.conf:d /tmp/.Test-unix 1777 root root 10d
/usr/lib/tmpfiles.d/x11.conf:# Unlink the X11 lock files
/usr/lib/tmpfiles.d/x11.conf:r! /tmp/.X[0-9]*-lock
/var/run/tmpfiles.d/kmod.conf:c! /dev/fuse 0600 - - - 10:229
/var/run/tmpfiles.d/kmod.conf:c! /dev/cuse 0600 - - - 10:203
/var/run/tmpfiles.d/kmod.conf:c! /dev/btrfs-control 0600 - - - 10:234
/var/run/tmpfiles.d/kmod.conf:d /dev/net 0755 - - -
/var/run/tmpfiles.d/kmod.conf:c! /dev/net/tun 0600 - - - 10:200
/var/run/tmpfiles.d/kmod.conf:c! /dev/ppp 0600 - - - 108:0
/var/run/tmpfiles.d/kmod.conf:c! /dev/uinput 0600 - - - 10:223
/var/run/tmpfiles.d/kmod.conf:d /dev/mapper 0755 - - -
/var/run/tmpfiles.d/kmod.conf:c! /dev/mapper/control 0600 - - - 10:236
/var/run/tmpfiles.d/kmod.conf:c! /dev/uhid 0600 - - - 10:239
/var/run/tmpfiles.d/kmod.conf:c! /dev/vhci 0600 - - - 10:137
/var/run/tmpfiles.d/kmod.conf:d /dev/snd 0755 - - -
/var/run/tmpfiles.d/kmod.conf:c! /dev/snd/timer 0600 - - - 116:33
/var/run/tmpfiles.d/kmod.conf:d /dev/snd 0755 - - -
/var/run/tmpfiles.d/kmod.conf:c! /dev/snd/seq 0600 - - - 116:1

ベストアンサー1

簡単に言うと:衝突が発生した場合は、ライブメディアを使用してください。それ以外の場合は、ファイルを/usr/lib/tmpfiles.d/tmp.confコピーして変更して/etc/tmpfiles.d/tmp.confシステムを設定してくださいetc

-D /tmp 1777 root root -
+d /tmp 1777 root root 1s
+x /tmp/*output

ファイルが特定のパターンに従わない場合は、代わりに次の設定を使用してください。

-D /tmp 1777 root root -
+d /tmp 1777 root root 12h

このステップの実行中にシステムがbクラッシュします。b最初に完全に実行せずにすぐに再起動できるように、/ tmpの内容(通常は起動時に発生)を削除しないようにシステムを再起動できますか?

さて、システムを設定できるなら今後衝突が発生します。このときシステムがクラッシュした場合〜しなければならないすべての共通systemd.targetrescue、、、)multi-userにはgraphical一時ファイルの削除も含まれるため、ライブメディアを使用してくださいrescue.target

つまり、次の崩壊に備えて、私たちはあなたのtmpfiles行動を変えることができます。ほとんどの Debian 派生は/tmpin の動作を定義します/usr/lib/tmpfiles.d/tmp.conf

$ cat /usr/lib/tmpfiles.d/tmp.conf
#  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.

# See tmpfiles.d(5) for details

# Clear tmp directories separately, to make them easier to override
D /tmp 1777 root root -
#q /var/tmp 1777 root root 30d

# Exclude namespace mountpoints created with PrivateTmp=yes
x /tmp/systemd-private-%b-*
X /tmp/systemd-private-%b-*/tmp
x /var/tmp/systemd-private-%b-*
X /var/tmp/systemd-private-%b-*/tmp

# Remove top-level private temporary directories on each boot
R! /tmp/systemd-private-*
R! /var/tmp/systemd-private-*

清掃を担当するラインは

D /tmp 1777 root root -

によると、tmpfiles.d(5)大文字はDそのディレクトリを削除する必要があることを示しますsystemd-tmpfiles --remove。残念ながら、このコマンドは次の理由でほぼすべてのターゲットで実行されますsystemd-tmpfiles-setup.service

$ systemctl cat systemd-tmpfiles-setup.service | grep Exec
ExecStart=/bin/systemd-tmpfiles --create --remove --boot --exclude-prefix=/dev

$ systemctl list-dependencies --reverse systemd-tmpfiles-setup.service | grep target
● └─sysinit.target
●   ├─basic.target
●   │ └─multi-user.target
●   │   └─graphical.target
●   └─rescue.target

--cleanまた、ジョブを実行して古いファイルを削除できるタイマーがいくつかあります。

状況に応じてさまざまなソリューションを使用できますが、どちらも完璧ではありません。

警告する:何をしても、/usr/lib/tmpfiles.d/内容を変更しないでください。代わりに、同じ名前のファイルを作成してください/etc/tmpfiles.d

sudo cp /usr/lib/tmpfiles.d/tmp.conf /etc/tmpfiles.d/tmp.conf

tmpfiles.d一般的なシステムルールに従ってください:/etc>> /run/usr/libこれは/etc/優先順位があります。

オプション1:サービスを恒久的に変更

/tmp上記のサービスにより--remove削除されました。systemctl editパラメータを使用してExecStartパラメータを削除できます--remove

$ systemctl edit systemd-tmpfiles-setup.service
ExecStart=
ExecStart=/bin/systemd-tmpfiles --create --boot --exclude-prefix=/dev

ExecStart元の構成を削除するには、追加のNULLが必要です。または、systemctl edit --full ...生成されたファイルを実行して編集します。

--remove不足により、Dすべてのプロファイルが効果的に無効になり、おそらく役に立たないため、お勧めできません。したがって、ルール定義を変更したい場合があります/tmp

オプション2:特定の期間のファイルに対してのみ/ tmpをクリーンアップ

/usr/lib/tmpfiles.d/tmp.confこの行をコピーして置き換えてください。/etc/tmpfiles.d/tmp.confD

-D /tmp 1777 root root -
+d /tmp 1777 root root 12h

これにより、すべてのファイルではなく12時間以上経過したファイルのみが削除されます。クラッシュ直後に再起動すれば、これで十分です。しかし、我々はさらに一歩進むことができます。

オプション3:プロジェクトファイルを除外

ファイルが常に同じ名前/パターンを持つ場合は、以下を除いてファイルが削除されるのを防ぎますx

-D /tmp 1777 root root -
+d /tmp 1777 root root 1s
+x /tmp/*output

呼び出す1sと、すべてのファイルが効果的に削除されます。systemd-tmpfilesとは別に /tmp/*outputファイル、たとえば/tmp/aoutputフォルダ全体を除外することもできます。

/tmp/この最後のバリエーションは問題を解決し、大きすぎる問題が発生するのを防ぐのに十分です。

構成の確認

構成を変更したら、テストする順番です。どのバリアントを使用しても、このテストは同じです。ファイルに同じ名前のファイルを作成し、/tmpsystemdサービスを実行します。

$ touch /tmp/my-project-files-{a,b,c,d,e,f} /tmp/some-test-garbage{1..10}
$ systemctl start systemd-tmpfiles-{clean,setup}.service

すべてが正しく設定されている場合は、「プロジェクト」ファイルがまだ存在している必要があります。除外バリアントを使用した場合、他のジャンクx/tmp/消えなければなりません。

引用する

  • tmpfiles.d(5)tmpfiles.d/*ファイル構文と優先順位
  • systemd.service(5)~のためExecStart
  • systemd.unit(5)ExecStart=カバーに使用
  • systemd-tmpfiles(8)tmpfiles風景の概要
  • ファイルがsystemd-tmpfiles-*.service通過しましたsystemctl cat systemd-tmpfiles-{clean,setup,setup-dev}.service

おすすめ記事