# Moving /var in an existing installation

## NuMPTy

Hi everyone,

My SSD is running out of space and actually preventing me from compiling some products (libreoffice needs 6 GB free in /var/tmp/portage, and I've only got about 3).

I've got a few spare HDDs that I can use, however I'm not sure on the proper process of 'moving' an important directory. Right now it's just part of / on sda2

Can anyone supply the steps required for doing this properly?

What I know so far:

1) Setup fstab for /var

2) Already have initramfs active

3) Disk is partitioned and mounted (aka ready to go -). 

What's next?  :Smile: 

Thanks!

----------

## khayyam

NuMPTy ...

boot from a livecd, mount / (on /mnt/gentoo) and new-var (on /mnt/new-var)

```
rsync -av /mnt/gentoo/var/ /mnt/new-var
```

... edit /etc/fstab to reflect the new location of /var ... remove or backup the old /var/* ... reboot.

best ... khay

ps. note: the slashes on directory names are not accidental ... so no trailing slash on /mnt/new-var

----------

## robdd

Hi Numpty,

khayyam's suggestion will work, but there may be an easier way you could try. Being an old Unix hacker I normally set my Linux systems up with a "small" / partition (say 2Gb), a larger /usr partition (say 20Gb), and another partition using the remaining space for my data, girlie pics, videos, etc. (This arrangement is from the old Unix days when these partitions were often on different disks, and having a separate / partition meant that you could boot single-user and fix file system problems so long as the / partition was OK. Oh, and my idea of a "small" partition has changed radically as disks get bigger, and bigger, and bigger..)

Now Gentoo uses a lot of space in /var for portage files, and unless I do something my arrangement runs out of space in /. So I move *just* the /var/db directory onto the /usr partition using a symbolic link. *You* can do this by shutting down to single user mode, tar'ring up the var/db directory tree, and moving it to a partition on your external hard drive. This way your system will run OK without needing the hard drive plugged in UNLESS you start doing stuff with portage that needs to access the /var/db directory tree. In that case just mount the external drive and "portage" away.

To go into detail:

1) Exit out of X if you're running in graphical mode, make sure you're logged in as root for the rest of this, then shut the system down to single-user mode by typing "shutdown -s now". That will stop nearly all the services that are running, and allow you to dick around with the disk partitions without upsetting any other software. Do a "ps -ef" before and after shutting down to single user to see the difference in what's running.

2) Work out where you're going to mount your external drive, and then do it.. "cd /", "mkdir extra", "mount - t auto /dev/sdb1 /extra". This assumes that you want to mount your sdb1 partition on /extra - change as required.

3) Now copy across the current contents of the /var/db directory to a directory on your external drive using tar.. "cd /var", "tar cf - db | (cd /extra && tar xvfpB -)". This will list the files as they are being copied.

4) Point the /var/db directory to the new location on the external drive. If you're gung ho you can remove the existing /var/db directory contents now. If you're a chicken you can rename the directory until you're happy that it works   :Smile:   Gung ho: "cd /var", "rm -rf db". Chicken: "cd /var", "mv db db_SAV". Now link the new directory location: "cd /var", "ln -s /extra/db db". The soft-link means that you'll just get an error if someone tries to access the linked directory.

5) Test that the moved files are still accessible: "cd /var", "ls -lR db". If you see lots of files listed you did it correctly. You can get back into multi-user mode by hitting Ctrl-D. You should then try to emerge something to make sure it all works. When you're happy it all works don't forget to remove the saved db_SAV directory tree to get back the space you want.

You really should make a backup before trying this. I've typed the commands from memory, so if something doesn't work just post where you're up to and I'll help out. Also, if you want to see where the space is being used in any directory tree you can use the du command - e.g. "cd /var; du -ks *" will list the space usage in kB of each directory under /var.

Good luck, and Happy Gentoo'ing,

Regards, Rob.

----------

## DaggyStyle

how about using tmpfs for compilations?

----------

## robdd

Hi Again Numpty,

Doh ! Should have thought more before I posted (picking up bad habits from reading slashdot !). You'll also need to move the /var/tmp directory onto your external drive (as well as /var/db) to make enough room. As far as I know portage is the only thing to use /var/tmp (anyone out there know what else uses /var/tmp rather than /tmp ??), so again your system should be fine without the external drive plugged in as long as you're not emerge'ing.

Regards, Rob.

----------

## DirtyHairy

Or, even easier, if the portage tempdir is the only thing you're after, you can set PORTAGE_TEMPDIR in make.conf .

----------

