Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - Distributions > Red Hat
User Name
Red Hat This forum is for the discussion of Red Hat Linux.


  Search this Thread
Old 03-05-2011, 12:08 PM   #1
Registered: Mar 2009
Location: Bangalore, India
Distribution: CentOS6.5, CentOS7, Ubuntu14.04
Posts: 182

Rep: Reputation: 29
Unhappy 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?
Old 03-05-2011, 02:33 PM   #2
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1977Reputation: 1977Reputation: 1977Reputation: 1977Reputation: 1977Reputation: 1977Reputation: 1977Reputation: 1977Reputation: 1977Reputation: 1977Reputation: 1977
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.
Old 03-05-2011, 04:55 PM   #3
LQ Newbie
Registered: Dec 2010
Location: Bangalore
Distribution: Red Hat Linux
Posts: 28

Rep: Reputation: 0
Hi Chris,

Any commands how to migrate /home and how to add /home location to new created LVM volume.
Old 03-06-2011, 10:17 AM   #4
LQ Newbie
Registered: Apr 2005
Location: NJ
Distribution: Centos 5.5
Posts: 15

Rep: Reputation: 1

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



Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Advice needed on partitions, LVM Azazwa Linux - Newbie 6 07-12-2010 09:42 AM
Basic LVM Education Needed jamoody Linux - General 2 11-25-2008 07:36 PM
LVM resizing advice needed yunusyb Linux - Server 4 07-05-2008 02:14 AM
Raid 0 and LVM Help needed Legolas327 Linux - Newbie 1 02-10-2008 12:20 PM
Help needed with LVM jalmod Linux - General 4 06-23-2007 09:17 AM > Forums > Linux Forums > Linux - Distributions > Red Hat

All times are GMT -5. The time now is 05:19 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration