How to move a folder to a different partition in Linux
My web server on Amazon AWS was low on disk space and I decided to move my /var folder to another partition.
After adding another 50G from the AWS console, I checked the server console to verify
I could see the 50G partition listed as xvdf. The next step was to make it available
Next, I create a folder newvar under the /mnt folder and mounted the partition
mount /dev/xvdf /mnt/newvar
The next step was to copy files from the /var to /mnt/newvar
find . -depth -print0 | cpio --null --sparse -pvd /mnt/newvar
Once the files were copied, I unmounted the newvar folder
Now I had to disconnect the /var folder and replace it with the newvar folder
mv /var /var.old
mount /dev/xvdf /var
The final step was to make an entry in the fstab file to ensure that the /var folder gets mounted on /dev/xvdf
Inser the following line:
/dev/xvdf /var auto defaults 1 2
Save the file and reboot. The /var is now 50G large.