將 /tmp 從 ramdisk 移至其他分割區

將 /tmp 從 ramdisk 移至其他分割區

由於 Debian 上的 RAM 不足,我需要將 /tmp 移至 SSD 驅動器。但我仍然不知道如何做到這一點,以便使用它的程式仍然可以在 /tmp 路徑下存取它。

所以基本上,我想要實現的是將 /tmp 從 ramdisk 移動到例如 /home/tmp。並且能夠透過/tmp存取它

答案1

systemctl mask tmp.mount

此指令指示systemd不要tmpfs在 /tmp 上安裝基於 RAM 的檔案系統 ( )。若要套用更改,您必須重新啟動系統。

在大多數情況下,這就是您需要做的全部。無需將 /tmp 重新導向到 /home/tmp 或其他任何地方。官方推薦這個方法系統文件 --

我只是想擺脫 tmpfs 支援的 /tmp!

您有三個選擇:

  1. 停用 /tmp 上的任何安裝,以便它與根目錄駐留在同一實體檔案系統上。為此,執行 systemctl mask tmp.mount
  2. 將不同的實體檔案系統安裝到 /tmp。為此,只需在 /etc/fstab 中為其建立一個條目,就像對任何其他檔案系統所做的那樣。
  3. 保留 /tmp 但增加/減少其大小。為此,只需在 /etc/fstab 中為其建立一個條目,就像對任何其他 tmpfs 檔案系統所做的那樣,並使用正確的 size= 選項。

為什麼不需要將 /tmp 例如重定向到 /home/tmp?

上面應該將 /tmp 保留為內部可寫目錄/(根檔案系統)。適用於 Debian 或大多數其他 Linux 發行版的軟體應該僅將 /tmp 用於一小部分文件,因此我不必擔心根文件系統中的空間不足。此要求主要源自於 /tmp 可能是 RAM 檔案系統的想法:-)。

您無需擔心 /tmp 隨著時間的推移會被陳舊的文件填滿。 /tmp 在啟動時自動清理:

$ 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

# There are more lines here, but they are not important to this answer
# ...

相關內容