Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Recently, my 2TB hard drive ran out of space, so I purchased another one to supplement it. My old drive is mounted in a specific folder (does not have system files or anything). Technically, I could just make a new folder and use that as the mountpoint for the new drive, but it would be much neater if I could use LVM to combine the two drives so that there is only one mountpoint.

Is there a way to convert my existing 2TB drive to LVM live? I do not have any external storage to use as a transfer medium nor are there any other backup mediums that will suffice, so I need a way to convert it without actually deleting anything on it (and the drive is full so I cannot create a new partition and use that as backup either).

share|improve this question

3 Answers 3

up vote 0 down vote accepted

Nope, you can't convert an existing full drive to LVM without temporarily moving your data somewhere else. You need to create one or more fresh partitions on the drive, and then run pvcreate on the new filesystem to create an LVM physical volume. Then you create and activate a volume group on top of that, and so on.

However, you say that you bought a new drive so I'm assuming it's at least 2TB, right? That provides you a migration path if you can get both drives running in your system at the same time.

First, connect the big new drive as your second (I'll assume sata) drive. It will come up on the system as /dev/sdb. Use fdisk to create two partitions on it. One should be a small boot partition, a gig is probably plenty. Devote the rest to a new lvm partition. Use the lvm tools (pvcreate, vgcreate, etc.) to set up LVM on that second drive. Leave the small boot partition empty.

Shut down the machine and disconnect your old 2TB drive. Move the new drive to the primary sata interface, or use the bios to make it primary. Boot the machine using your install dvd. Install a new linux system on just the small boot partition you created.

Once you have that working, reconnect your original drive, now on the secondary sata channel. Bring the system up and configure your new LVM-based filesystem as /newdrive (on /dev/sda now, remember). Mount the old drive somewhere like /olddrive.

Copy all the data off the old hard drive onto your new drive by suning something like rsync to copy the contents of /olddrive to /newdrive. Now you have transitioned all your data to the new LVM filesystem.

Now comes the scary part: wipe your original drive. Think very carefully about this because if you wipe the wrong device you lose all your original data. Perhaps you could borrow another drive form someone else to serve as a temporary backup?

Once the original drive is blank, set it up as an LVM device with pvcreate. Then you can use vgextend and lvresize to grow your LVM volume group onto that new device. That can be done while the system is running and will not affect your data on the new drive. Once that operation is done, you have a 4TB volume group. You can use resizefs on the resulting filesystem to make it fill the whole space.

Note that there are many ways to screw this oepration up, but it is feasible. I strongly encourage you to make extra backups somehow. Also note that one giant volume group running on top of two separate drives is not very robust - if one drive fails you could lose a lot of data. A better idea is often to run lvm on top of a raid zero array of two mirrored drives. That way you only get 2TB of space, but one drive dying doesn't cause everything to completely fail. Here's how I performed an LVM migration a while back, for reference.

Another option is to install a third drive in the machine and use it just for booting. That makes things a little simpler since you don't have to set up seperate regular and lvm partitions on your boot device. Actually modern Linux distros may have fixed this but I know a few years back that boot loaders like grub couldn't work with lvm so yo always had to boot off a non-lvm device.

share|improve this answer

Looks like I figured it out on my own: I created a volume group with just the new hard drive, so I can copy the data to the new drive, then wipe the old drive and just add it to the volume group.

share|improve this answer
    
ha absolutely. I've tried to expound on that idea in my ridiculously long answer below. –  Phil Hollenback Mar 2 '11 at 1:24

Yes it can be done, it is old question but I needed to reply as you can convert an existing hard drive to LVM without moving your data and nobody has said it can be done. You need to create one new LVM partition on new disk and then run pvcreate with -Zn on the old filesystem to create an LVM physical volume but rememeber to use -Zn when creating vg or lv other wise you will lose all your data and if you have brought new 2 TB hard disk your total disk will be 2+2 TB.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.