Sometimes when I install Linux, I do not do the partition configuration on Linux so that my Linux only has one partition that is partition /. This will cause problems if one folder commonly used by the system such as /var or /usr folder size is getting larger so the server cannot run normally due to partition / lack of space. Therefore, this article will explain how to move the full folder that resides on the partition / to the new hard disk. This article uses CentOS 7 and it should be applicable to another Linux.
Example condition of my server like this:
You can see that partition / has only 4% available file size and I try to know which folders have big size, I see folder /var is the biggest:
So, I want to try move folder /var to another folder. Then I must insert a new hard disk to the server and make sure CentOS can detect hard disk using command fdisk -l:
You can see that CentOS can detect the hard disk as /dev/sdb. Next, I must format the new hard disk with type the commands:
After that, I must move data in folder /var to /mnt/newvar. To do that, I must change to the single-user mode with type init 1. After I type init 1, the server will display like this:
Type root password and I must copy data in folder /var to /mnt/newvar.
and I check partition size:
From the picture above, I can see that folder /var has separated from the partition / but partition / still 96% was used. So I delete folder /var.old and then check partition size:
Now we can see that partition / only 3% was used. In order to /var partition can be mounted automatically after server reboot then adds the following script in file /etc/fstab: