I'm not very deep into this mounting/unmouting thing on Linux, so here goes my question:

With df -h I get the following overview:

Filesystem            Size  Used Avail Use% Mounted on
/dev/sda1             323M  306M     0 100% /
tmpfs                 502M     0  502M   0% /lib/init/rw
udev                  497M  116K  497M   1% /dev
tmpfs                 502M     0  502M   0% /dev/shm
/dev/sda9              47G  181M   44G   1% /home
/dev/sda8             368M   12M  338M   4% /tmp
/dev/sda5             8,3G  1,1G  6,8G  14% /usr
/dev/sda6             2,8G  433M  2,2G  17% /var

I'm using this machine as web server where all web related stuff resides under /srv/. As this is part of / I'm out of disk space here. I saw /home having 44G available web space, which is pure nonsense in my case. So I want to have /home not as own partition (rather part of /), but /srv as own partition, grabbing the space consumed by /home. So after that df -h should look like this (/home replaced by /srv):

Filesystem            Size  Used Avail Use% Mounted on
/dev/sda1             323M  306M     0 100% /
tmpfs                 502M     0  502M   0% /lib/init/rw
udev                  497M  116K  497M   1% /dev
tmpfs                 502M     0  502M   0% /dev/shm
/dev/sda9              47G  181M   44G   1% /srv
/dev/sda8             368M   12M  338M   4% /tmp
/dev/sda5             8,3G  1,1G  6,8G  14% /usr
/dev/sda6             2,8G  433M  2,2G  17% /var

What have to do to get here?


Since you have plenty of room in /home, move all the stuff from /srv into /home, then (optionally) move the stuff that was in /home to the root partition.

The simplest solution, if you don't mind a few minutes' downtime, is to move /srv into the larger partition and symlink it:

mv /srv /home
ln -s /home/srv /

If you really want to move /home to the root partition, then it takes a few renames. I assume there's no directory called /home/srv or /srv/srv.

mv /srv home
mkdir /srv
mount --move /home /srv
mv /srv/acme … /home/
mv /srv/srv/* /srv
rmdir /srv/srv

Finally (if you're not using the symbolic link method) edit /etc/fstab to change the mount point: on the line that begins with /dev/sda9 /home, replace /home by /srv.

  • Thanks - sounds like the best solution to me as I don't have to fiddle around with creating/modifying partitions. Downtime is not a problem as this machine is not yet online. – acme Mar 14 '11 at 7:51

Before you do anything you're going to have to figure out a place to keep the 180 megabytes of data that /home is currently taking up. I'd recommend repartitioning the current /dev/sda9 into, say, two gigs for /home and 42 for /srv.

Next up you're going to have to be a little tricky. This is all best accomplished in single user mode so that only root is logged on and you don't run into trouble with someone trying to access /home while you're moving it around.

You've got a decent amount of room in /var, so we'll use that as a temporary holding space: mkdir /var/tmp/oldhome

cd /home

`tar -cvf - ./ | ( cd /var/tmp/oldhome && tar -xvf - )

Now we've got /home backed up to someplace while we repartition /dev/sda9 into 2 gigs for /dev/sda9 and 42 gigs for /dev/sda10

Once you've finished repartitioning and creating new filesystems (I'm going to assume you know how to do this) you'll need to edit /etc/fstab.

Somewhere in there you'll see a line saying something along the lines of

/dev/sda9 /home ext3 defaults 0 2

Assuming that you've made /dev/sda9 the smaller of the two partitions, you can leave that line unchanged; you'll just need to add

/dev/sda10 /srv ext3 defaults 0 2

directly underneath.

Once those lines have been added, simply enter

mount /home ; mount /srv

and check with df -h to make sure both partitions are mounted.

Then replace the data from /home:

cd /var/tmp/oldhome

tar -cvf - ./ | ( cd /home && tar -xvf - )

Reboot your system in multi-user mode and everything should work.

  • Thank you for your detailed answer. Say I'd have enough space on / for /home can't I just switch the mount point from /dev/sda9 /home ext3 defaults 0 2 to /dev/sda9 /srv ext3 defaults 0 2 without creating new partions and moving stuff around? Another strange thing: /home has only one root-folder which is empty. I don't know why it uses 181M as seen in the output. – acme Mar 10 '11 at 14:43
  • From the outputs, / is completely full despite the discrepancy in total and used space - and I'm seeing a similar discrepancy in /home. I'd recommend you look //very// carefully at what /home actually contains ( find /home/ -ls would be a good start. ) – Shadur Mar 10 '11 at 14:51
  • As far as I understood /home contains /srv (which I could transfer to somewhere else and move it again to /srv when it has its own partition). And /home really contains only an empty dir root and an empty dir lost+found. So couldn't I just change /home to /srv in fstab (after freeing some space in /)? – acme Mar 10 '11 at 14:58
  • This is complicated and inefficient! Why move the data around several times? Why bother with tar (cp -a is actually better at preserving metadata and copying “strange” files)? – Gilles 'SO- stop being evil' Mar 10 '11 at 20:12
  • I suppose you could just store it in a tarball rather than unpack each time, but you are going to have to move it to a safe location before repartitioning the partition it's currently on. – Shadur Mar 10 '11 at 21:43

As a quick but not very beautiful solution, you could remount a directory on one of your less-used disk to some point under /srv and move something there to clear a bit of space on /srv proper.

Read about --bind in man mount. It boils down to something like mount --bind /some/spare/dir /busy/dir/mountpoint. It works on any modern Linux.

Suppose that you have /srv/some/stuff.

  • mkdir /home/offload/some/stuff — this is on the 44G free space partition
  • mv /srv/some/stuff /srv/some/previous-stuff — temporarily, free up the name
  • mount --bind /home/offload/some/stuff /srv/some/stuff — now some/stuff is on another partition!
  • mv /srv/some/previous-stuff/* /srv/some/stuff — put things back under the original name, free up the space on /srv.

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.