Using LVM To Upgrade a Disk In a Linux System

Using LVM to upgrade a disk in a Linux system is very easy, assuming everything is set up correctly ahead of time.

The way my Linux system is configured, I have / and /boot on a SSD not using LVM.  I have swap, /var, and /home on a spinning platter drive, configured with LVM.  I recently upgraded it from a 1 TB disk to a 4 TB disk.

The Prereqs for this specific procedure are:

  1. The disk being upgraded must be completely on a LVM volume.
  2. You have to have a spare SATA or SAS port, and available power in your computer to hook up both the new and old drive.  It does not have to be inside your computer during the procedure – in fact mine was sitting on top of it.
So to start, you probably should turn off your computer, then hook up your new drive an appropriate port and its power connection.  Then boot your computer and using your favorite partitioning tool, create one big LVM partition.
NOTE: One that spans a >2 TB disk has to use gpt disk label.
NOTE: Possibly not necessary, but I did this in single user mode
On my system, the disk was /dev/sdb and the new one was /dev/sdc. The Volume group is called vg01.
pvcreate /dev/sdc1
vgextend vg01 /dev/sdc1
pvmove /dev/sdb1 /dev/sdc1
Now you can go do something else.  If you are doing this to multi-TB disks, it will take HOURS, even on a fast computer.
Once that has completed:
vgreduce vg0 /dev/sdb1
Then verify everything is how you expect it to be:
vgdisplay -v vg01
pvdisplay -m
That’s it, once everything is how it should be, you shutdown your computer and remove the old disk from you system, and permanently install the new one and let it boot into multi-user.  Then you can extend a file system to use some of the new space easily enough
NOTE: This can safely be done in multi-user to mounted filesystems: 
lvextend -L 3600g /dev/vg01/home
resize2fs /dev/vg01/home
It really is that easy.

Leave a Reply

Your email address will not be published. Required fields are marked *