-   Red Hat (
-   -   help needed with LVM (

basheer 03-05-2011 12:08 PM

help needed with LVM
I have my harddisk partitioned with fdisk. It has seven partitions. I have some important data in my /home partition. The /home partition is almost full. I want to extend the size of /home. Mind you I'm not using LVM. Can I use LVM now and add another harddisk to extend the /home partition. Will I lose my data. Or do I have to re-install linux?

acid_kewpie 03-05-2011 02:33 PM

there's certainly no need to reinstall, but you wouldn't have a seamless migration to LVM. You'd need to create a new LVM volume, migrate /home to it, and then add the old /home location to the new LVM volume. In this case, it sounds, without knowing the disk sizes at stake, that you probably wouldn't want to add the old partition to it anyway, if you have a whole new disk to dedicate to /home anyway.

nallanisai 03-05-2011 04:55 PM

Hi Chris,

Any commands how to migrate /home and how to add /home location to new created LVM volume.

eegerda 03-06-2011 10:17 AM

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:

pvcreate /dev/sdb
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:

pvcreate /dev/sdb1
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:

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

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:

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:

mkfs.ext3 /dev/homevg/homelv
Create a mount point to mount the new file system to:

mkdir /mnt/newhome
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:

lsof |grep "/home"
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:

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

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

All times are GMT -5. The time now is 09:47 PM.