Linux HOT grow of vdisk/underlying LVM

Notice: Page may contain affiliate links for which we may earn a small commission through services like Amazon Affiliates or Skimlinks.

whitey

Moderator
Jun 30, 2014
2,766
868
113
41
Figured I'd throw this out there for all to benefit as a golden nugget one of these days. My Red Hat Satellite Server at work is abt toast on it's VG for free space and I needed to add some more space, on the fly/HOT. Done this a few times before for various reasons (usually to get out of a not so well thought out disk partitioning scheme or one that we simply outgrew) so I thought I'd actually document it and post for prosperity. This is all done hot/live while vm is up. This is definitely a production lifesaver, all of these cmds really, muuuhahaha the pwr of LVM, ALMOST as good as ZFS :-D

vdisk-increasesize-rescanscsibus-fdiskgeometrysync-pvresize-lvresize-resize2fs-HOT.png

I know you can do the dance of 'just add another vdisk, pvcreate, vgextend, lvresize, resize2fs, etc.' but this is WAY cleaner and does not introduce vmdk cruft, that's just editing a secondary data disk that was 100GB and taking it to 120GB with zero downtime on the Linux server VM. (My prd VM went from 1.5TB to 2TB), had to test in the home lab first ya know before I introduce a CLM if ya know what I mean :-D

Easy enough to port to whatever virt technology (KVM/Xen/etc.) as long as you can change vdisk size live.

Take care, all, hopefully someone gains something out of this.
 
Last edited:

TuxDude

Well-Known Member
Sep 17, 2011
616
338
63
No need to rescan the entire SCSI bus to pick up changes to an existing disk (you do need that command if you hot-add a new drive), or for any messing around with fdisk. Also note that it only works when you are using the entire device as a LVM-PV (eg. /dev/sdb as in the OP - if you are using /dev/sdb1 you need to add a new partition/device to grow without downtime, you can't edit a partition that is in use).


To force linux to rescan an existing device, which will pick up a change in size of the underlying VM disk (run as root):

echo 1 > /sys/block/sdx/device/rescan # Change the x so that you are scanning the device that you resized.

Optionally you can run 'dmesg', and should see a line or two telling you that changes were discovered. If not you probably rescanned the wrong device. Assuming that you rescanned the correct device, you can move straight on to the 'pvresize' command, no fdisk usage is needed.

You can also change the lvresize command so that it will automatically just use all of the new space instead of having to specify the amount:

lvresize -l +100%FREE <path-to-lv>

And if you're doing this on RHEL7 (or clones) and left the defaults during install, you now have an XFS filesystem instead of EXT4, so the 'resize2fs' command changes to 'xfs_growfs <path>'

That will get you down to just 4 commands needing to be run on the linux server, plus whatever work you do at the virtualization layer to resize the underlying disk first.
 

cptbjorn

Member
Aug 16, 2013
100
19
18
For the most part I just format and mount bare block devices without partitioning. Mainly because it makes it easier to build bootstrapped puppetized servers and more portable between hypervisor types and public clouds, but also if you need to resize you just do a rescan and then grow the filesystem instead of having to muck around with partitions and LVMs
 

whitey

Moderator
Jun 30, 2014
2,766
868
113
41
No need to rescan the entire SCSI bus to pick up changes to an existing disk (you do need that command if you hot-add a new drive), or for any messing around with fdisk. Also note that it only works when you are using the entire device as a LVM-PV (eg. /dev/sdb as in the OP - if you are using /dev/sdb1 you need to add a new partition/device to grow without downtime, you can't edit a partition that is in use).


To force linux to rescan an existing device, which will pick up a change in size of the underlying VM disk (run as root):

echo 1 > /sys/block/sdx/device/rescan # Change the x so that you are scanning the device that you resized.

Optionally you can run 'dmesg', and should see a line or two telling you that changes were discovered. If not you probably rescanned the wrong device. Assuming that you rescanned the correct device, you can move straight on to the 'pvresize' command, no fdisk usage is needed.

You can also change the lvresize command so that it will automatically just use all of the new space instead of having to specify the amount:

lvresize -l +100%FREE <path-to-lv>

And if you're doing this on RHEL7 (or clones) and left the defaults during install, you now have an XFS filesystem instead of EXT4, so the 'resize2fs' command changes to 'xfs_growfs <path>'

That will get you down to just 4 commands needing to be run on the linux server, plus whatever work you do at the virtualization layer to resize the underlying disk first.
Thanks for the tips/tricks, this one was GOLD although my fdisk trick was working as well just more steps 'echo 1 > /sys/block/sdx/device/rescan' yeah I guess a scsi bus rescan isn't needed since I dont actually add a vdisk but expand an existing vdisk at virt layer. I knew abt xfs_growfs as I run a bunch of RHEL7 boxes already and have crossed that fun path already (first time you throw resize2fs at XFS makes ya go wtf until you realize the errors in your ways lol), good stuff, down to 4 cmds indeed.
 

TuxDude

Well-Known Member
Sep 17, 2011
616
338
63
Thanks for the tips/tricks, this one was GOLD although my fdisk trick was working as well just more steps 'echo 1 > /sys/block/sdx/device/rescan' yeah I guess a scsi bus rescan isn't needed since I dont actually add a vdisk but expand an existing vdisk at virt layer. I knew abt xfs_growfs as I run a bunch of RHEL7 boxes already and have crossed that fun path already (first time you throw resize2fs at XFS makes ya go wtf until you realize the errors in your ways lol), good stuff, down to 4 cmds indeed.
Ya - I added the bit about xfs_growfs just to make sure all of that info was in the thread here, so that when someone finds it in a google search in 6 months they get everything in one place.