1.首先给虚拟机添加一块硬盘(最好是同类型的,但不同类型的好像也成功了)
2.启动虚拟机,对硬盘进行分区
[root@gjm ~]# fdisk /dev/nvme0n2 欢迎使用 fdisk (util-linux 2.23.2)。 更改将停留在内存中,直到您决定将更改写入磁盘。 使用写入命令前请三思。 Device does not contain a recognized partition table 使用磁盘标识符 0x5f046293 创建新的 DOS 磁盘标签。 命令(输入 m 获取帮助):n Partition type: p primary (0 primary, 0 extended, 4 free) e extended Select (default p): Using default response p 分区号 (1-4,默认 1): 起始 扇区 (2048-20971519,默认为 2048): 将使用默认值 2048 Last 扇区, +扇区 or +size{K,M,G} (2048-20971519,默认为 20971519): 将使用默认值 20971519 分区 1 已设置为 Linux 类型,大小设为 10 GiB 命令(输入 m 获取帮助):t 已选择分区 1 Hex 代码(输入 L 列出所有代码):8e 已将分区“Linux”的类型更改为“Linux LVM” 命令(输入 m 获取帮助):w The partition table has been altered! Calling ioctl() to re-read partition table. 正在同步磁盘。
3.根据新建分区,创建一个新的pv
[root@gjm ~]# pvcreate /dev/sda1 Physical volume "/dev/sda1" successfully created. [root@gjm ~]# pvdisplay --- Physical volume --- PV Name /dev/nvme0n1p2 VG Name centos_gjm PV Size <59.00 GiB / not usable 3.00 MiB Allocatable yes PE Size 4.00 MiB Total PE 15103 Free PE 1 Allocated PE 15102 PV UUID nIM8YH-AGz8-bQAS-FnUz-cOhA-qFwD-d8TemG "/dev/sda1" is a new physical volume of "<20.00 GiB" --- NEW Physical volume --- PV Name /dev/sda1 VG Name PV Size <20.00 GiB Allocatable NO PE Size 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID K6ZoNN-11Gt-09Xs-x1Jv-Idcm-LzFw-gJtHAU
4.查看vg组,并将新建的pv加入到根目录所在的vg组中
[root@gjm ~]# vgextend centos_gjm /dev/sda1 Volume group "centos_gjm" successfully extended [root@gjm ~]# vgs VG #PV #LV #SN Attr VSize VFree centos_gjm 2 3 0 wz--n- 78.99g 20.00g [root@gjm ~]# vgdisplay --- Volume group --- VG Name centos_gjm System ID Format lvm2 Metadata Areas 2 Metadata Sequence No 5 VG Access read/write VG Status resizable MAX LV 0 Cur LV 3 Open LV 3 Max PV 0 Cur PV 2 Act PV 2 VG Size 78.99 GiB PE Size 4.00 MiB Total PE 20222 Alloc PE / Size 15102 / 58.99 GiB Free PE / Size 5120 / 20.00 GiB VG UUID ujPCog-empR-5mxd-I7DP-ugKO-PNN1-NXZAye
5.给根目录的lv卷扩容,并且使用xfs_growfs对文件系统进行扩容
[root@gjm ~]# lvextend -l +100%FREE /dev/centos_gjm/root Size of logical volume centos_gjm/root changed from <37.04 GiB (9481 extents) to <57.04 GiB (14601 extents). Logical volume centos_gjm/root successfully resized. [root@gjm ~]# xfs_growfs /dev/centos_gjm/root meta-data=/dev/mapper/centos_gjm-root isize=512 agcount=4, agsize=2427136 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0 spinodes=0 data = bsize=4096 blocks=9708544, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=1 log =internal bsize=4096 blocks=4740, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 data blocks changed from 9708544 to 14951424
6.此时使用df -h命令查看根目录内存情况
扩容前
[root@gjm ~]# df -h 文件系统 容量 已用 可用 已用% 挂载点 /dev/mapper/centos_gjm-root 38G 5.1G 32G 14% / devtmpfs 1.9G 0 1.9G 0% /dev tmpfs 1.9G 0 1.9G 0% /dev/shm tmpfs 1.9G 13M 1.9G 1% /run tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup /dev/nvme0n1p1 1014M 166M 849M 17% /boot /dev/mapper/centos_gjm-home 19G 37M 19G 1% /home tmpfs 378M 8.0K 378M 1% /run/user/42 tmpfs 378M 0 378M 0% /run/user/0
扩容后
[root@gjm ~]# df -h 文件系统 容量 已用 可用 已用% 挂载点 /dev/mapper/centos_gjm-root 58G 5.1G 52G 9% / devtmpfs 1.9G 0 1.9G 0% /dev tmpfs 1.9G 0 1.9G 0% /dev/shm tmpfs 1.9G 13M 1.9G 1% /run tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup /dev/nvme0n1p1 1014M 179M 836M 18% /boot /dev/mapper/centos_gjm-home 19G 37M 19G 1% /home tmpfs 378M 8.0K 378M 1% /run/user/42 tmpfs 378M 0 378M 0% /run/user/0
标签:centos,虚拟机,1.9,dev,gjm,根目录,tmpfs,root,硬盘 From: https://www.cnblogs.com/gjm-study-test/p/16715916.html