Move your /home to a new LVM partition

To have better control and security over your Linux OS, you might want to move your say /home  or /var to another LVM partition. The advantage is that you can easily increase / decrease the size at a future stage.On this article, i will take an example of the /home directory and we will move it to a fresh disk on Virtual Box. Here is an example of a df -h on my virtual Machine.We will now add a new disk [sdc] by creating another VG.Screenshot from 2015-10-21 19:22:05Start with the following steps:
  • pvcreate /dev/sdc
  • vgcreate vghome /dev/sdc
  • lvcreate -l 100%FREE vghome
  • lvrename /dev/vghome/lvol0 /dev/vghome/lvhome 
Screenshot from 2015-10-21 19:27:38Once you have succesfully created the lvhome, you will need to edit your /etc/fstab before mounting the partition so that each time you reboot your machine, it will render the same configuration. I have inserted the following parameters:
  • /dev/mapper/vghome-lvhome /home ext4 defaults,noatime 1 2 
Screenshot from 2015-10-21 19:32:28 You will also need to format the partition before mounting the disk with this command :
  • mkfs.ext4 /dev/mapper/vghome-lvhome
Screenshot from 2015-10-21 19:35:49
  • You now need to mount the partition by using the following command mount /home
  • Here is now the results from a df -h
Screenshot from 2015-10-21 19:39:55
Tips:
  • You can also format your partition with ext3 when your /etc/fstab has been specified with the ext4 format as ext4 support ext3
  • You can also specify the name of the lv directly whilst creating it by using the command lvcreate -l 100%FREE -n lvhome vghome so that you don't need to rename anew the lv. By default on Vbox and Vmware it use lvol0
  • More articles i have posted on LVM are :
Add and extend disk on Virtual Box through LVMManaging LVM with Pvmove - Part 1 Managing LVM with Pvmove - Part 2