CentOS7LVM logical volume partitions automatically expand Shell scripting


Scenarios and known problems:
Apply to CentOS6 or CentOS7 (probably available on CentOS4 and earlier versions such as 5)
The root file system (extended file system) use LVM to manage, such as the mount command output /dev/mapper/vg_$hostname-lv_root on/type ext4 (RW) contains the Mapper keywords
Automatic expansion of the root file system, if you want to extend the file system, such as the existing business application data directory is not in the root partition, you will need to modify the VG_PATH_TO_EXTEND variable in the Shell script code (around line 78).
Only support partition formats such as ext2, ext3, ext4, XFS file systems
Might not support some customized CentOS system too much, but the most important step is similar to
Scripts only add SCSI disk support, such as the need to manage other disks, you need your own extension scripts
In order to simplify the script, avoiding multiple (the implementation of the present program does not write locks), pre-existing disk name is already set to the SDA, see ONLINE_SCSI_DISK_PRESENT 45th row variables in Shell script code
Considerations:
Due to the CentOS6 and CentOS7 differ in file system format of the default root file system, you need to determine whether for the XFS if XFS xfs_growfs option should be used without using the resize2fs.
Use resize2fs extension of ext2, ext3, ext4 file system format using xfs_growfs expanding XFS file system format
The same script is executed multiple times may be triggered by the same system error, you might consider using file locking to solve this problem
Programming method:
(Should be prepared or checked before Shell scripting environment) Gets a block device file names currently in use
Get new add SCSI disk filename
Gets a LVM volume group (VG), the file path to the volume group name will be expanded
Adds a new disk using Fdisk partition is created and formatted with the LVM format
To create a physical volume, pvcreate
Extending a volume group, vgextend
Adjusting the size of the logical volume, lvresize
To determine whether an XFS file system
Synchronize file systems, making expansion force
Returns the system disk usage
Shell code:

Leave a Reply

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