2

i want to have 2 partitions. one is called system. the other is private.

in the private partition i've got some folders i want to mount into system as system folders.

folders in private: - www - home

mount points in system: - /var/www - /home

is this possible? cause it seems that you can only specify a whole partition to use for a mount point and not a folder in a partition or am i wrong?

i run ubuntu server.

cheers

4

On Linux, you can do this with bind mounts.

These commands:

mount --bind /private/www /var/www
mount --bind /private/home /home

Will do what you want. The fstab version of them is:

/private/www   /var/www  none  bind
/private/home  /home     none  bind
4
  • ...the unspoken assumption being that you've previously mounted the private partition to /private ...right? – quack quixote Apr 7 '10 at 18:21
  • so i dont have to do this during installation? but what happens to the files in /var/www if i mount /private/www there instead? so goes with /home. cause maybe someone already created some users in /home. – ajsie Apr 7 '10 at 18:22
  • The files are still there, just hidden by the filesystem that is mounted on top. If you need access to them, consider adding links in, for example, /home to the directories in /private/home – KeithB Apr 7 '10 at 20:15
  • Yes same caveats of normal mounting still apply, the src has to exist (you can't mount /dev/md0 to / if you don't have /dev/md0), contents of the dst directory will be hidden. Did I answer you question? – kbyrd Apr 7 '10 at 20:54
1

You need to mount the whole volume somewhere so that you can get access to the contents. Once you have done that you can do a bind mount to mount part of it somewhere else as well. See the mount(8) man page for details:

Bind mount operation

Remount part of the file hierarchy somewhere else. The call is:

    mount --bind olddir newdir

or by using this fstab entry:

    /olddir /newdir none bind

After this call the same contents are accessible in two places.

It is important to understand that "bind" does not create any second-class or special node in the kernel VFS. The "bind" is just another operation to attach a filesystem. There is nowhere stored information that the filesystem has been attached by a "bind" operation. The olddir and newdir are independent and the olddir may be unmounted.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.