VMware Linux(Centos)虚拟机扩容根目录磁盘空间

https://blog.csdn.net/m0_64206944/article/details/131453844?spm=1001.2014.3001.5506

上述链接为主,融合下面文章中lvextend扩容操作错误处理部分

1:编辑虚拟机设置,点击[硬盘],选择[扩展] 填写大小:

image

image

点击扩展后VMware提示磁盘已经成功扩展。

image

完成扩展后,需从客户机操作系统内部对磁盘【重新分区】和【扩展文件系统】

2:启动虚拟机操作系统Centos,查看磁盘情况:

1

# fdisk -l

显示如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

Disk /dev/sda: 32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00094582

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          64      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              64        2611    20458496   8e  Linux LVM

Disk /dev/mapper/vg_rxf-lv_root: 18.9 GB, 18865979392 bytes
255 heads, 63 sectors/track, 2293 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Disk /dev/mapper/vg_rxf-lv_swap: 2080 MB, 2080374784 bytes
255 heads, 63 sectors/track, 252 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

可以看见分区情况如下:

1
2
3
4

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          64      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              64        2611    20458496   8e  Linux LVM

3:创建分区sda3:
输入指令

1

# fdisk /dev/sda

根据命令提示创建分区:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): n  #输入n表示创建新分区
Command action
   e   extended
   p   primary partition (1-4)
p       #输入p
Partition number (1-4): 3 #输入3,表示sda3,前面已经有2个了
First cylinder (2611-3916, default 2611): #回车,默认值
Using default value 2611
Last cylinder, +cylinders or +size{K,M,G} (2611-3916, default 3916):   #回车,默认值
Using default value 3916

Command (m for help): w #输入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)
Syncing disks.

再查看分区情况

1

# fdisk -l

情况如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26

Disk /dev/sda: 32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00094582

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          64      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              64        2611    20458496   8e  Linux LVM
/dev/sda3            2611        3916    10483750   83  Linux

Disk /dev/mapper/vg_rxf-lv_root: 18.9 GB, 18865979392 bytes
255 heads, 63 sectors/track, 2293 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Disk /dev/mapper/vg_rxf-lv_swap: 2080 MB, 2080374784 bytes
255 heads, 63 sectors/track, 252 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

可以看见现在的分区情况如下:

1
2
3
4
5

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          64      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              64        2611    20458496   8e  Linux LVM
/dev/sda3            2611        3916    10483750   83  Linux

这时分区已经变成3个了,但是还没有挂载,还不能用。
4:重启操作系统

1

# reboot

5:格式化新分区ext3

1

# mkfs -t ext3 /dev/sda3

显示情况如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

mke2fs 1.41.12 (17-May-2010)
文件系统标签=
操作系统:Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
655360 inodes, 2620937 blocks
131046 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=2684354560
80 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
    32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632

正在写入inode表: 完成                            
Creating journal (32768 blocks): 完成
Writing superblocks and filesystem accounting information: 完成

This filesystem will be automatically checked every 29 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

6:将物理硬盘分区初始化为物理卷,以便LVM使用,输入指令

1

# lvs

显示如下:

1
2
3

  LV      VG     Attr       LSize  Pool Origin Data%  Move Log Cpy%Sync Convert
  lv_root vg_rxf -wi-ao---- 17.57g                                            
  lv_swap vg_rxf -wi-ao----  1.94g

输入指令:

1

# pvcreate /dev/sda3

显示如下:

1

  Physical volume "/dev/sda3" successfully created

7:向卷组中添加物理卷来增加容量。
输入df -h 查看lvm组名

1

# df -h

1
2
3
4

Filesystem                  Size  Used Avail Use% Mounted on
/dev/mapper/vg_rxf-lv_root   18G   18G  112M 100% /
tmpfs                       931M  4.0K  931M   1% /dev/shm
/dev/sda1                   485M   35M  425M   8% /boot

其中vg_rxf为根所在组名.
输入指令,增加卷组的容量

1

# vgextend vg_rxf /dev/sda3

1

  Volume group "vg_rxf" successfully extended

8:查看可以扩展的空间大小:

1

vgdisplay

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

  --- Volume group ---
  VG Name               vg_rxf
  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               29.50 GiB
  PE Size               4.00 MiB
  Total PE              7553
  Alloc PE / Size       4994 / 19.51 GiB
  Free  PE / Size       2559 / 10.00 GiB
  VG UUID               KFyuD1-cj5n-cukx-z1Zf-Gg2T-IQLT-v6BD4N

Free PE / Size 就是可以提供分配的自由空间,最多10.00 GiB,在扩展时输入小于该值
9:扩充磁盘空间

1

# lvextend -L+9G /dev/mapper/vg_rxf-lv_root /dev/sda3

1
2

  Extending logical volume lv_root to 26.57 GiB
  Logical volume lv_root successfully resized

10:使用e2fsck指令查看检测文件系统错误

1

# e2fsck -a /dev/mapper/vg_rxf-lv_root

1
2

/dev/mapper/vg_rxf-lv_root is mounted.
e2fsck: 无法继续, 中止.

11:使用resize2fs指令来增大或者搜索未加载的"ext2/ext3"文件系统的大小(此处可能出现问题,没办法增大扩容空间)

1

resize2fs /dev/mapper/vg_rxf-lv_root

1
2
3
4

Filesystem at /dev/mapper/vg_rxf-lv_root is mounted on /; on-line resizing required
old desc_blocks = 2, new_desc_blocks = 2
Performing an on-line resize of /dev/mapper/vg_rxf-lv_root to 6965248 (4k) blocks.
The filesystem on /dev/mapper/vg_rxf-lv_root is now 6965248 blocks long.

11-1(如果11步出现问题,因为我的centos7的某些分区用的是xfs的文件系统(使用df -T查看即可知道)

1
2
3
4
5
6
7
8
9
10

[root@vnode1 ~]# df -T
文件系统                           类型          1K-块        已用        可用          已用%  挂载点
/dev/mapper/centos-root   xfs           37173520 5574340  31599180  15%      /
devtmpfs                      devtmpfs  3987400   0              3987400    0%       /dev
tmpfs                                 tmpfs        3997856   0              3997856    0%      /dev/shm
tmpfs                                 tmpfs        3997856   8628        3989228     1%     /run
tmpfs                                 tmpfs        3997856   0               3997856     0%    /sys/fs/cgroup
/dev/sda1                          xfs            508588      127152    381436       26%  /boot
tmpfs                                tmpfs         799572      0              799572       0%   run/user/0
[root@vnode1 ~]#

将resize2fs替换为xfs_growfs,重新执行一遍即可,如下:

1

[root@vnode1 ~]# xfs_growfs /dev/mapper/vg_rxf-lv_root

12:查看扩展空间后的结果:

1

# df -h

1
2
3
4

Filesystem                  Size  Used Avail Use% Mounted on
/dev/mapper/vg_rxf-lv_root   27G   18G  8.9G  66% /
tmpfs                       931M  4.0K  931M   1% /dev/shm
/dev/sda1                   485M   35M  425M   8% /boot

可以看见,大功告成。

转载:https://www.jianshu.com/p/578816f4e9b8
备注:转载的地方有不对的地方已经在此文进行了修改,看这一篇就够了

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值