虚拟机磁盘扩容
参考:https://blog.csdn.net/qq_26963433/article/details/79467959
lsblk -f查看连接的磁盘设备和文件格式
假设原虚拟机使用xfs格式的逻辑卷
- 扩容硬盘,假设扩容设备为/dev/vdb,从100g扩容到200g
- 增加分区fdisk,类型为8e (如果使用整块盘,此步骤非必要)
- fdisk -l 查看分区
- fdisk /dev/vdb,n新建分区其他默认,
- p查看类型,类型不对用t修改
- w保存
- partprobe启用分区表
- 创建物理卷
- pvdisplay查看
- pvcreate /dev/vdb2
- 扩展卷组
- vgdisplay查看 ,原vg名为vg_data
- vgextend vg_data /dev/vdb2
- 扩展逻辑卷
- lvdisplay查看,copy原lv路径
- lvextend -l +100%FREE /dev/vg_data/lv_data
- 刷新文件系统大小
- 扩容文件系统xfs_growfs /dev/vg_data/lv_data
- 其他文件格式是用resize2fs /dev/vg_data/lv_data
- 查看生效 df
举例:
[root@srd-code-gerrit-2 ~]# fdisk -lDisk /dev/vda: 42.9 GB, 42949672960 bytes, 83886080 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: 0x000bcc64Device Boot Start End Blocks Id System/dev/vda1 2048 8390655 4194304 82 Linux swap / Solaris/dev/vda2 * 8390656 83886046 37747695+ 83 LinuxDisk /dev/vdb: 536.9 GB, 536870912000 bytes, 1048576000 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: 0x19260f80Device Boot Start End Blocks Id System/dev/vdb1 2048 419430399 209714176 8e Linux LVMDisk /dev/mapper/vg_data-lv_data: 214.7 GB, 214744170496 bytes, 419422208 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytes[root@srd-code-gerrit-2 ~]# fdisk /dev/vdbWelcome 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/vdb: 536.9 GB, 536870912000 bytes, 1048576000 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: 0x19260f80Device Boot Start End Blocks Id System/dev/vdb1 2048 419430399 209714176 8e Linux LVMCommand (m for help): nPartition type:p primary (1 primary, 0 extended, 3 free)e extendedSelect (default p):Using default response pPartition number (2-4, default 2):First sector (419430400-1048575999, default 419430400):Using default value 419430400Last sector, +sectors or +size{K,M,G} (419430400-1048575999, default 1048575999):Using default value 1048575999Partition 2 of type Linux and of size 300 GiB is setCommand (m for help): pDisk /dev/vdb: 536.9 GB, 536870912000 bytes, 1048576000 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: 0x19260f80Device Boot Start End Blocks Id System/dev/vdb1 2048 419430399 209714176 8e Linux LVM/dev/vdb2 419430400 1048575999 314572800 83 LinuxCommand (m for help): tPartition number (1,2, default 2):Hex code (type L to list all codes): 8eChanged type of partition 'Linux' to 'Linux LVM'Command (m for help): pDisk /dev/vdb: 536.9 GB, 536870912000 bytes, 1048576000 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: 0x19260f80Device Boot Start End Blocks Id System/dev/vdb1 2048 419430399 209714176 8e Linux LVM/dev/vdb2 419430400 1048575999 314572800 8e Linux LVMCommand (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@srd-code-gerrit-2 ~]# partprobe[root@srd-code-gerrit-2 ~]# pvdisplay--- Physical volume ---PV Name /dev/vdb1VG Name vg_dataPV Size <200.00 GiB / not usable 3.00 MiBAllocatable yes (but full)PE Size 4.00 MiBTotal PE 51199Free PE 0Allocated PE 51199PV UUID mmVYBe-1OHD-PZSJ-KyBd-IgIM-cMNz-hlYl0y[root@srd-code-gerrit-2 ~]# pvcreate /dev/vdb2Physical volume "/dev/vdb2" successfully created.[root@srd-code-gerrit-2 ~]# lvdisplay--- Logical volume ---LV Path /dev/vg_data/lv_dataLV Name lv_dataVG Name vg_dataLV UUID OT7IYK-xaSX-KbPs-k8zb-bjWb-N9od-uNE1oELV Write Access read/writeLV Creation host, time srd-code-gerrit-2, 2021-06-17 16:19:12 +0800LV Status available# open 1LV Size <200.00 GiBCurrent LE 51199Segments 1Allocation inheritRead ahead sectors auto- currently set to 8192Block device 252:0[root@srd-code-gerrit-2 ~]# vgdisplay--- Volume group ---VG Name vg_dataSystem IDFormat lvm2Metadata Areas 1Metadata Sequence No 2VG Access read/writeVG Status resizableMAX LV 0Cur LV 1Open LV 1Max PV 0Cur PV 1Act PV 1VG Size <200.00 GiBPE Size 4.00 MiBTotal PE 51199Alloc PE / Size 51199 / <200.00 GiBFree PE / Size 0 / 0VG UUID c3ZqAV-TBt7-nG4W-XYao-d407-sZib-U3QAyc[root@srd-code-gerrit-2 ~]# vgextend vg_data /dev/vdb2Volume group "vg_data" successfully extended[root@srd-code-gerrit-2 ~]# lvextend -l +100%FREE /dev/vg_data/lv_dataSize of logical volume vg_data/lv_data changed from <200.00 GiB (51199 extents) to 499.99 GiB (127998 extents).Logical volume vg_data/lv_data successfully resized.[root@srd-code-gerrit-2 ~]# df -hFilesystem Size Used Avail Use% Mounted ondevtmpfs 126G 0 126G 0% /devtmpfs 126G 0 126G 0% /dev/shmtmpfs 126G 17M 126G 1% /runtmpfs 126G 0 126G 0% /sys/fs/cgroup/dev/vda2 36G 3.6G 30G 11% //dev/mapper/vg_data-lv_data 197G 110G 78G 59% /datasfs-nas1.cn-sz1.internal.ctclouds.com:/share-d5c508dc 1000G 90G 911G 9% /mnt/gerritgitoverlay 197G 110G 78G 59% /data/docker/overlay2/af9b9127e31a43d2fcf827b12169de493a14197d91ddc6c402618e31c1067be2/mergedshm 64M 0 64M 0% /data/docker/containers/0b0d772defa1335aff1e9c0d58f1a81b0a2b7c1fc3635e07d85051941f31321a/shmtmpfs 26G 0 26G 0% /run/user/0[root@srd-code-gerrit-2 ~]# resize2fs /dev/vg_data/lv_dataresize2fs 1.42.9 (28-Dec-2013)Filesystem at /dev/vg_data/lv_data is mounted on /data; on-line resizing requiredold_desc_blocks = 25, new_desc_blocks = 63The filesystem on /dev/vg_data/lv_data is now 131069952 blocks long.[root@srd-code-gerrit-2 ~]# df -hFilesystem Size Used Avail Use% Mounted ondevtmpfs 126G 0 126G 0% /devtmpfs 126G 0 126G 0% /dev/shmtmpfs 126G 17M 126G 1% /runtmpfs 126G 0 126G 0% /sys/fs/cgroup/dev/vda2 36G 3.6G 30G 11% //dev/mapper/vg_data-lv_data 493G 110G 361G 24% /datasfs-nas1.cn-sz1.internal.ctclouds.com:/share-d5c508dc 1000G 90G 911G 9% /mnt/gerritgitoverlay 493G 110G 361G 24% /data/docker/overlay2/af9b9127e31a43d2fcf827b12169de493a14197d91ddc6c402618e31c1067be2/mergedshm 64M 0 64M 0% /data/docker/containers/0b0d772defa1335aff1e9c0d58f1a81b0a2b7c1fc3635e07d85051941f31321a/shmtmpfs 26G 0 26G 0% /run/user/0[root@srd-code-gerrit-2 ~]#
