Ais..2025 11 20..0312..cmp.cnf..use.dirs.elsewhere

· eog's blog


👤 User #

linux (live systems): i often wanna hve a dir from hd be available eg ~/.config/ /etc/ /tmp/npm-cache/ ... do i symlink, hardlink, mount bind, mount-copy, mount-move, overlayfs, ...


👆 ChatGPT #

Here’s a practical breakdown of the right tool for making directories from your hard drive appear in a live-boot Linux system. Each method has different behavior, safety, and performance characteristics.

✅ Short Answer (What you actually want)

For persistent directories from your HD to appear in a live system:

Best general solution: → Use mount --bind for entire directories → Use overlayfs if you want writeable changes without touching the original → Use symlinks only when the underlying FS is already mounted early enough

Everything else is almost always the wrong tool.

🔍 Detailed Comparison

  1. Symlink (ln -s)

✔ Easy ✔ Good when target directory is always mounted before use ✘ Breaks if the underlying filesystem isn’t mounted yet (common in live systems) ✘ Doesn’t isolate writes — everything goes directly to the HD ✘ Symlinks don’t work for system directories needed at boot (e.g., /etc)

Use symlinks when:

The directory’s mount timing is safe

You want a simple redirection

The path should be readable by all tools (symlinks are universal)

  1. Hardlink (ln)

✘ Never useful for directories (dangerous, not allowed except by root and even then discouraged) ✘ Must be same filesystem ✘ No cross-mount support → Ignore for this purpose.

  1. Bind mount (mount --bind)

✔ The safest and simplest for full directories ✔ Real filesystem semantics ✔ Works for system directories (/etc, /var, …) ✔ Can be made read-only (mount -o bind,ro) ✔ Works early in boot (systemd mount units or initramfs hooks)

This is usually the correct method for live systems.

Example:

bash Copy code mount --bind /media/HD/persist/etc /etc mount --bind /media/HD/persist/.config ~/.config

  1. mount --move

Moves a mount point to another location. Useful only when reorganizing mount points during boot or inside initramfs. Not useful for “persistent directory injection.”

  1. mount-copy (copy-on-write overlays)

This usually refers to overlayfs (see below). Traditional CP (copying the directory) gives you a static snapshot, not dynamic or persistent.

  1. OverlayFS

✔ Allows the lower directory (live system) and upper directory (HD) to merge ✔ Lets you keep HD persistent data while also allowing live modifications ✔ Perfect for things like:

~/.config

cache dirs

/etc tweaks you want writeable ✔ Protects the “real” live layer

✘ Slightly complex to set up ✘ Only works on directories (not files)

Example:

bash Copy code mkdir -p /overlay/upper /overlay/work mount -t overlay overlay -o lowerdir=/etc,upperdir=/persist/etc,workdir=/overlay/work /etc

📌 Which method for which directory? Directory Recommended Why ~/.config bind mount or overlay configs need persistence but sometimes need "partial" merging → overlay is ideal /etc overlay safer than bind (avoids wiping live system defaults) /tmp/npm-cache bind mount (tmpfs → HD) caches don't need overlay complexity, bind is fine Any system directory bind or overlay, avoid symlinks symlink timing issues Anything needed before user login avoid symlinks, use mount units systemd honors /etc/fstab or /etc/systemd/system/*.mount 🧭 Practical Recommendations for Live Systems If you want persistent writable directories that override the live system:

→ OverlayFS Especially for config directories.

If you want a simple “use this directory from my hard drive”:

→ Bind mount

If the directory is optional or late-loaded (user apps only):

→ Symlink is acceptable (e.g., ~/Music, ~/Projects, etc.)

If you need speed, isolation, and safety:

→ overlay + tmpfs is best (e.g., /etc overlays over tmpfs to keep upper clean)

💬 If you tell me your exact directories and persistence goals, I can give you a complete fstab or systemd-mount setup tailored to your live OS.

last updated: