LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Practical questions for having /tmp and /var on same partition (https://www.linuxquestions.org/questions/linux-general-1/practical-questions-for-having-tmp-and-var-on-same-partition-4175688514/)

Grobe 01-13-2021 05:33 PM

Practical questions for having /tmp and /var on same partition
 
Hi.

I just installed MX Linux onto a computer, and tough the installer does provide an option to have separate / /root /home and swap partitions, it does not natively offer the user to specify partitions to put /var and /temp.

Therefore, I have set aside 25BG free space for this purpose. I also want to put /var and /tmp on same one partition.

On this page - unix.stackexchange.com/../why-put-things-other-than-home-to-a-separate-partition it says:
Quote:

var and /tmp can be filled up by user programs or daemons. Therefore it can be safe to have these in separate partitions that would prevent /, the root partition, to be 100% full, and would hit your system badly. To avoid having two distinct partitions for these, it is not uncommon to see /tmp being a symlink to /var/tmp.
The first practical question - what steps are necessary to do this? According to last post in this askubuntu forum thread:
Quote:

if you provide an existing directory instead of the link name, ln will create a link inside that directory
I've made symlinks before, but this confuses me.


Thanks in advance

jailbait 01-13-2021 06:42 PM

You will probably have to do these steps from a rescue DVD. If you try them on a live system the system will probably crash part way through the rearrangement.

Format the new partition.

Move the contents of /var to the new partition leaving /var as an empty directory on /.

change /etc/fstab to mount the new partition on /var

delete /tmp on / and recreate /tmp on / as a symbolic link to /var/tmp

The only possible problem I see with what you are attempting is if the boot process uses /tmp before /var is mounted through /etc/fstab. I don't think that is what actually happens so I think it should work.

--------------------------
Steve Stites

Grobe 01-13-2021 06:56 PM

Thanks a lot #jailbait, that make sense. See if I got time to test this tomorrow.

If it get problems with this, it's a newly OS installed so not much time wasted anyway.

frankbell 01-13-2021 08:15 PM

The practice of putting /var and /tmp on separate partitions dates back through the mists of time when hard drives were still relatively new and extremely small. With today's hard drives, it should not be necessary.

I common allocate 25-30GB for my root partition, which contains everything except /home, and have never experienced any issues related the /var and /tmp. (Before I started doing that, I would have just one root partition containing everything, and also never encountered any issues.)

MadeInGermany 01-14-2021 03:16 AM

Quote:

The only possible problem I see with what you are attempting is if the boot process uses /tmp before /var is mounted through /etc/fstab. I don't think that is what actually happens so I think it should work.
Good point!
systemd places files in /tmp
If these are overmounted, it might misbehave.

EDIT
I think it uses the /tmp later, not before mounting, so it is likely not a real problem.

DavidMcCann 01-14-2021 10:55 AM

Quote:

Originally Posted by MadeInGermany (Post 6207570)
I think it uses the /tmp later, not before mounting, so it is likely not a real problem.

The new idea is to use /run.

Putting /tmp and /var on their own partition(s) is only useful for servers. There a lot of users may create a lot of data on /tmp, while databases typically make use of /var to keep track of things.

ondoho 01-15-2021 01:42 AM

FWIW, /tmp is a tmpfs (aka RAM disk) on my system.
Major distros seem to disagree about what exactly /tmp should be, but I think that's the right way.
There's more:
Code:

$> grep -w tmpfs /etc/mtab
run /run tmpfs rw,nosuid,nodev,relatime,mode=755 0 0
tmpfs /dev/shm tmpfs rw,nosuid,nodev 0 0
tmpfs /sys/fs/cgroup tmpfs ro,nosuid,nodev,noexec,size=4096k,nr_inodes=1024,mode=755 0 0
tmpfs /tmp tmpfs rw,nosuid,nodev,size=3538532k,nr_inodes=409600 0 0
tmpfs /run/user/1000 tmpfs rw,nosuid,nodev,relatime,size=707704k,nr_inodes=176926,mode=700,uid=1000,gid=1000 0 0


Michael Uplawski 01-16-2021 12:22 AM

Quote:

Originally Posted by ondoho (Post 6207888)
FWIW, /tmp is a tmpfs (aka RAM disk) on my system.

tmpfs, AKA “a symlink to /dev/shm” or just any kind of ramdisk for temporary data should be a natural choice. I do not know if my use of the temp-directory qualifies me as a security-freak. But knowing that wiping RAM is quite different from wiping a hard-disk has its charms. – Knowing that not doing anything at all is enough for a RAM-disk, too.

Grobe 03-30-2021 11:33 AM

2 Attachment(s)
Ok - I've made an attempt, this is as far I got:
  • I moved the contents of the old /var and /tmp to the new location.
  • I've made a symlink to the new locations (/sda/mx_var/ and /sda/mx_tmp/ ) (not sure if I should have used "/dev" before).

However the editing of /etc/fstab file I don't know how to proceed further from this. From what I read, fstab can only deal with volumes and not folders within.

As it sits now, the system are not able to boot (see screenshot of the boot error messages)

attempt 1 : the symlinks does not include "/dev" (probably wrong anyway)
attempt 2 : the symlinks does include "/dev" --> "dev/sda5/mx_var/"
So far, the /etc/fstab file are not changed in any way.

craigevil 03-30-2021 11:46 AM

Why not just put /var in tmpfs?

Code:

*grep -w tmpfs /etc/mtab
tmpfs /dev/shm tmpfs rw,nosuid,nodev 0 0
tmpfs /run tmpfs rw,nosuid,nodev,mode=755 0 0
tmpfs /run/lock tmpfs rw,nosuid,nodev,noexec,relatime,size=5120k 0 0
tmpfs /sys/fs/cgroup tmpfs ro,nosuid,nodev,noexec,mode=755 0 0
tmpfs /var/spool tmpfs rw,noatime 0 0
tmpfs /var/tmp tmpfs rw,noatime 0 0
tmpfs /tmp tmpfs rw,noatime 0 0
tmpfs /var/log tmpfs rw,noatime,mode=755 0 0
tmpfs /run/user/1000 tmpfs rw,nosuid,nodev,relatime,size=388636k,mode=700,uid=1000,gid=1000 0 0

My /etc/fstab
Code:

*cat /etc/fstab
proc            /proc          proc    defaults          0      0
PARTUUID=66b4c1cf-01  /boot          vfat    defaults          0      2
PARTUUID=66b4c1cf-02  /              ext4    defaults,noatime  0      1
# a swapfile is not a swap partition, no line here
#  use  dphys-swapfile swap[on|off]  for that
# Added 4 lines to use RAM instead of SSD for temp and log files
tmpfs /tmp tmpfs defaults,noatime,mode=1777 0 0
tmpfs /var/tmp tmpfs defaults,noatime,mode=1777 0 0
tmpfs /var/log tmpfs defaults,noatime,mode=0755 0 0
tmpfs /var/spool tmpfs defaults,noatime,mode=1777 0 0


hazel 03-30-2021 11:55 AM

I wouldn't do it with symlinks. I'd just have empty /var and /tmp directories on the root partition and put them into fstab as mountpoints. In most modern distros /tmp is empty anyway and a tmpfs (ramdisk) is mounted there.

re your query about unnamed symlinks:
Quote:

if you provide an existing directory instead of the link name, ln will create a link inside that directory
In creating a symbolic link, the target always comes first, then the link name. If no link name is given, the name will be the same as the target file. Obviously this will not work if you simply type
Code:

ln -s target .
because you can't have two files of the same name in the same directory. However:
Code:

ln -s target /other_directory
will work. It will create a link at /other_directory/target.

Your images show a successful boot though some daemons have failed. The acpi errors are not serious. It might be worth logging in and exploring the system to find out what the /var and /tmp directories actually contain.

Grobe 03-30-2021 12:05 PM

Thanks @craigevil

Yep - tempfs is an alternative.

However, If I stuck to the plan and have to use fstab, the issue is that the first column of fstab file cannot point to a folder within any partition/volume.

Emerson 03-30-2021 12:14 PM

The whole /var in tmpfs is not a good idea, many setups use data stored there, must survive reboot. First column can have directories, use bind mount for those.

hazel 03-30-2021 12:15 PM

Quote:

Originally Posted by Grobe (Post 6235583)
However, If I stuck to the plan and have to use fstab, the issue is that the first column of fstab file cannot point to a folder within any partition/volume.

So don't use a folder. Make a partition of a suitable size for your /var contents and use that, mounting it on the empty /var directory. As Emerson pointed out, there are important databases stored here so you want it to be permanent.

And set up /tmp as a tmpfs if it isn't that way already.

Grobe 03-31-2021 01:54 PM

Ok, so I ended up no being able to restore the MX desktop, despite attempting to copy the contents of /var back again (created the /tmp and /var folder and copied back it's content in order to try to fix the MX desktop issue).

But - no problem, it's a test setup for this purpose anyway.

So for now - lessons learned as following:
  • tempfs are probably the way to go regarding /tmp
  • If /var is removed manually, it may be very hard or impossible to make it work again (for a beginner like me at least). Maybe a workaround here would be to just rename the /var folder and when renamed back it's al good - or maybe the system does something when it doesn't find/accept /var that screw up the desktop regardless to wether I restore it back or not.
  • The original goal of making /tmp and /var physically located in same partition seems impossible at this moment.


All times are GMT -5. The time now is 10:30 AM.