2

Somewhat along the lines of this question, How to mount multiple directories on the same partition? but my situation is different.

I have a 2 small partitions that I'm using for two variants of linux and one large partition that I'm using as the home for both. I'd like to move the /usr folder from one of the variants to that same partition.

Any suggestions of how to accomplish this?

Jas
  • 23
  • 5

1 Answers1

4

There is no generic way to directly mount a subtree of a filesystem. But you can mount the whole filesystem somewhere, and then “copy” a subtree of the mount with a bind mount.

mount /dev/foobar /media/foobar
mount --bind /media/foobar/usr /usr

In fstab syntax:

/dev/foobar /media/foobar auto defaults 0 2
/media/foobar/usr /usr bind bind
  • So if I wanted to use that partition for both variants /usr folders there is no way to do that? @Gilles – Jas Jul 21 '16 at 11:59
  • @Jas I don't understand your comment. What do you mean by “use that partition for both variants /usr folders”? – Gilles 'SO- stop being evil' Jul 21 '16 at 17:53
  • I apologize for my lack of clarity, I'll try to do better. My thought went like this, if I have 4 partitions in my hard drive I can have one be /swap another be /home and two be /, the two / would be for two different linux variants. The two / or root partitions can be small, maybe 10GB each for system files only. The swap can be as large as my RAM, and the /home partition can be the rest of the drive. – Jas Aug 25 '16 at 06:33
  • However what happened was that the /usr folder in both of the variants became too large and I was trying to move them to the /home partition, but since they had the same name I was hoping to mount them as /usr from the /home partition, for each of the variants, while having the actual folder name be something like "usr16" and "usr14" to keep track of which usr folder went with which variant, say for example if the variants were Ubuntu 14.04 and Ubuntu 16.04. – Jas Aug 25 '16 at 06:38
  • @Jas Sure, you can do that. The best way to do it would be with a symbolic link: ln -s /home/usr14 /usr on the 14.04 system, ln -s /home/usr16 /usr on the 16.04 system. – Gilles 'SO- stop being evil' Aug 25 '16 at 07:22
  • This is not booting for me. It works for /home, /var ... , but not for /usr. During boot I see the mount of the root. Then the failure of the bind mount: Failed: 'mount -t bind -o bind /newroot/media/foobar/usr /newroot/usr So it tries to do the bind mount before the partition mount. But the partition mount is clearly there in /etc/fstab before the bind. What am I missing here ? – aminator Apr 19 '23 at 09:29