2

I currently run a webserver running Debian. I have a 1GB disk with a single ext4 partition mapped to / and an 8GB disk with a single ext4 partition mapped to /var/www.

The 1GB disk is at 70% full without a DB installed. Once I put on psql, my /var is probably going to fill up the 1GB disk.

So what I want to do is to resize the ext4 on the 8GB disk to 4GB and create another partition using the free space.

Now, in my mind, I've came up with the following set of steps:

  1. umount and use resize2fs (or parted) to resize the partition on the 8GB disk.
  2. parted to create a new 4 GB partition on the free space.
  3. mount the new parition to say /media/new
  4. cp -a to copy my /var from the 1GB partition to the new 4GB partition. (or should I use tar for this?)
  5. add an entry for the new partition in fstab
  6. delete the redundant stuff like /var from my 1GB disk and /var/www for the new partition.

I've never done something like this before, so could someone please verify my steps and see if I'm missing anything?

PS. I did a du --max-depth=1, and it looks like aside from the 200MB taken up by /var, there is also a 300MB allocated to /usr and 200MB to /lib. Should I move these too?

1 Answer 1

4

You don't actually have to repartition your disk to accomplish this. An alternate solution is to use mount -o bind.

  1. Stop all services running on the server, and confirm that there are no open handles to /var with lsof | grep /var - if there are, kill the processes holding them.
  2. Unmount your 8GB drive (/var/www) and mount it somewhere else (e.g. /mnt)
  3. On your 8GB disk, move the entire contents to a single folder - let's call it 'www'.
  4. Move /var/ to your 8GB drive (you may want to copy and rename the original instead for a bit of safety) (So, you now have two folders /mnt/www and /mnt/var)
    • (Since /var/www is in var, it is simpler to just move it there at this point (i.e. mv /mnt/www /mnt/var/, although, I you should be able to setup nested mounts)
  5. Mount bind /var: mount -o bind /mnt/var /var
  6. Append to fstab:

    /mnt/var  /var    bind     defaults,noatime,bind        0   0
  7. Check that everything is working, and resume normal operations

This approach should offer the same functionality, with a bit less risk (no repartitioning/resizing file systems) and more flexibility - if you want to add two or three more folders, you don't have to keep making new partitions.

As an aside, moving the entirety of /var to a second disk wouldn't be my first choice, I'd favour moving the directories that store data instead of those that store programs, such as the following: (you will probably find that /var/log and /var/lib use the majority of space in /var anyway).

  • /var/log
  • /var/lib/pgsql
  • /var/spool/mail (and/or /var/vmail)
  • /var/www (which you have already moved)

The same procedure can be applied to most directories (except something like /boot). Also, you may consider using rsync instead of cp, if some files are locked, etc. and you have to run it a second time, it can be more forgiving.

1
  • Thanks for the tip about mount -o bind! For future readers, /mnt/var /var bind defaults,noatime,bind 0 0 might result in a mount: unknown filesystem type 'bind'. Just use none as the type will work.
    – Pentos
    Feb 5, 2012 at 20:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .