Difference between revisions of "Grow Logical Volume"
(Created page with "This article is split into two parts - resizing a physical volume, and resizing the logical volumes contained within. First, we will cover resizing various configurations of p...") |
(No difference)
|
Revision as of 14:10, 3 January 2018
This article is split into two parts - resizing a physical volume, and resizing the logical volumes contained within. First, we will cover resizing various configurations of physical volumes.
Resizing a PV
First of all, rescan the associated device:
echo 1 > /sys/class/scsi_device/X\:X\:X\:X/device/rescan
And then verify that you see a change in dmesg, e.g.:
# dmesg
</nowiki>[4849955.387134] sdg: detected capacity change from 214748364800 to 322122547200</nowiki>
Having trouble? Try rescanning the entire scsi bus again with:
# echo "- - -" > /sys/class/scsi_host/host1/scan
From a partition
If you are aiming to resize a PV that is a partition of another disk, you will need to find a way to refresh the partition information in the kernel about the disk itself. The first thing to do is to alter the partition information written onto the disk itself, and for this we will use fdisk:
# fdisk /dev/sda
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to switch off the mode (command 'c') and change display units to sectors (command 'u'). Command (m for help): p Disk /dev/sda: 80.5 GB, 80530636800 bytes 255 heads, 63 sectors/track, 9790 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x0008b7e2 Device Boot Start End Blocks Id System /dev/sda1 * 1 66 524288 83 Linux Partition 1 does not end on cylinder boundary. /dev/sda2 66 6528 51903488 8e Linux LVM Command (m for help): d Partition number (1-4): 2 Command (m for help): p Disk /dev/sda: 80.5 GB, 80530636800 bytes 255 heads, 63 sectors/track, 9790 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x0008b7e2 Device Boot Start End Blocks Id System /dev/sda1 * 1 66 524288 83 Linux Partition 1 does not end on cylinder boundary. Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 2 First cylinder (66-9790, default 66): Using default value 66 Last cylinder, +cylinders or +size{K,M,G} (66-9790, default 9790): Using default value 9790 Command (m for help): p Disk /dev/sda: 80.5 GB, 80530636800 bytes 255 heads, 63 sectors/track, 9790 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x0008b7e2 Device Boot Start End Blocks Id System /dev/sda1 * 1 66 524288 83 Linux Partition 1 does not end on cylinder boundary. /dev/sda2 66 9790 78112863 83 Linux Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. WARNING: Re-reading the partition table failed with error 16: Device or resource busy. The kernel still uses the old table. The new table will be used at the next reboot or after you run partprobe(8) or kpartx(8) Syncing disks.
At this point, you can use partprobe
to try and convince the kernel to read the new partition data. Beware, though - if this is the boot disk, this most likely will not work and you must then restart the machine to get the updated partition information into the kernel.
Finishing resizing a PV
This is a simple act of running:
# pvresize /dev/mapper/san4_Data
Physical volume "/dev/dm-10" changed 1 physical volume(s) resized / 0 physical volume(s) not resized
Resizing an LV
Once you have resized the space contained within the Physical Volumes associated with a Volume Group, you can then resize the Logical Volume into the space available:
# lvresize /dev/mapper/Vsan4-Ldata -l +100%FREE
Extending logical volume Vsan4/Ldata to 350.00 GB Logical volume Ldata successfully resized
Lastly, resize the filesystem. First example, ext4:
# resize2fs /dev/mapper/Vsan4-Ldata
resize2fs 1.39 (29-May-2006)
Filesystem at /dev/mapper/Vsan4-Ldata is mounted on /san4; on-line resizing required
Performing an on-line resize of /dev/mapper/Vsan4-Ldata to 30145536 (4k) blocks.
The filesystem on /dev/mapper/Vsan4-Ldata is now 30145536 blocks long.
Or for XFS:
# xfs_growfs /dev/mapper/Vsan4-Ldata
meta-data=/dev/mapper/Vsan4-Ldata isize=256 agcount=16, agsize=3276796 blks
= sectsz=512 attr=2, projid32bit=1
= crc=0 finobt=0
data = bsize=4096 blocks=52428736, imaxpct=25
= sunit=4 swidth=4096 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=0
log =internal bsize=4096 blocks=25600, version=2
= sectsz=512 sunit=4 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 52428736 to 78643200
# df -h /san4
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/Vsan4-Ldata 350G 185G 66G 74% /san4