Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

When installing Ubuntu (10.04) I chose the /home to be installed in a separate partition. I would now like to move the /srv directory into the same partition.

The problem I found is that Ubuntu did not make a /home directory inside the partition itself. It just places the account directories in the partition and mounts it to /home. So I cannot just easily move the /srv folder into the partition.

How can I:

  1. Move those account directories into a home folder inside the partition
  2. Make that new home folder the default /home folder.
  3. ditto with the /srv folder, or any I choose in the future.
share|improve this question

3 Answers 3

Once /home has been mounted, you can do a bind mount to mount e.g. /home/srv on /srv.

mount --bind /home/srv /srv

In this case, the same files will appear under /home/srv and /srv.

Or you can do a move mount to move /home/srv to /srv.

mount --move /home/srv /srv

In this case, /home/srv will no longer exist after the mount. Unmounting /srv will make /home/srv appear again.

share|improve this answer
    
+1 for bind... I tried the move mount on a test directory but it didn't work for me. –  David Z Jun 28 '10 at 5:04

If I understand correctly what you're trying to do, it's not exactly possible - mounting doesn't work that way. (Although you can kind of fake it, as explained in e.g. Ignacio's answer)

You can think of each partition as its own filesystem. So for example, let's say you have a partition sda1 that you're going to use for the root of the overall filesystem, and sda2 that you're going to use to hold home directories. As you now know, the filesystem on sda1 contains top-level directories bin, lib, usr, home, etc., and the filesystem on sda2 contains top-level directories user1, user2, etc. (or whatever your users' home directories are called). The hierarchy might look like this:

sda1
|-bin
| |- (programs)
|-home
|-lib
| |- (libraries)
|-usr
| |-bin
| |-lib
| |-share

sda2
|-user1
| |-Documents
|-user2
| |-Documents

And also as you know, in order to mount a filesystem, you have to specify the filesystem (of course) and a directory, the mount point. When you do this, the directory you specify becomes the name for the root of the partition's filesystem. For example, one of the first things the OS does when starting up is mount sda1 (in this example) on the directory /. That makes / the name for the root of the filesystem on sda1. You can now refer to the bin directory on sda1 as /bin, for example. Later on in the boot process, the OS mounts sda2 on /home/, which means that /home/ is the name for the root of the sda2 filesystem. To refer to the user1 directory on sda2, you can write /home/user1. And so on.

Now it sounds like what you had in mind was assigning a name (like /srv/) to some subdirectory within a partition's filesystem, rather than the root of that filesystem. But mount doesn't work that way. I'm not sure whether there's a technical reason for that, or it was just a design decision by the maintainers of the Linux kernel. The bottom line is, in order to have anything on a partition accessible, you have to assign a name to the root of the filesystem. But once you do that, you can make subdirectories within the partition's filesystem accessible under other names using the --bind option to mount, and that's probably your best option.

share|improve this answer
    
It's just *nix legacy. –  Ignacio Vazquez-Abrams Jun 28 '10 at 5:25

in your case, /home is considered the "mountpoint", the name of the mountpoint can be changed by editing /etc/fstab

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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