一,Centos为硬盘新增容量分区并挂载到根目录
1.查看硬盘的情况。
可以看到硬盘新增了大小,但是没有被用起来。
下面我要做的其实就是lvm扩展
[root@Slave2 ~]# fdisk /dev/sdaWelcome to fdisk (util-linux 2.23.2).Changes will remain in memory only, until you decide to write them.Be careful before using the write command.Command (m for help): pDisk /dev/sda: 429.5 GB, 429496729600 bytes, 838860800 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk label type: dosDisk identifier: 0x0001784cDevice Boot Start End Blocks Id System/dev/sda1 * 2048 2099199 1048576 83 Linux/dev/sda2 2099200 33554431 15727616 8e Linux LVMCommand (m for help): nPartition type:p primary (2 primary, 0 extended, 2 free)e extendedSelect (default p): pPartition number (3,4, default 3): 3First sector (33554432-838860799, default 33554432): 33554432Last sector, +sectors or +size{K,M,G} (33554432-838860799, default 838860799): 838860799Partition 3 of type Linux and of size 384 GiB is setCommand (m for help): pDisk /dev/sda: 429.5 GB, 429496729600 bytes, 838860800 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk label type: dosDisk identifier: 0x0001784cDevice Boot Start End Blocks Id System/dev/sda1 * 2048 2099199 1048576 83 Linux/dev/sda2 2099200 33554431 15727616 8e Linux LVM/dev/sda3 33554432 838860799 402653184 83 LinuxCommand (m for help): wThe 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 atthe next reboot or after you run partprobe(8) or kpartx(8)Syncing disks.[root@Slave2 ~]#
用 partprobe /dev/sda3 没有启作用,重启后生效

可以看到sda3为刚刚新增的分区。
开始扩容:
创建物理卷:
[root@Slave2 ~]# lvmlvm> pvcreate /dev/sda3Physical volume "/dev/sda3" successfully created.lvm>
查看物理卷和卷组:
lvm> pvdisplay--- Physical volume ---PV Name /dev/sda2VG Name centosPV Size <15.00 GiB / not usable 3.00 MiBAllocatable yes (but full)PE Size 4.00 MiBTotal PE 3839Free PE 0Allocated PE 3839PV UUID VZ9vj7-442j-SGbv-3ZRj-gdDs-kQuK-YIPcEj"/dev/sda3" is a new physical volume of "384.00 GiB"--- NEW Physical volume ---PV Name /dev/sda3VG NamePV Size 384.00 GiBAllocatable NOPE Size 0Total PE 0Free PE 0Allocated PE 0PV UUID TRQMxO-ouRd-E4GM-mL60-R4Ub-3FsX-BjiXZFlvm>
将物理卷加入到卷组:
lvm> vgextend centos /dev/sda3Volume group "centos" successfully extendedlvm> vgdisplay--- Volume group ---VG Name centosSystem IDFormat lvm2Metadata Areas 2Metadata Sequence No 4VG Access read/writeVG Status resizableMAX LV 0Cur LV 2Open LV 2Max PV 0Cur PV 2Act PV 2VG Size 398.99 GiBPE Size 4.00 MiBTotal PE 102142Alloc PE / Size 3839 / <15.00 GiBFree PE / Size 98303 / <384.00 GiBVG UUID e6v5QC-dUMm-yUWn-KSy7-5eOx-ttq6-5eyDIDlvm>
将卷组剩余空间添加到逻辑卷组/dev/centos/root
lvm> lvextend -l +100%FREE /dev/centos/rootSize of logical volume centos/root changed from 13.39 GiB (3429 extents) to 397.39 GiB (101732 extents).Logical volume centos/root successfully resized.lvm>
同步到文件系统
lvm> exitExiting.[root@Slave2 ~]# xfs_growfs /dev/centos/rootmeta-data=/dev/mapper/centos-root isize=512 agcount=4, agsize=877824 blks= sectsz=512 attr=2, projid32bit=1= crc=1 finobt=0 spinodes=0data = bsize=4096 blocks=3511296, imaxpct=25= sunit=0 swidth=0 blksnaming =version 2 bsize=4096 ascii-ci=0 ftype=1log =internal bsize=4096 blocks=2560, version=2= sectsz=512 sunit=0 blks, lazy-count=1realtime =none extsz=4096 blocks=0, rtextents=0data blocks changed from 3511296 to 104173568[root@Slave2 ~]# df -hFilesystem Size Used Avail Use% Mounted ondevtmpfs 7.8G 0 7.8G 0% /devtmpfs 7.8G 0 7.8G 0% /dev/shmtmpfs 7.8G 8.8M 7.8G 1% /runtmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup/dev/mapper/centos-root 398G 9.9G 388G 3% //dev/sda1 1014M 150M 865M 15% /boottmpfs 1.6G 0 1.6G 0% /run/user/0[root@Slave2 ~]#
