I have some unused space on my disk, and decided to use a little of it to create a separate /var partition. There might be an easier way to do this, but my idea is to

  1. copy the existing /var directory to the partition;
  2. mount the partition over the existing /var directory;
  3. using another system, either another distro on the disk or a live CD, to delete the original /var contents while the partition is not mounted.

I've done the first 2 steps, and it seems OK so far. I've made an entry in fstab to mount on boot, which I'll test before deleting. But I'm wondering if this is a valid strategy, and also if it's a good idea and/or if there is a better way. It's somewhat of a learning experience for me to play around more with mounting beyond the basics.

Edit (results):

Thanks to the suggestions below, I completed step 3 without the need to use a 2nd system. The method I used was to remount the root fs using the command mount --bind / /mnt/temp, then going to /mnt/temp/var and deleting the files and directories there.

The one suggestion made after I did it was to create a dummy file, and then check the mounted /var directory to confirm that it was not seen in that directory. But I compared timestamps to see that they were different, so I felt confident that I was OK.

Thanks for the suggestions, everyone.


If you're on Linux you can :

  • Mount your root filesystem on a random mountpoint. I usually use /mnt for this sort of things.

    mount --bind / /mnt
  • Then you can (re)move the files from /mnt/var

Not all OS's allow a filesystem mounted on a second mount point at the same time, that's why I wrote 'on Linux'. Just try the mount, it won't break anything.

  • Interesting idea - So, I'll see the "real" /var directory doing that, instead of the mounted one. If that's true, then this method is much more straightforward than any other ideas I saw in my research for accessing the original files when mounting on a non-empty directory. I'll check it out and come back later. – Marty Fried May 2 '12 at 18:31
  • Well, that worked out perfectly - amazing that it was that easy. I used the command sudo mount --bind / /mnt/temp to mount the filesystem, and deleted the files with no problem, after confirming that the timestamps were different than /var, to make sure it was indeed different. Thanks for the tip. – Marty Fried May 2 '12 at 18:53

I'm going to assume (very dangerous, I know) that you are running out of space on your primary partition and have added a new disk.

/dev/sda1 /boot /dev/sda2 / /dev/sdb1 /var

Assuming you've copied over the /var folder on sda2 to the partition on sdb1 you can mount sda2 a second time:

mount /dev/sda2 /root/tmp
cd /root/tmp/var
rm -rf *

You are now in the old '/var' directory, you can check by creating a file, it will not be under /var but it will be there under /root/tmp/var

Now you can safely delete the files onder /root/tmp/var and umount tmp.

DISCLAIMER: No warranty, use at your own risk, do not trust me (or anyone else on the internet) take backups!

  • Well, your answer was good, but the assumption wasn't. :) I wasn't running out of space, but I wanted to avoid that possibility in the future. I had plenty of unused space on my drive, along with several used and unused partitions to play with, so I decided to do this more as something that seemed like a good idea. I used the tip from @jippie before I saw your post, but both seem to be similar. Yours was more detailed, but I didn't really need details too much, just the idea was enough. Thanks for the post – Marty Fried May 2 '12 at 19:02

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.