VMware下对Redhat/centos系统磁盘扩容

在创建虚拟机时只给了15G的存储,时间长了之后/空间就满了,这时不想再新建虚拟机就只能扩容了,下面就介绍如何为虚拟机扩磁盘。

查看当前磁盘使用情况,根空间马上就满了

[root@server1 ~]# df -h
Filesystem                         Size  Used Avail Use% Mounted on
/dev/mapper/rhel-root               13G   12G  1.3G  91% /
devtmpfs                           893M     0  893M   0% /dev
tmpfs                              910M     0  910M   0% /dev/shm
tmpfs                              910M   19M  892M   3% /run
tmpfs                              910M     0  910M   0% /sys/fs/cgroup
/dev/sr0                           3.7G  3.7G     0 100% /var/www/html/myyum
/dev/sda1                          497M  191M  306M  39% /boot
/dev/mapper/datastorage-datastore   74M  1.6M   68M   3% /mnt/measure
tmpfs                              182M  4.0K  182M   1% /run/user/42
tmpfs                              182M   24K  182M   1% /run/user/0

打开虚拟机设置
在这里插入图片描述
点击硬盘-扩展磁盘容量,输入需要扩展的磁盘容量
注意:扩展磁盘容量需要关闭当前虚拟机,并且当前虚拟机不能有快照

查看当前分区使用情况

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

/dev/sda1   *        2048     1026047      512000   83  Linux
/dev/sda2         1026048    31457279    15215616   8e  Linux LVM
/dev/sda3        31457280    62914559    15728640   83  Linux

/dev/sda3为刚才新添加的硬盘

使用fdisk /dev/sda进入菜单项,m是列出菜单,p是列出分区表,n是增加分区,w是保存并退出

[root@server1 ~]# fdisk /dev/sda3
The number of cylinders for this disk is set to 1958.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
   (e.g., DOS FDISK, OS/2 FDISK)
3、Command (m for help): p
Disk /dev/sda: 16.1 GB, 16106127360 bytes
255 heads, 63 sectors/track, 1958 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          13      104391   83  Linux
/dev/sda2              14        1305    10377990   8e  Linux LVM
4、Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
5、p
Partition number (1-4): 3
First cylinder (1306-1958, default 1306): +1306
Last cylinder or +size or +sizeM or +sizeK (1306-1958, default 1958): 
Value out of range.
Last cylinder or +size or +sizeM or +sizeK (1306-1958, default 1958): 
Using default value 1958
6、可以都选择默认
7、Command (m for help): w   保存修改

刷新磁盘,可以不用重启系统生效

[root@server1 ~]# partprobe 

将物理硬盘分区初始化为物理卷
[root@server1 ~]# pvcreate /dev/sda3

向卷组中添加物理卷来增加卷组的容量

[root@server1 ~]# vgextend rhel-root /dev/sda3

扩充磁盘空间

[root@server1 ~]# lvextend -L+29.5G /dev/mapper/rhel_root /dev/sda3

这里仅是扩大了逻辑卷,但文件系统并没有扩展

[root@server1 ~]# df -h
Filesystem                         Size  Used Avail Use% Mounted on
/dev/mapper/rhel-root               13G   12G  1.3G  91% /
devtmpfs                           893M     0  893M   0% /dev
tmpfs                              910M     0  910M   0% /dev/shm
tmpfs                              910M   19M  892M   3% /run
tmpfs                              910M     0  910M   0% /sys/fs/cgroup
/dev/sr0                           3.7G  3.7G     0 100% /var/www/html/myyum
/dev/sda1                          497M  191M  306M  39% /boot
/dev/mapper/datastorage-datastore   74M  1.6M   68M   3% /mnt/measure
tmpfs                              182M  4.0K  182M   1% /run/user/42
tmpfs                              182M   24K  182M   1% /run/user/0

扩展文件系统

[root@server1 ~]# resize2fs /dev/mapper/rhel-root 
resize2fs 1.42.9 (28-Dec-2013)
resize2fs: Bad magic number in super-block while trying to open /dev/mapper/rhel-root
Couldn't find valid filesystem superblock.

可以看到报错了,查了下原来是格式不对

重新扩展文件分区

[root@server1 ~]# xfs_growfs /dev/mapper/rhel-root 
meta-data=/dev/mapper/rhel-root  isize=256    agcount=9, agsize=849920 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=0        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=7306240, 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 

再次查看磁盘空间,发现已经扩展成功

[root@server1 ~]# df -h
Filesystem                         Size  Used Avail Use% Mounted on
/dev/mapper/rhel-root               28G   12G   17G  43% /
devtmpfs                           893M     0  893M   0% /dev
tmpfs                              910M     0  910M   0% /dev/shm
tmpfs                              910M   19M  892M   3% /run
tmpfs                              910M     0  910M   0% /sys/fs/cgroup
/dev/sr0                           3.7G  3.7G     0 100% /var/www/html/myyum
/dev/sda1                          497M  191M  306M  39% /boot
/dev/mapper/datastorage-datastore   74M  1.6M   68M   3% /mnt/measure
tmpfs                              182M  4.0K  182M   1% /run/user/42
tmpfs                              182M   24K  182M   1% /run/user/0

至此,虚拟机扩展磁盘空间大功告成!

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值