VMWare虚拟机扩展磁盘空间(扩充root根目录空间)

1. 扩展虚拟机磁盘空间

Vm虚拟机下Linux扩展原有磁盘空间,10G
在这里插入图片描述
10G的基础上不能满足需求,只好进行磁盘扩展。
在这里插入图片描述
调整到合适的磁盘空间
在这里插入图片描述
在这里插入图片描述
需注意以下几点: linux只能扩展磁盘容量而不能减小, 所填写的容量为总容量,即包含已分区的磁盘。

2.查看、创建系统分区

  1. 启动虚假机,查看磁盘分区
[root@node1 ~]# fdisk -l

在这里插入图片描述
总磁盘大小32.2GB,其中磁盘分了sda1,sda2两个分区。Linux LVM为虚拟机分区约有9GB磁盘空间。

  1. 创建新分区
[root@node1 ~]# fdisk /dev/sda
#输入m查看帮助文档
Command (m for help): m
Command action
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   g   create a new empty GPT partition table
   G   create an IRIX (SGI) partition table
   l   list known partition types
   m   print this menu
   n   add a new partition #创建新分区
   o   create a new empty DOS partition table
   p   print the partition table
   q   quit without saving changes
   s   create a new empty Sun disklabel
   t   change a partition's system id
   u   change display/entry units
   v   verify the partition table
   w   write table to disk and exit
   x   extra functionality (experts only)

3.执行分区创建

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):  #由前面已有2个分区,所有从3开始
First sector (20971520-62914559, default 20971520): #一路回车即可
Using default value 20971520
Last sector, +sectors or +size{K,M,G} (20971520-62914559, default 62914559): 
Using default value 62914559
Partition 3 of type Linux and of size 20 GiB is set

Command (m for help): w #保存退出
The partition table has been altered!

4.重新查看分区

我们的新建分区/dev/sda3

[root@node1 ~]# 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: 0x00009cb6

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200    20971519     9436160   8e  Linux LVM
#sda3为新创建的分区
/dev/sda3        20971520    62914559    20971520   83  Linux

Disk /dev/mapper/centos-root: 8585 MB, 8585740288 bytes, 16769024 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: 1073 MB, 1073741824 bytes, 2097152 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.查看文件系统格式、分区格式化

#查看文件系统格式
 df  -T -h
#分区格式化
mkfs.xfs /dev/sda3  #格式化为xfs格式
#进入lvm管理
lvm
lvm> pvcreate /dev/sda3  #这是初始化刚才的分区3
WARNING: ext4 signature detected on /dev/sda3 at offset 1080. Wipe it? [y/n]: y
  Wiping ext4 signature on /dev/sda3.
  Physical volume "/dev/sda3" successfully created.
lvm> vgdisplay -v #卷和卷组的命令可以通过 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               <9.00 GiB
  PE Size               4.00 MiB
  Total PE              2303
  Alloc PE / Size       2303 / <9.00 GiB
  Free  PE / Size       0 / 0   
  VG UUID               zy2221-18Zz-hNix-Xa40-fn2S-ymfs-QfifRi
   
  --- Logical volume ---
  LV Path                /dev/centos/swap
  LV Name                swap
  VG Name                centos
  LV UUID                ypW1dW-fdTc-qCso-7Wck-L1gH-hsOp-v4ZBey
  LV Write Access        read/write
  LV Creation host, time localhost, 2021-06-25 13:10:00 +0800
  LV Status              available
  # open                 2
  LV Size                1.00 GiB
  Current LE             256
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:1
   
  --- Logical volume ---
  LV Path                /dev/centos/root
  LV Name                root
  VG Name                centos
  LV UUID                2IDcZo-HeDY-VzTg-FIAP-YhvQ-qU0K-cxyuBr
  LV Write Access        read/write
  LV Creation host, time localhost, 2021-06-25 13:10:00 +0800
  LV Status              available
  # open                 1
  LV Size                <8.00 GiB
  Current LE             2047
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0
   
  --- Physical volumes ---
  PV Name               /dev/sda2     
  PV UUID               kb7rhp-Lcow-6z3W-RBYx-fJxo-pHUc-cLxYTN
  PV Status             allocatable
  Total PE / Free PE    2303 / 0

