首页 > 其他分享 >ESXI虚拟机 硬盘扩容/目录(添加新硬盘)

ESXI虚拟机 硬盘扩容/目录(添加新硬盘)

时间:2022-11-28 10:44:57浏览次数:54  
标签:centos ESXI 虚拟机 1.9 dev LV localhost root 硬盘

背景:

线上服务器,磁盘Linux的虚拟机根分区已经使用90%,触发了磁盘告警,再一顿操作删除后,勉勉强强回到了82%,现在需要对根目录进行扩容。

进入到EXSI管理平台,看到原来的sda磁盘只有30G【图一】,新添加一块100G 的新硬盘【图二】

图一

图二

登录机器,查看磁盘,发现了多了一块sdb

[root@localhost ~]# lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda               8:0    0   30G  0 disk 
├─sda1            8:1    0    1G  0 part /boot
└─sda2            8:2    0   29G  0 part 
  ├─centos-root 253:0    0   26G  0 lvm  /
  └─centos-swap 253:1    0    3G  0 lvm  [SWAP]
sdb               8:16   0  100G  0 disk 
sr0              11:0    1 1024M  0 rom 

第一步:分区

[root@localhost ~]# fdisk /dev/sdb
Welcome 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.

Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x3cb140d1.

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-209715199, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-209715199, default 209715199): 
Using default value 209715199
Partition 1 of type Linux and of size 100 GiB is set

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

再次查看磁盘,发现多了个sdb1

[root@localhost ~]# lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda               8:0    0   30G  0 disk 
├─sda1            8:1    0    1G  0 part /boot
└─sda2            8:2    0   29G  0 part 
  ├─centos-root 253:0    0   26G  0 lvm  /
  └─centos-swap 253:1    0    3G  0 lvm  [SWAP]
sdb               8:16   0  100G  0 disk 
└─sdb1            8:17   0  100G  0 part 
sr0              11:0    1 1024M  0 rom  

第二步:格式化

格式化硬盘,这里使用xfs格式,建议使用和系统一样的文件格式

可以看到/分区 【/dev/mapper/centos-root】 使用的是xfs 的文件系统

[root@localhost ~]# blkid
/dev/sda1: UUID="e1e8eda5-8b7a-45f0-a763-8868777e3f5f" TYPE="xfs" 
/dev/sda2: UUID="DQGZrB-2WRU-JneT-xKKw-WFSN-ozM9-rnW0S4" TYPE="LVM2_member" 
/dev/mapper/centos-root: UUID="a8e67b40-8e6e-4010-a911-21b4f95b90bf" TYPE="xfs" 
/dev/mapper/centos-swap: UUID="326cb3bd-ea93-460d-9f2b-cded2d3836c8" TYPE="swap"

把/dev/sdb1 格式化成 xfs文件系统

[root@localhost ~]# mkfs.xfs /dev/sdb1
meta-data=/dev/sdb1              isize=512    agcount=4, agsize=6553536 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=26214144, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=12799, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0

可以看到/dev/sdb1 的文件系统为 xfs

[root@localhost ~]# blkid
/dev/sda1: UUID="e1e8eda5-8b7a-45f0-a763-8868777e3f5f" TYPE="xfs" 
/dev/sda2: UUID="DQGZrB-2WRU-JneT-xKKw-WFSN-ozM9-rnW0S4" TYPE="LVM2_member" 
/dev/mapper/centos-root: UUID="a8e67b40-8e6e-4010-a911-21b4f95b90bf" TYPE="xfs" 
/dev/mapper/centos-swap: UUID="326cb3bd-ea93-460d-9f2b-cded2d3836c8" TYPE="swap" 
/dev/sdb1: UUID="2eca6693-8885-4efe-a09e-320a0fe4eefa" TYPE="xfs" 

第三步:lvm扩容

通过lvdisplay 可以看到 / 分区 的lv 名称为 root

