increasing mount size

Jerry McAllister jerrymc at clunix.cl.msu.edu
Thu Oct 27 15:49:17 PDT 2005


> 
> Hello
> My /var mount has no more space left. I was wondering if there is  
> some way to increase the size of it without loosing anything?

This is a frequent question on the list.   There might even be a FAQ on
it.   You might check.   I know I have written numerous responses to
essentially the same question.

The first thing to do is find out what is using up all the space.
In /var, it may well be log files that are outdated and can be
thrown away, or stuff stuck in /var/spool that never goes anywhere,
or something of that nature.

To start checking, go in to that directory and run du(1)
  cd /var
  du -sk *
Then if you see a directory that seems abnormally large, go in
to it and run du again until you get a clearer picture of what
is using the space and if it is something you need to keep or
can just nuke.

Presuming you need to keep enough of the stuff that it won't free
up enough space for you, you have two options.   One is to get 
a larger or additional disk.    Another is to look for a existing
file system that isn't getting much use.

If you have enough extra space somewhere else such as in a /junk
file system you made way back, just for something to do with extra 
space, then you can move the biggest consumers of space there and make 
symlinks.    Lets say /var/spool is gobbling scads of space and
you want to move it in to /junk
Go to /junk and create a directory for it - say var.spool
tar stuff up and move it
check it for peace of mind
make the symlink
clean up

  cd /junk
  mkdir var.spool
  cd /var/spool
  tar cvpf /junk/varspool.tar *
  cd /junk/var.spool
  tar xvpf ../varspool.tar

Look at stuff to make sure it is cool.

  cd /var
  mv spool spool.old
  ln -s /junk/var.spool spool

Check things out some more.   At this stage, it should all be
working from the copy in /junk/var.spool
If you do a cd /var/spool and then a pwd you should see that
you are really in /junk/var.spool

Then clean up.
  cd /var
  rm -rf spool.old
  cd /junk
  rm varspool.tar

Voila - lots of space now in var and room for spool to grow as well.

Note that the way I describe is somewhat due to lack of confidence
in stuff.   It results in three copies of /var/spool for a short
time until you clean up.   You could pipe the one tar in to another
and it would work fine and leave you with just two copies until cleanup.

I also explain it this way, because it is more straightforward to
understand.

If you add a disk, fdisk, disklabel/bsdlabel and newfs it to
get a filesystem, then the process of moving some part of /var
there is exactly the same.  Only the names (of where you are putting
it) change a little.

If you add a disk and make a big file system on it just for /var
then use dump(8) and restore(8) to move the old /var to the
new file system and then just edit /etc/fstab so that the 
new file system gets mounted as /var instead of the old one.

Let's presume your current /var is /dev/da0s1e.
Let's also say you created a /dev/da1s1f (amongst possibly others) 
with lots of room and you want to put /var there.   

  cd /
  mkdir tmpvar                  (Could probably use /mnt but I usually 
  mount /dev/da1s1f /tmpvar      already have that one tied up elsewhere)
  cd /tmpvar
  dump 0af - /var | restore rf -

Then edit /etc/fstab so that the previous line:

  /dev/da0s1e      /var     ufs     rw       2       2

Now looks like:

  /dev/da1s1f      /var     ufs     rw       2       2

Then you remount /var

  umount /var
  mount /var

I think you can just do    mount -u /var

Now it will be using the new one and you have some left over space
on the old disk (/dev/da0s1e) to decide what to do with.  You can
use it as scratch space.

  cd /
  mkdir scratch
  mount /dev/da0s1e /scratch

Make an /etc/fstab entry that looks like:  
  
  /dev/da0s1e      /scratch     ufs     rw       2       2

And it will mount on boot.

If your current /var is not its own separately mounted filesystem - but
really just a part of /root, which is most often the case, then you will 
not be able to use dump/restore to move stuff.   You will need to use tar.   
But the rest is the same in that you create the new filesystem on the new 
disk.  Then put stuff there like we did with tar above when moving just
the /var/spool directory except you move the whole /var instead of just
/var/spool.   

Then make the entry in /etc/fstab.   

But, before mounting it, rename the old /var and make a new mount
point - somewhat like we did above when moving just /var/spool.

  cd /
  mv /var /var.old
  mkdir var
  mount /dev/da1s1f /var

Now you can clean up the old space

  cd /
  rm -rf var.old

That will automatically return all that space to the /root filesystem.

////jerry

> Thanks
> Eoghan


More information about the freebsd-questions mailing list