lvm> vgextend centos /dev/sda3 #将初始化过的分区加入到虚拟卷组centos
  Volume group "centos" successfully extended

可以查看到新加入的物理卷sda3
在这里插入图片描述
通过vgdisplay再次查看,可以发现Volume group中多了Free PE / Size 5119 / <20.00 GiB一行记录

lvm> vgdisplay -v
  --- 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               28.99 GiB
  PE Size               4.00 MiB
  Total PE              7422
  Alloc PE / Size       2303 / <9.00 GiB
  Free  PE / Size       5119 / <20.00 GiB
  VG UUID               zy2221-18Zz-hNix-Xa40-fn2S-ymfs-QfifRi
   
  --- Logical volume ---
  LV Path                /dev/centos/swap
  LV Name                swap
  VG Name                centos
  LV UUID                ypW1dW-fdTc-qCso-7Wck-L1gH-hsOp-v4ZBey
  LV Write Access        read/write
  LV Creation host, time localhost, 2021-06-25 13:10:00 +0800
  LV Status              available
  # open                 2
  LV Size                1.00 GiB
  Current LE             256
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:1
   
  --- Logical volume ---
  LV Path                /dev/centos/root
  LV Name                root
  VG Name                centos
  LV UUID                2IDcZo-HeDY-VzTg-FIAP-YhvQ-qU0K-cxyuBr
  LV Write Access        read/write
  LV Creation host, time localhost, 2021-06-25 13:10:00 +0800
  LV Status              available
  # open                 1
  LV Size                <8.00 GiB
  Current LE             2047
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0
   
  --- Physical volumes ---
  PV Name               /dev/sda2     
  PV UUID               kb7rhp-Lcow-6z3W-RBYx-fJxo-pHUc-cLxYTN
  PV Status             allocatable
  Total PE / Free PE    2303 / 0
   
  PV Name               /dev/sda3     
  PV UUID               V708hY-OO5p-IH3v-ZRlU-Torj-tXOC-ERvLr1
  PV Status             allocatable
  Total PE / Free PE    5119 / 5119
#/dev/mapper/centos-root 为根路径挂载点
lvm> lvextend -l+5119 /dev/mapper/centos-root ##扩展已有卷的容量(5119 是通过vgdisplay查看Free  PE / Size的大小)
  Size of logical volume centos/root changed from <8.00 GiB (2047 extents) to 27.99 GiB (7166 extents).
  Logical volume centos/root successfully resized.
lvm> pvdisplay
  --- Physical volume ---
  PV Name               /dev/sda2
  VG Name               centos
  PV Size               <9.00 GiB / not usable 3.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              2303
  Free PE               0
  Allocated PE          2303
  PV UUID               kb7rhp-Lcow-6z3W-RBYx-fJxo-pHUc-cLxYTN
   
  --- Physical volume ---
  PV Name               /dev/sda3
  VG Name               centos
  PV Size               20.00 GiB / not usable 4.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              5119
  Free PE               0
  Allocated PE          5119
  PV UUID               V708hY-OO5p-IH3v-ZRlU-Torj-tXOC-ERvLr1
lvm>quit  #退出

3.文件系统的扩容

以上只是做成了卷扩容,接下来做文件系统的真正扩容

#执行df -h时根目录的挂载点
df -h 

在这里插入图片描述
centos7执行执行扩容

xfs_growfs /dev/mapper/centos-root

在这里插入图片描述
再次查看磁盘使用情况

df -h 

在这里插入图片描述
可以看见根目录下的磁盘空间已经扩展为28G了

评论 19
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值