Mount /tmp and /home to separate hard drive

24,891

Solution 1

To have /tmp and /home on the same partition as each other but a different partition from /, you'll need to do this:

  1. Make tmp and home the two top-level directories on the partition you want to contain them. So if right now that partition is itself /tmp, you'll need to move its entire contents to a tmp directory in its root.

  2. Give the partition that contains tmp and home its own mount point. A reasonable name for this is tmp+home (unless you plan to use that partition for other stuff too) and reasonable locations for it are /, /mnt, and /media. I recommend putting it directly in / and the rest of this answer assumes that's where it is.

  3. Give /tmp+home its own entry in /etc/fstab. (You will see /tmp has its own entry.)

  4. Make /tmp and /home symbolic links to /tmp+home/tmp and /tmp+home/home.

Please note that this will not involve using these instructions for creating a separate /home partition, because in this configuration, /home will be a symbolic link into a separate partition, rather than a mount point for a separate partition.

Furthermore, you'll have to unconfigure your separate /tmp directory (including removing or, better, commenting out its entry in /etc/fstab), since /tmp will no longer be a mount point for a separate partition, but will instead be a symbolic link into a separate partition.

This answer doesn't provide extremely specific instructions (though it should be sufficient, combined with the available documentation). If someone who has experience moving /tmp can weigh in on whether or not it's possible/safe to move /tmp while in the installed system, that would be helpful. I can give detailed instructions for doing this from the installed system or from a live CD, but I don't want to give directions that are ineffective or unsafe (nor directions that are unnecessarily difficult and time-consuming).

Solution 2

The easy way would be to make another / partition with an install disk then reboot, and mount that partition temporarily in /media or whatever then copy the /home and /tmp folders in the new / root partition you mounted under media. Unmount it and reboot.

Share:
24,891

Related videos on Youtube

arcyqwerty
Author by

arcyqwerty

Updated on September 18, 2022

Comments

  • arcyqwerty
    arcyqwerty over 1 year

    is it possible to mount the root file system '/' on one hard drive (where folders like /usr, /boot, etc will be stored) and mount /tmp and /home to another hard drive on the same partition?

    Something like this:

    HDD1:
    
    /
      /usr
      /bin
      /boot
      /var
    
    
    HDD2:
    
      /tmp
      /home
    

    I know LVM is possible for creating a single large volume but that is not what I want

    • arcyqwerty
      arcyqwerty almost 12 years
      This is on an existing install. But it was just set up so there isnt a whole lot of stuff to move around
    • arcyqwerty
      arcyqwerty almost 12 years
      well. I already have a partition on each drive. I would like to keep /tmp and /home on the same partition if possible (like how mounting HDD1 as / puts all /usr /var and /boot on the same partition) such that the space is shared
    • Eliah Kagan
      Eliah Kagan almost 12 years
      Ah, I see, you want /tmp and /home to be on a separate partition from / but on the same partition as each other. This is slightly less trivial to achieve. I'll post an answer about how to do this (and then someone more experienced moving system directories while they're in use can weigh in as well).
  • Eliah Kagan
    Eliah Kagan almost 12 years
    The OP is asking specifically about how to put /tmp and /home on a different partition from / but the same partition as each other. This can be done.
  • jackweirdy
    jackweirdy almost 12 years
    I noticed that, but that would include mounting / twice in the fstab. This specific requirement has caused me problems before (admittedly in the 2.20s of the kernel) but I wouldn't want to risk it again.
  • Eliah Kagan
    Eliah Kagan almost 12 years
    You don't have to (and indeed you're right, you should never) have two fstab entries for /. You should never try to use one directory as a mount point for more than one partition. Instead, just make /tmp and /home directories in the root of their partition, mount the root of their partition on its own mount point, and make /tmp and /home symbolic links to the respective subdirectories of that mount point. See my answer for details.
  • jackweirdy
    jackweirdy almost 12 years
    I can't think of any risks with moving /tmp besides the idea that if you unmount it and a process wants to access it then it might (extremely worst case scenario) cause a kernel panic. If fstab hadn't been changed then you could restart and try again later. If it had, and the mount point was invalid or non existent yet, the OS could fail to boot, or it could chug on without it. In any case, better safe than sorry. Likely as not though there wouldn't be a panic in the first place, the process would just end or carry on regardless.
  • Eliah Kagan
    Eliah Kagan almost 12 years
    @jackweirdy An app finding it can't access data won't cause a kernel panic, but I'm worried that if important apps or services need /tmp and it's moved under them, the system might not remain functional while the other steps are followed. Furthermore, in general any file or directory in /tmp is considered eligible for deletion anytime when it's not actively in use by some process, so if the contents of /home go into a partition that's still mounted as /tmp... You can definitely use a live CD, but I'm hoping someone whose done it in a running system can comment (or edit my answer).
  • jackweirdy
    jackweirdy almost 12 years
    Just tried following your instructions (only to a new partition though). Went fine :)