Press "Enter" to skip to content

ESXI Centos7 磁盘扩容

背景:

当初装系统的时候,磁盘空间分的太小了,不够用。想增加点磁盘空间给服务器。

ESXI部署的Centos7系统。

操作:

1.现在esxi上面给虚拟机对应磁盘的空间调大,这个很简单。

2.进入虚拟机,df -h ,fdisk -l 命令查看磁盘状况,发现磁盘大小,可用空间并没有变化,这很正常。

[root@kafka1 ~]# df -h
Filesystem               Size  Used Avail Use% Mounted on
devtmpfs                 908M     0  908M   0% /dev
tmpfs                    920M     0  920M   0% /dev/shm
tmpfs                    920M  8.9M  911M   1% /run
tmpfs                    920M     0  920M   0% /sys/fs/cgroup
/dev/mapper/centos-root   14G  2.8G   11G  21% /
/dev/sda1               1014M  182M  833M  18% /boot
tmpfs                    184M     0  184M   0% /run/user/0
[root@kafka1 ~]# fdisk -l

Disk /dev/sda: 17.2 GB, 17179869184 bytes, 33554432 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: 0x000aa121

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200    33554431    15727616   8e  Linux LVM

Disk /dev/mapper/centos-root: 14.4 GB, 14382268416 bytes, 28090368 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 /dev/mapper/centos-swap: 1719 MB, 1719664640 bytes, 3358720 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.虚拟机中刷新scsi

ls /sys/class/scsi_disk/
0:0:0:0
echo 1 >/sys/class/scsi_disk/0\:0\:0\:0/device/rescan

4.再使用fdisk -l命令查看磁盘,发现空间磁盘变大了。

[root@kafka1 ~]# ls /sys/class/scsi_disk/
0:0:0:0
[root@kafka1 ~]# echo 1 >/sys/class/scsi_disk/0\:0\:0\:0/device/rescan
[root@kafka1 ~]# fdisk -l

Disk /dev/sda: 32.2 GB, 32212254720 bytes, 62914560 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: 0x000aa121

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200    33554431    15727616   8e  Linux LVM

Disk /dev/mapper/centos-root: 14.4 GB, 14382268416 bytes, 28090368 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 /dev/mapper/centos-swap: 1719 MB, 1719664640 bytes, 3358720 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. 使用命令 fdisk /dev/sda 对磁盘进行可用空间分区。

[root@kafka1 ~]# fdisk /dev/sda
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.


Command (m for help): p

Disk /dev/sda: 32.2 GB, 32212254720 bytes, 62914560 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: 0x000aa121

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200    33554431    15727616   8e  Linux LVM

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

Command (m for help): p

Disk /dev/sda: 32.2 GB, 32212254720 bytes, 62914560 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: 0x000aa121

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200    33554431    15727616   8e  Linux LVM
/dev/sda3        33554432    62914559    14680064   83  Linux

Command (m for help): t
Partition number (1-3, default 3): 3
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'

Command (m for help): p

Disk /dev/sda: 32.2 GB, 32212254720 bytes, 62914560 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: 0x000aa121

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200    33554431    15727616   8e  Linux LVM
/dev/sda3        33554432    62914559    14680064   8e  Linux LVM

Command (m for help): w
The 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 at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.

注意,这里我用t命令将分区code改成8e,用于inux分区LVM类型。

5.将我们新加的分区进行初始化。

[root@kafka1 ~]# pvcreate /dev/sda3
  Device /dev/sda3 not found.

他会提示你设备不存在,刷一下。

[root@kafka1 ~]# partprobe -s
/dev/sda: msdos partitions 1 2 3
[root@kafka1 ~]# pvcreate /dev/sda3
  Physical volume "/dev/sda3" successfully created.

6. 查看待扩容的VG名称 pvdisplay

[root@kafka1 ~]# pvdisplay
  --- Physical volume ---
  PV Name               /dev/sda2
  VG Name               centos
  PV Size               <15.00 GiB / not usable 3.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              3839
  Free PE               0
  Allocated PE          3839
  PV UUID               RYNzEm-V9M9-OdZr-PZli-asfp-D78n-ozCvmF

7.扩容

vgextend VG_NAME DEVICE

lvextend -r -l +100%FREE /dev/mapper/centos-root

[root@kafka1 ~]# vgextend centos /dev/sda3
  Volume group "centos" successfully extended
[root@kafka1 ~]# df -h
Filesystem               Size  Used Avail Use% Mounted on
devtmpfs                 908M     0  908M   0% /dev
tmpfs                    920M     0  920M   0% /dev/shm
tmpfs                    920M  8.9M  911M   1% /run
tmpfs                    920M     0  920M   0% /sys/fs/cgroup
/dev/mapper/centos-root   14G  2.8G   11G  21% /
/dev/sda1               1014M  182M  833M  18% /boot
tmpfs                    184M     0  184M   0% /run/user/0
[root@kafka1 ~]# lvextend -r -l +100%FREE /dev/mapper/centos-root
  Size of logical volume centos/root changed from 13.39 GiB (3429 extents) to 27.39 GiB (7012 extents).
  Logical volume centos/root successfully resized.
meta-data=/dev/mapper/centos-root isize=512    agcount=4, agsize=877824 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=3511296, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 3511296 to 7180288
[root@kafka1 ~]# df -h
Filesystem               Size  Used Avail Use% Mounted on
devtmpfs                 908M     0  908M   0% /dev
tmpfs                    920M     0  920M   0% /dev/shm
tmpfs                    920M  8.9M  911M   1% /run
tmpfs                    920M     0  920M   0% /sys/fs/cgroup
/dev/mapper/centos-root   28G  2.8G   25G  11% /
/dev/sda1               1014M  182M  833M  18% /boot
tmpfs                    184M     0  184M   0% /run/user/0

扩容完成!

参考资料:

https://www.jianshu.com/p/537e8e8360af

https://www.programminghunter.com/article/2697297287/

https://echochio.pixnet.net/blog/post/44944759-esxi-%E7%9A%84-centos7-extend-hdd

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注