虚拟机(Vmware)磁盘扩容(xfs格式)
创始人
2024-04-08 09:44:16

 先将虚拟机关机,按上图调整虚拟磁盘大小。

1.开启并进入虚拟机,打开终端,输入命令 df -Th 查看格式,图示中 /dev/mapper/centos-root 类型为xfs。

[mango@localhost ~]$ df -Th
Filesystem              Type      Size  Used Avail Use% Mounted on
devtmpfs                devtmpfs  1.9G     0  1.9G   0% /dev
tmpfs                   tmpfs     1.9G   16K  1.9G   1% /dev/shm
tmpfs                   tmpfs     1.9G   13M  1.9G   1% /run
tmpfs                   tmpfs     1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/mapper/centos-root xfs        97G   18G   80G  18% /
/dev/sda1               xfs      1014M  185M  830M  19% /boot
tmpfs                   tmpfs     378M     0  378M   0% /run/user/1004
tmpfs                   tmpfs     378M   24K  378M   1% /run/user/1000
[mango@localhost ~]$ 

2.执行 fdisk -l 命令查看磁盘容量,Disk /dev/sda: 107.4 GB

[root@localhost mango]# fdisk -lDisk /dev/sda: 107.4 GB, 107374182400 bytes, 209715200 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000a56edDevice Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200    41943039    19921920   8e  Linux LVMDisk /dev/mapper/centos-root: 104.1 GB, 104144568320 bytes, 203407360 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytesDisk /dev/mapper/centos-swap: 2147 MB, 2147483648 bytes, 4194304 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

3. 新建分区

执行命令:fdisk /dev/sda

然后输入m->n->p->回车->回车->回车->w

WARNING: Re-reading the partition table failed with error 16
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)

然后重起机器,执行命令:reboot ,重启之后执行命令:fdisk -l 查看分区,新的分区号是3

[root@localhost mango]# fdisk -lDisk /dev/sda: 107.4 GB, 107374182400 bytes, 209715200 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000a56edDevice Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200    41943039    19921920   8e  Linux LVM
/dev/sda3        41943040   209715199    83886080   83  LinuxDisk /dev/mapper/centos-root: 104.1 GB, 104144568320 bytes, 203407360 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytesDisk /dev/mapper/centos-swap: 2147 MB, 2147483648 bytes, 4194304 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

4.对/dev/sda3进行格式化

执行命令:mkfs.xfs /dev/sda3

meta-data=/dev/sda3              isize=512    agcount=4, agsize=67108864 blks=                       sectsz=512   attr=2, projid32bit=1=                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=268435455, imaxpct=25=                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=131071, version=2=                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0

5.创建pv

执行命令:pvcreate /dev/sda3,然后输入y。

WARNING: xfs signature detected on /dev/sda3 at offset 0. Wipe it? [y/n]: y
Wiping xfs signature on /dev/sda3.
Physical volume "/dev/sda3" successfully created.

6.处理逻辑卷

执行命令: vgs

VG     #PV #LV #SN Attr   VSize     VFree
centos   1   3   0 wz--n- <40.00g 4.00m

执行命令:vgextend centos /dev/sda3

Volume group "centos" successfully extended

执行命令: vgs

VG     #PV #LV #SN Attr   VSize  VFree
centos   2   3   0 wz--n- <100.00g 60.00g

可以看到由原来的40G变成100G。其中60G是空闲的.

7.扩容

执行命令 df -h 查看要扩容的文件系统的位置 ,这是是/dev/mapper/centos-root

devtmpfs                 7.8G     0  7.8G    0% /dev
tmpfs                    7.8G     0  7.8G    0% /dev/shm
tmpfs                    7.8G  8.9M  7.8G    1% /run
tmpfs                    7.8G     0  7.8G    0% /sys/fs/cgroup
/dev/mapper/centos-root  100G   40G  60G    60% /
/dev/sda1               1014M  188M  827M   19% /boot
tmpfs                    1.6G     0  1.6G    0% /run/user/0

执行命令 lvextend -l +100%free /dev/mapper/centos-root  

Size of logical volume centos/root changed from <40.00 GiB (244470 extents) to 99 G iB(504414 extents).
Logical volume centos/root successfully resized.

执行命令 xfs_growfs /dev/mapper/centos-root ,扩容,调整分区。

meta-data=/dev/mapper/centos-root isize=512    agcount=4, agsize=63249920 blks=                       sectsz=512   attr=2, projid32bit=1=                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=252999680, imaxpct=25=                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=123535, version=2=                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 252888680 to 521435136

 最后执行命令 df -h 查看结果,/dev/mapper/centos-root   97G   18G   80G  18% / 扩容成功。

[root@localhost mango]# df -h
Filesystem               Size  Used Avail Use% Mounted on
devtmpfs                 1.9G     0  1.9G   0% /dev
tmpfs                    1.9G   16K  1.9G   1% /dev/shm
tmpfs                    1.9G   14M  1.9G   1% /run
tmpfs                    1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/mapper/centos-root   97G   18G   80G  18% /
/dev/sda1               1014M  185M  830M  19% /boot
tmpfs                    378M     0  378M   0% /run/user/1004
overlay                   97G   18G   80G  18% /var/lib/docker/overlay2/991379841d72fc0590635ec3200708f4ded9dc835e03f802f41b43e8f5c646c5/merged
overlay                   97G   18G   80G  18% /var/lib/docker/overlay2/2111d79f02eff348c8d279503dd1792f8087f557b5a3cd46cb3b34cfe35ee77c/merged
overlay                   97G   18G   80G  18% /var/lib/docker/overlay2/471057e0f8924906878163b59f57e20b01a2d8b9310f8b0e6fe125703305cafe/merged
overlay                   97G   18G   80G  18% /var/lib/docker/overlay2/1814426175f7cebe390a28befb3b8643689e32f589081f3c686382ad3a3e1fa0/merged
overlay                   97G   18G   80G  18% /var/lib/docker/overlay2/355a1a6ba62146001c72c9f26714763fb99613ddd0d45374047fc43c4caec37a/merged
overlay                   97G   18G   80G  18% /var/lib/docker/overlay2/9efb26b7e01cd506b16898c97bee46b5396ce914493ee38bfa946ec83bbab756/merged
tmpfs                    378M   24K  378M   1% /run/user/1000
tmpfs                    378M     0  378M   0% /run/user/0

相关内容

热门资讯

提... 1、明白目前刷单已经不再是我们获取流量的主要方式。2、我是一条龙专家。 从今年年初到现在,有一个现象...
致癌物超标3倍!这种一次性杯子... 一次性杯子不少人家里都常备尤其是过年接待客人,方便实用但你知道吗有的一次性杯子背后暗藏危机!上海市消...
目... 获取流量的方法已经不再是最重要的淘宝提升流量软件,那么增加淘宝流量最快的方法是什么?首先我们先来了解...
怎... 我们总是需要下载各种软件,而下载软件的方式有上千种,那么如何才能安全下载呢?01下载方法我们首先应该...
重... --------------------2023--------------------各区县(自治...