Comments on Adding mount points to an existing partition that already has one
Parent
Adding mount points to an existing partition that already has one
I have /
mounted on a relatively small partition and /home
on a larger one taking up most of the rest of the drive (as seems to be common practice). I'd like to move certain other parts of the filesystem onto the main partition - notably:
-
/var
(especially/var/log
), since it tends to grow in size progressively as I use the system and I don't want to do regular cleanup -
/tmp
(I'm aware I can use tmpfs for this, but...) -
/usr/local
(for me this basically only has things I compiled myself, so I'm not worried about e.g. losing track of those things when reinstalling Linux)
I've heard that there's something called a "bind mount" that can be used to allow multiple mount points to share the same partition. But can this still work if the partition already has something mounted on it normally?
What's a minimally disruptive way to relocate these folders? (Are there any special consideration specific to what's being moved?)
Post
Yes, bind mounts or possibly rbind mounts is most likely what you want here.
You need a rbind mount if you want the contents of file systems mounted below the specified mount point to be accessible in the new location as well; you need a bind mount if you don't want or need that. Given the situation you describe in your question (/
and /home
separate, everything else in /
), a bind mount should be exactly what you want.
As with any operation that makes large-scale changes, making sure to refresh your backups first is a good idea.
The easiest way to set this up is if you can tolerate shutting the system down. In that case:
-
boot with live media (such that there is nothing running from the file systems you're working with)
-
mount both file systems in separate locations (let's say that you mount your current
/
at /mount/root and/home
at /mount/home); depending on partitioning, this can also include setting up MD RAID arrays, opening LUKS containers, or other steps to make the actual file systems accessible -
move (not copy) everything from (in this case) /mount/root/var/log to, say, /mount/home/var/log, making sure to preserve the permissions from both the original /var as well as /var/log; but leave the original directory (/mount/root/var/log = /var/log) in place
-
update /mount/root/etc/fstab (that is to say, your main system's /etc/fstab) to include an entry on the form:
/home/var/log /var/log none bind 0 0
-
repeat for each file system you want to move
-
reboot when done
Take it nice and slow; this isn't terribly complex, but you can easily cause mayhem if you aren't careful in matching up old and new locations, including permissions and ownership.
The fstab entry is on the usual "what where type options" form, with the options being bind
and the file system type being irrelevant for a bind mount. See mount(8) under the "bind mount operation" heading.
Doing the equivalent on a running system is in principle possible in much the same way, but requires significantly greater care regarding files that are in use, particularly ones being written to. I don't recommend going that route.
I don't see any particular reason why you'd need to do something special depending on exactly which directory you're moving.
0 comment threads