-1

Lets say i want this directory structure on a SD card:

SD
├── log -> var/log
├── dbs -> var/db
└── desktop -> home/desktop

(its just an example)

This is so everytime a file goes into /var/log instead it goes to SD/var/log, how could i do that? i'm thinking about symbolic links but im not really sure and i didn't want to break my system.

I am right now using Ubuntu 22.04.3 LTS but if theres a solution for it and other Unix-like / linux systems please let me know. Im using it for everyday personal use (e.g. work, school, media, to learn programming, etc)

if you need any more info please ask in the comments and ill add that into the question

  • 1
    You've not provided any OS/release details (I'd for sure consider that, and what apps you run on the system; ie. what you use the system for) in your question. You can put directories on any drive you want (you control it via the file-system table; ie. /etc/fstab), even shadow* mount (useful when you want it done at only certain times, useful in testing etc), but there are risks of course to shadow mounting so consider the details you didn't mention first. – guiverc Sep 26 '23 at 02:56
  • 1
    What I provided will apply to all GNU/Linux systems, but you'll need to adjust for your OS (be it Ubuntu 22.04 LTS Server, Ubuntu 22.04 LTS Desktop or other system), what apps you'll use (ie. how you use your system influences the apps, their defaults/storage requirements, including how they're packaged) etc. How safe will vary on the actual directory involved (I used to love it for my home folder for desktop; I now avoid it! instead mounting specific directories within $HOME and for some it's on a per app basis inc. how packaged). Systems directories differ too; but fstab is GNU/Linux – guiverc Sep 26 '23 at 05:57

1 Answers1

1

This is so everytime a file goes into /var/log instead it goes to SD/var/log, how could i do that? I'm thinking about symbolic links but I'm not really sure and i didn't want to break my system.

If you mean on the system's level, then that's a very bad idea and it will break your system ... Some essential applications like e.g. APT will consider some symbolic links at e.g. /var/log as insecure/dangerous and will refuse to follow them thus resulting in errors or even not working at all.

Bind mounts on the other hand should work in most cases but again that might be acceptable on the user-space level but requires special care on the system level with e.g. /var/log and even though might still cause problems due to availability/connectivity/filesystem of your SD card so not advised and will affect all users and services system-wide as well which might yield unexpected results.

... So, bottom line, the above is not recommended and will in most cases break your system.

However, in your own userspace, you can modify/bind VFS mounts as you like with no effects on the other users/services by creating a filesystem namespace in a user-space (without sudo or root privileges) like e.g.:

bwrap --die-with-parent --bind / / --dev-bind /dev /dev --bind /SD/var/log /var/log \
--bind /SD/desktop /home/desktop --bind /SD/dbs /var/db -- /bin/bash

For more info, please see I want /ts to reference ~/.local/ts without root/admin privileges?

Raffa
  • 32,237