3

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.

4 Answers 4

4

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.

1
  • +1 for bind... I tried the move mount on a test directory but it didn't work for me.
    – David Z
    Jun 28, 2010 at 5:04
2

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.

1
1

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

0

Mount the partition as /data, add directories /data/home and /data/srv.

Now you can either simply symlink /home -> /data/home and /srv -> /data/srv:

sudo ls -s /data/home /home
sudo ls -s /data/srv  /srv

Or use mount --bind. In /etc/fstab/ that would be:

sudo /data/home /home none bind 0 0
sudo /data/srv  /srv  none bind 0 0

I think that's all you need. Someone please correct if different options are needed for the fstab entries.

I have used the symlinks approach for years and it seems to work fine. Perhaps there is a performance hit for following the link, but I haven't noticed it. The bind method is probably better though, and I plan to use that going forward (assuming I haven't overlooked an issue/downside).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .