2

Is it safe to move complete /var directory in separate partition and create symlink to it?

mv /var /mnt/storage
ln -s /mnt/storage /var

Distribution is Google Cloud CentOS Image

I do not want to use bind mount due the following reasons:

https://unix.stackexchange.com/questions/49623/are-there-any-drawbacks-from-using-mount-bind-as-a-substitute-for-symbolic-lin

2
  • 3
    Why bother with the symlink? You could just mount /var there directly. Sep 27, 2014 at 0:41
  • To expand on Michael's comment - you specified you don't want to use a bind mount, but why not use a conventional mount? Sep 27, 2014 at 18:17

2 Answers 2

2

I don't know any reason that this shouldn't work. Symlinks are a standard feature of Linux filesystems, that are recognized and used correctly by every utility I know of.

I've never symlinked all of /var, but I've done large parts of it. It worked fine. Just make sure the permissions are set correctly on /mnt/storage.

1

Just tried it on ubuntu 20.04 and it worked fine. I did the copying and the symlink from rescue mode root shell.

And to clarify why it might be helpful - when you don't have unpartitioned disk space, and you need to move /var to a simple folder on another disk without re-partitioning anything. Yes, you can use a bind mount, but it can be rather inconvenient to figure out later what is mounted where, so I prefer ln -s

UPDATE: Ok, I've found at least one problem - snap stopped working correctly, seems like AppArmor issue. I gave up for now as I've found an unused partition right after ex-var, so I've put it back and enlarged it with resizefs.

1
  • 1
    The AppArmor problem is because AppArmor definitions are based on the absolute path, not the logical (symlink-including) path. Pre-baked AppArmor profiles assuming /var/{something} is a physical path will break when /var is symlinked somewhere novel.
    – sysadmin1138
    Mar 26, 2021 at 16:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .