Lvm – Convert full hard drive to LVM without external storage

hard drivelvm

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).

Best Answer

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.

Related Topic