Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

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

+1
−0

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?)

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.
Why should this post be closed?

0 comment threads

Post
+0
−0

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.

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

1 comment thread

Quick clarifications (1 comment)
Quick clarifications
Karl Knechtel‭ wrote 5 months ago

Re "making sure to preserve the permissions", is ordinary mv not sufficient? Also, what exactly is the "r" in "rbind"?