openstack 虚机硬盘扩容

一 摘要

二 环境信息

三 虚机硬盘扩容

(一)虚机硬盘扩容

3.1.1 查看当前分区情况

[root@host-10-3-178-54 ~]# lsblk
NAME        MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
vda         252:0    0  500G  0 disk
├─vda1      252:1    0    1G  0 part /boot
└─vda2      252:2    0  199G  0 part
  ├─cl-root 253:0    0  167G  0 lvm  /
  ├─cl-swap 253:1    0    2G  0 lvm  [SWAP]
  └─cl-home 253:2    0   30G  0 lvm  /home
[root@host-10-3-178-54 ~]#

3.1.2 分区剩余区间

[root@host-10-3-178-54 ~]# fdisk /dev/vda
欢迎使用 fdisk (util-linux 2.23.2)。

更改将停留在内存中,直到您决定将更改写入磁盘。
使用写入命令前请三思。


命令(输入 m 获取帮助):n
Partition type:
   p   primary (2 primary, 0 extended, 2 free)
   e   extended
Select (default p): p
分区号 (3,4,默认 3):
起始 扇区 (419430400-1048575999,默认为 419430400):
将使用默认值 419430400
Last 扇区, +扇区 or +size{K,M,G} (419430400-1048575999,默认为 1048575999):
将使用默认值 1048575999
分区 3 已设置为 Linux 类型,大小设为 300 GiB

命令(输入 m 获取帮助):w
The partition table has been altered!

Calling ioctl() to re-read partition table.

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)
正在同步磁盘。
[root@host-10-3-178-54 ~]#

[root@host-10-3-178-54 ~]# lsblk
NAME        MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
vda         252:0    0  500G  0 disk
├─vda1      252:1    0    1G  0 part /boot
├─vda2      252:2    0  199G  0 part
│ ├─cl-root 253:0    0  167G  0 lvm  /
│ ├─cl-swap 253:1    0    2G  0 lvm  [SWAP]
│ └─cl-home 253:2    0   30G  0 lvm  /home
└─vda3      252:3    0  300G  0 part
[root@host-10-3-178-54 ~]#

3.1.3 创建pv

/dev/vda3 这个参数要与上面保持一致

[root@host-10-3-178-54 ~]# pvcreate /dev/vda3
  Physical volume "/dev/vda3" successfully created.
[root@host-10-3-178-54 ~]#

3.1.4 添加物理卷

[root@host-10-3-178-54 ~]# pvcreate /dev/vda3
  Physical volume "/dev/vda3" successfully created.
[root@host-10-3-178-54 ~]# vgscan
  Reading volume groups from cache.
  Found volume group "cl" using metadata type lvm2

## 注意 cl,下面会用到,不同的系统 参数可能会不一样

[root@host-10-3-178-54 ~]# vgextend cl /dev/vda3
  Volume group "cl" successfully extended
[root@host-10-3-178-54 ~]#

3.1.5 扩展物理卷

[root@host-10-3-178-54 ~]# df -h
文件系统             容量  已用  可用 已用% 挂载点
/dev/mapper/cl-root  167G  3.5G  164G    3% /
devtmpfs              16G     0   16G    0% /dev
tmpfs                 16G   84K   16G    1% /dev/shm
tmpfs                 16G  8.8M   16G    1% /run
tmpfs                 16G     0   16G    0% /sys/fs/cgroup
/dev/vda1           1014M  173M  842M   17% /boot
/dev/mapper/cl-home   30G   37M   30G    1% /home
tmpfs                3.2G   16K  3.2G    1% /run/user/42
tmpfs                3.2G     0  3.2G    0% /run/user/0

### /dev/mapper/cl-root  扩展到该目录

[root@host-10-3-178-54 ~]# lvextend -l +100%FREE /dev/mapper/cl-root
  Size of logical volume cl/root changed from 166.99 GiB (42750 extents) to 466.99 GiB (119550 extents).
  Logical volume cl/root successfully resized.
[root@host-10-3-178-54 ~]# lsblk
NAME        MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
vda         252:0    0  500G  0 disk
├─vda1      252:1    0    1G  0 part /boot
├─vda2      252:2    0  199G  0 part
│ ├─cl-root 253:0    0  467G  0 lvm  /
│ ├─cl-swap 253:1    0    2G  0 lvm  [SWAP]
│ └─cl-home 253:2    0   30G  0 lvm  /home
└─vda3      252:3    0  300G  0 part
  └─cl-root 253:0    0  467G  0 lvm  /
[root@host-10-3-178-54 ~]#

3.1.6 xfs 在线扩容

[root@host-10-3-178-54 ~]# xfs_growfs /dev/mapper/cl-root
meta-data=/dev/mapper/cl-root    isize=512    agcount=4, agsize=10944000 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=43776000, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=21375, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 43776000 to 122419200
[root@host-10-3-178-54 ~]# df -h
文件系统             容量  已用  可用 已用% 挂载点
/dev/mapper/cl-root  467G  3.5G  464G    1% /
devtmpfs              16G     0   16G    0% /dev
tmpfs                 16G   84K   16G    1% /dev/shm
tmpfs                 16G  8.8M   16G    1% /run
tmpfs                 16G     0   16G    0% /sys/fs/cgroup
/dev/vda1           1014M  173M  842M   17% /boot
/dev/mapper/cl-home   30G   37M   30G    1% /home
tmpfs                3.2G   16K  3.2G    1% /run/user/42
tmpfs                3.2G     0  3.2G    0% /run/user/0
[root@host-10-3-178-54 ~]#

posted on 2020-12-09 17:27  weiwei2021  阅读(700)  评论(0)    收藏  举报