nallanisai there are different ways to migrate /home or any other partition to a LVM volume. Here is one of them:
The first thing I would is make a backup of all the important files in /home.
Since a new disk is being added we have to initialize the disk for use by LVM. I assume the new disk is larger in capacity than the /home file system. Assuming that the new disk is SATA or SCSI device and is assigned the device name /dev/sdb I would use the following command:
This command marks the entire disk to be used by LVM, if you would only like to use a portion or a partition of the drive, you can use:
In this case only the first partition in sdb will be used.
Next step would be to create the volume group using the command vgcreate:
Code:
vgcreate homevg /dev/sdb
homevg is the name of the volume group, it can be any name you like.
Create the logical volume:
The following command creates a logical volume name homelv from the volume group homevg assining 100% of the space available in /dev/sdb
Code:
lvcreate -l 100%FREE -n homelv homevg /dev/sdb
or if you want to assign only some of the space, such as creating 50G logical volume name homelv from the homevg volume group:
Code:
lvcreate -L 50G -n homelv homevg
The “new home” logical volume should be larger than the current /home file system since we want to migrate the contents of /home to the new lv and use the new lv as /home.
We now have to create a file system on the new logical volume
This command creates an ext3 file system in the homelv logical volume which is part of the homevg volume group:
Code:
mkfs.ext3 /dev/homevg/homelv
Create a mount point to mount the new file system to:
Next we want to copy the content of /home to the new file system. We want to make sure that only logged in user is root and that there are no files from /home currently in use. The following line should show any open files in /home and which user and process has the files open:
If this command doesn't return anything, then no files are open from /home.
Make sure you stop any process with open files in /home.
Now we use rsync to copy the content of /home to /mnt/newhome:
Code:
rsync -avx /home/ /mnt/newhome
This may take a while depending on how much data we are copying.
Verify that all the data has been copied and then mount your “new home” file system in /home:
umount /home
Code:
mount /dev/homevg/homelv /home
Don't forget to adjust the entry in /etc/fstab so that /home points to /dev/homevg/homelv.
Verify that everything is there and that it works as it should. Now you can free up the space on the old /home and add it to your your new logical volume. You can extend the size of the logical volume without having umount the file system.
For more information on logical volumes you should read the redhat/centos documentation on
LVM Administration