[root@localhost ~]# lvdisplay 
.............. 
  --- Logical volume ---
  LV Path                /dev/centos/root
  LV Name                root
  VG Name                centos
  LV UUID                upKlP7-AbiZ-e3Yh-aYYN-5Eel-ULsG-TVXVer
  LV Write Access        read/write
  LV Creation host, time localhost, 2021-09-26 05:16:02 -0400
  LV Status              available
  # open                 1
  LV Size                <26.00 GiB
  Current LE             6655
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0

1、创建pv物理卷

[root@localhost ~]# pvcreate /dev/sdb1
WARNING: xfs signature detected on /dev/sdb1 at offset 0. Wipe it? [y/n]: y
  Wiping xfs signature on /dev/sdb1.
  Physical volume "/dev/sdb1" successfully created.

查看下pv物理卷

[root@localhost ~]# pvs
  PV         VG     Fmt  Attr PSize    PFree   
  /dev/sda2  centos lvm2 a--   <29.00g       0 
  /dev/sdb1         lvm2 ---  <100.00g <100.00g

2、向vg卷组 添加 pv物理卷

使用vgdisplay 查看下vg卷组名称为 centos

[root@localhost ~]# vgdisplay 
  --- Volume group ---
  VG Name               centos
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  3
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               <29.00 GiB
  PE Size               4.00 MiB
  Total PE              7423
  Alloc PE / Size       7423 / <29.00 GiB
  Free  PE / Size       0 / 0   
  VG UUID               GzMH6f-8Hne-1SF4-h89q-n95E-0xft-x8JRkb

使用vgextend 添加pv到vg中

[root@localhost ~]# vgextend centos /dev/sdb1
  Volume group "centos" successfully extended

使用vgdisplay,可以看到空闲的PE 容量大约为100G

[root@localhost ~]# vgdisplay 
  --- Volume group ---
  VG Name               centos
  System ID             
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  4
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               128.99 GiB
  PE Size               4.00 MiB
  Total PE              33022
  Alloc PE / Size       7423 / <29.00 GiB
  Free  PE / Size       25599 / <100.00 GiB
  VG UUID               GzMH6f-8Hne-1SF4-h89q-n95E-0xft-x8JRkb

3、扩容逻辑卷 lvm


通过lvdisplay 可以看到 / 分区 的lv 名称为 root

[root@localhost ~]# lvdisplay 
.....................
  --- Logical volume ---
  LV Path                /dev/centos/root
  LV Name                root
  VG Name                centos
  LV UUID                upKlP7-AbiZ-e3Yh-aYYN-5Eel-ULsG-TVXVer
  LV Write Access        read/write
  LV Creation host, time localhost, 2021-09-26 05:16:02 -0400
  LV Status              available
  # open                 1
  LV Size                <26.00 GiB
  Current LE             6655
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0

使用lvextend 增加逻辑卷 100G

[root@localhost ~]# lvextend -L +100G /dev/centos/root 
  Insufficient free space: 25600 extents needed, but only 25599 available

提示没有那么多的空闲的pe去添加,那我们就添加99G 【其实,上面的操作在往vg卷组里添加pv 的时候,也说明了 可用容量< 100G】

[root@localhost ~]# lvextend -L +99G /dev/centos/root 
  Size of logical volume centos/root changed from <26.00 GiB (6655 extents) to <125.00 GiB (31999 extents).
  Logical volume centos/root successfully resized.

添加成功,我们看下磁盘大小,和挂载的情况

[root@localhost ~]# lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda               8:0    0   30G  0 disk 
├─sda1            8:1    0    1G  0 part /boot
└─sda2            8:2    0   29G  0 part 
  ├─centos-root 253:0    0  125G  0 lvm  /
  └─centos-swap 253:1    0    3G  0 lvm  [SWAP]
sdb               8:16   0  100G  0 disk 
└─sdb1            8:17   0  100G  0 part 
  └─centos-root 253:0    0  125G  0 lvm  /
sr0              11:0    1 1024M  0 rom  


