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:
umount
and useresize2fs
(orparted
) to resize the partition on the 8GB disk.parted
to create a new 4 GB partition on the free space.mount
the new parition to say/media/new
cp -a
to copy my/var
from the 1GB partition to the new 4GB partition. (or should I usetar
for this?)- add an entry for the new partition in
fstab
- 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?
Best Answer
You don't actually have to repartition your disk to accomplish this. An alternate solution is to use
mount -o bind
.lsof | grep /var
- if there are, kill the processes holding them.mv /mnt/www /mnt/var/
, although, I you should be able to setup nested mounts)mount -o bind /mnt/var /var
Append to fstab:
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).
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.