Summery of idea in a nutshell is basically to make the package set /tmp mount point to tmpfs and add a /etc/profile.d/ drop in to set the XDG_CACHE_HOME=/tmp/.cache variable for all users shell.
Idea for /etc/profile.d/xdg-cache.sh
#!/bin/sh
## Set XDG_CACHE_HOME to a per-user cache directory.
# Prefer a private sub-directory under /tmp when /tmp is a tmpfs.
# Fall back to ${HOME}/.cache if /tmp is not a tmpfs.
#
## Detect whether /tmp is a mount point (i.e. a separate filesystem).
# On most modern distros this will be a tmpfs, but on some it may
# be a regular disk partition.
if grep -q "^tmpfs.*/tmp.*tmpfs" /proc/mounts || mountpoint -q /tmp; then
# /tmp is a mount point - assume it is a tmpfs.
BASE_ROOT="/tmp/${USER}"
else
# /tmp is part of the root filesystem (disk based).
# Use the traditional default users /home based cache location instead.
BASE_ROOT="${HOME}"
fi
## Build the final cache directory path.
# We always put the cache in a ".cache" sub-folder so that tools
# that follow the XDG spec find what they expect.
CACHE_DIR="${BASE_ROOT}/.cache"
## Ensure the directory exists and is private to the user.
# /tmp is world-writable (drwxrwxrwt), so we must create a
# private subtree and lock it down with chmod 700.
#
# Create the parent directory (only needed when we are using /tmp)
if [ "${BASE_ROOT}" != "${HOME}" ] && [ ! -d "${BASE_ROOT}" ]; then
mkdir -p "${BASE_ROOT}"
chmod 700 "${BASE_ROOT}"
fi
# Now create the .cache directory itself
mkdir -p "${CACHE_DIR}"
chmod 700 "${CACHE_DIR}"
## Export the variable so the rest of the session sees it.
export XDG_CACHE_HOME="${CACHE_DIR}"
For the above To make it more bullet‑proof, you could tighten the /tmp detection for the export XDG_CAHCE_HOME="/tmp/${USER}/.cache creation
Systemd can generate a tmpfs mount for /tmp via the tmp.mount unit, but that unit is optional and can be disabled.
In live environments, the initramfs (often via dracut in Kicksecure case) typically mounts tmpfs at /tmp automatically.
Either the package should detect this and not interfere. otherwise a more robust way would be to ship /etc/fstab to be mounted to tmpfs by enabling and masking the builtin systemd unit, completely bypassing the need to fiddle with /etc/fstab. This is via enabling systemd’s tmp.mount unless it interferes with grub-live?
Would this be a good idea to implement or do you think its a waste of time since grub-live “Live Mode” already exists and it could complicate its implementation or conflict with it with complexity?
fedoraproject . org/wiki/Features/tmp-on-tmpfs
Solaris has been doing this since 1994. (Much like other Unixes, too.) Debian’s next release defaults to tmpfs on /tmp, too. ArchLinux defaults to this as well. Ubuntu has plans for their 12.10 release.
From trixie, the default is for the /tmp/ directory to be stored in memory using a tmpfs(5) filesystem. This should make applications using temporary files faster, but if you put large files there, you may run out of memory.
Is there some type of wrapper that could be added so you could launch ./applications in some kind overlayroot in tmp based RAM?
This seems like a good work around between wanting “Live Mode” vs mounting all .cache in TMPFS.
Use case = user wants to start a app in RAM but doesn’t want all their RAM resources being used for “Live Mode”.
Two Examples would be generating a bitcoin wallet with Electrum in RAM so that nothing is saved. The other would be generating GPG keys so one could export their private keys without saving them to the system.
Um…last I checked bwrap has bwrap --tmpfs but requires more arguments or flags to do this correctly. This could be a good starting point if you where to make a bwrap wrapper for this.
The problem I see among others would be creating logic to detect the needed runtime dependencies to have exposed to bwrap. --ro-bind /usr /usr might help with automatic with having to know which libs are required. The other issue I could think of is if the application needs internet access and access to ca-certificates and ssl. Thoughts on using bwrap for a wrapper for launching apps in RAM?