扩展虚拟机磁盘分区

本文是扩展虚拟机 根目录(/ )磁盘空间。

操作系统是CentOS7

1、首先使用 fdisk  新建一个磁盘分区,然后重启虚拟机.

[root@s201 ~]$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): n
Partition type:
   p   primary (2 primary, 0 extended, 2 free)
   e   extended
Select (default p): p
Partition number (3,4, default 3): 3
First sector (41943040-73400319, default 41943040): 
Using default value 41943040
Last sector, +sectors or +size{K,M,G} (41943040-73400319, default 73400319): 
Using default value 73400319
Partition 3 of type Linux and of size 15 GiB is set

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): 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.

 

[root@s201 ~]$ls /dev/sd*
/dev/sda  /dev/sda1  /dev/sda2  /dev/sda3

2:创建pv

[root@s201 ~]$pvcreate /dev/sda3
  Physical volume "/dev/sda3" successfully created.
You have new mail in /var/spool/mail/root

4:把pv加入vg中,相当于扩充vg的大小

   先使用vgs查看vg组

[root@s201 ~]$vgs
  VG     #PV #LV #SN Attr   VSize   VFree 
  centos   1   2   0 wz--n- <19.51g 40.00m

 5、扩展vg,使用vgextend命令

[root@s201 ~]$ vgextend centos /dev/sda3
  Volume group "centos" successfully extended
[root@s201 ~]$vgs
  VG     #PV #LV #SN Attr   VSize  VFree  
  centos   2   2   0 wz--n- 44.50g <25.04g

6、扩展lv

[root@s201 ~]$lvextend -L +25G /dev/mapper/centos-root
  Size of logical volume centos/root changed from <17.47 GiB (4472 extents) to <42.47 GiB (10872 extents).
  Logical volume centos/root successfully resized.

7: 命令使系统重新读取大小

[root@s201 ~]$xfs_growfs /dev/mapper/centos-root
meta-data=/dev/mapper/centos-root isize=256    agcount=4, agsize=1144832 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=0        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=4579328, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=0
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 4579328 to 11132928

8、df -h 重新查看

[root@s201 ~]$df -h
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root   43G  8.0G   35G  19% /
devtmpfs                 475M     0  475M   0% /dev
tmpfs                    492M     0  492M   0% /dev/shm
tmpfs                    492M  7.8M  484M   2% /run
tmpfs                    492M     0  492M   0% /sys/fs/cgroup
/dev/sda1                497M  177M  321M  36% /boot
tmpfs                     99M     0   99M   0% /run/user/0

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值