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.

On my server the filesystem includes these partitions:

Filesystem            Size  Used Avail Use% Mounted on
/dev/sda6             4.6G  929M  3.5G  21% /
/dev/sda5              76M   20M   53M  27% /boot
/dev/sda8             449G  199M  426G   1% /home
/dev/sda7             4.6G  4.4G     0 100% /var

(Output from df -ah)

I'm storing the web sites and databases under /var and as you can see it's got full. The /home folder just has basic user directories and nothing else so I'd like to repartition the server so that /dev/sda8 is about 5GB, with the rest going to dev/sda7.

What's the easiest way to do this via command line (i.e. SSH)?

share|improve this question
is there another drive you can backup data to? or are you trying to resize-in-place? –  quack quixote May 15 '10 at 20:59
Don't you wish you said "Yes" to LVM now? –  Ignacio Vazquez-Abrams May 15 '10 at 21:08

1 Answer 1

up vote 1 down vote accepted

The easiest way would be to switch so that /home is on /dev/sda7 and /var is on /dev/sda8

First, you need to verify that your backup is working correctly. You never want to do anything like this without a good backup.

Shut down as many processes as you can, and check that both /home and /var are idle.

fuser /var

cd /home
tar czf /home.bak.gz .
tar tvfz /home.bak # make sure that the backup is good
pwd # make sure that you are in /home
rm -f *
cd /var
tar cf - . |(cd /home;tar xf -)
# check that /home now contains all your /var data
pwd # check that you're in /var
rm -r *
tar xvzf /home.bak.gz
# check that all the /home data is restored
gedit /etc/fstab #or your favourite editor and switch /home with /var


This will avoid having to repartition the disk.

share|improve this answer
This is generally a good idea, but I should comment on some things. First, using tar is probably a waste of time. Just copy everything from /var to /home, then delete everything from /var, copy contents of /home to /var, delete old contents from /home, and finally edit /etc/fstab. Secondly, "your favourite editor" is definitely not gedit, since it doesn't work on command line. Some alternatives are pico, vim, emacs, mcedit or whatever. –  petersohn May 15 '10 at 21:22
gotta disagree with @petersohn; tar is a good tool for this job. run it with sudo to make sure your copies get the correct permissions and ownership. but it's a really good idea to do this while booted into some system that isn't using these partitions at all. –  quack quixote May 15 '10 at 21:32
@quack quixote: Can you explain to me why tar is useful in that situation? I feel that it just adds an unnecessary step to the process. –  petersohn May 15 '10 at 21:54
I prefer tar for bulk copying like this because it preserves permissions & attributes by default, while cp has to have the correct flags, and since we use cp for other tasks, we don't have it hardwired into our fingers. As for gedit, it will work over a ssh connection as long it's forwarding the X protocol, and I'm using it in the example because most ubuntu examples use it. I wouldn't use it myself, but then I wouldn't have the problem to begin with either. –  gorilla May 16 '10 at 1:04
Oh right. As for another comment, I find "(cd /home;tar xf -)" a bit strange. Wouldn't "tar -C /home xf -" do the same, but without opening a new subshell? –  petersohn May 16 '10 at 6:45

Your Answer


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.