[root@localhost ~]# df -h
Filesystem               Size  Used Avail Use% Mounted on
devtmpfs                 1.9G     0  1.9G   0% /dev
tmpfs                    1.9G     0  1.9G   0% /dev/shm
tmpfs                    1.9G  8.9M  1.9G   1% /run
tmpfs                    1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/mapper/centos-root   26G  1.5G   25G   6% /
/dev/sda1               1014M  150M  865M  15% /boot
tmpfs                    379M     0  379M   0% /run/user/0

通过 lsblk 可以看到/ 分区磁盘的容量变成了125G 了,但是 磁盘挂载那边还是没有变化


有两个解决方法:

1、重启

2、刷新下文件系统

这里,我们采用第二种方法,刷新文件系统

注意:不同的文件系统的刷新命令不一样

  • resize2fs 逻辑卷名   (只适用于ext文件系统)
    • xfs_growfs 挂载点 (只适用于xfs文件系统)

通过blkid 查看到/ 分区的文件系统为 xfs 格式【/dev/mapper/centos-root】

[root@localhost ~]# df -h
Filesystem               Size  Used Avail Use% Mounted on
devtmpfs                 1.9G     0  1.9G   0% /dev
tmpfs                    1.9G     0  1.9G   0% /dev/shm
tmpfs                    1.9G  8.9M  1.9G   1% /run
tmpfs                    1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/mapper/centos-root   26G  1.5G   25G   6% /
/dev/sda1               1014M  150M  865M  15% /boot
tmpfs                    379M     0  379M   0% /run/user/0

[root@localhost ~]# blkid
/dev/sda1: UUID="e1e8eda5-8b7a-45f0-a763-8868777e3f5f" TYPE="xfs" 
/dev/sda2: UUID="DQGZrB-2WRU-JneT-xKKw-WFSN-ozM9-rnW0S4" TYPE="LVM2_member" 
/dev/mapper/centos-root: UUID="a8e67b40-8e6e-4010-a911-21b4f95b90bf" TYPE="xfs" 
/dev/mapper/centos-swap: UUID="326cb3bd-ea93-460d-9f2b-cded2d3836c8" TYPE="swap" 
/dev/sdb1: UUID="kuZdno-Kaue-WMEV-d6jh-zTjc-0eAa-YKcDxB" TYPE="LVM2_member" 

使用xfs_growfs 刷新下文件系统

[root@localhost ~]# xfs_growfs /
meta-data=/dev/mapper/centos-root isize=512    agcount=4, agsize=1703680 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=6814720, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=3327, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 6814720 to 32766976

刷新后发现,/ 分区总的磁盘大小变成了125G

[root@localhost ~]# df -h
Filesystem               Size  Used Avail Use% Mounted on
devtmpfs                 1.9G     0  1.9G   0% /dev
tmpfs                    1.9G     0  1.9G   0% /dev/shm
tmpfs                    1.9G  8.9M  1.9G   1% /run
tmpfs                    1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/mapper/centos-root  125G  1.5G  124G   2% /
/dev/sda1               1014M  150M  865M  15% /boot
tmpfs                    379M     0  379M   0% /run/user/0


[root@localhost ~]# lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda               8:0    0   30G  0 disk 
├─sda1            8:1    0    1G  0 part /boot
└─sda2            8:2    0   29G  0 part 
  ├─centos-root 253:0    0  125G  0 lvm  /
  └─centos-swap 253:1    0    3G  0 lvm  [SWAP]
sdb               8:16   0  100G  0 disk 
└─sdb1            8:17   0  100G  0 part 
  └─centos-root 253:0    0  125G  0 lvm  /
sr0              11:0    1 1024M  0 rom  

好了,本次ESXI虚拟机扩容/目录 成功

标签:centos,ESXI,虚拟机,1.9,dev,LV,localhost,root,硬盘
From: https://www.cnblogs.com/ta1zi/p/16931573.html

相关文章