VMware ESXi 中的 CentOS 硬盘扩容

1. 在 vSphere Client 上直接扩大虚拟机的硬盘空间或者挂载一块新硬盘。

2. 查看当前硬盘空间情况:

[root@ucslab admin]# df -h
文件系统           容量  已用  可用 已用%% 挂载点
/dev/mapper/vg_ucslab-lv_root
                       50G  8.8G   38G  19% /
tmpfs                 7.8G   88K  7.8G   1% /dev/shm
/dev/sda1             485M   30M  430M   7% /boot
/dev/mapper/vg_ucslab-lv_home
                       26G  616M   24G   3% /home

3. 创建新分区并调整分区类型:

[root@ucslab admin]# fdisk /dev/sda

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): p (显示当前分区情况)

Disk /dev/sda: 536.9 GB, 536870912000 bytes
255 heads, 63 sectors/track, 65270 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: 0x000e362d

   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       10444    83373056   8e  Linux LVM

Command (m for help): n (创建新的主分区)
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 3
First cylinder (10444-65270, default 10444):
Using default value 10444
Last cylinder, +cylinders or +size{K,M,G} (10444-65270, default 65270):
Using default value 65270

Command (m for help): p (显示当前分区情况)

Disk /dev/sda: 536.9 GB, 536870912000 bytes
255 heads, 63 sectors/track, 65270 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: 0x000e362d

   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       10444    83373056   8e  Linux LVM
/dev/sda3           10444       65270   440395195   83  Linux

Command (m for help): t  (修改分区类型为 Linux LVM, 8e)
Partition number (1-4): 3
Hex code (type L to list codes): 8e
Changed system type of partition 3 to 8e (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: 设备或资源忙.
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.

建议重启,或使用partprobe刷新硬盘情况。

4. 查看修改后的分区情况:

[root@ucslab admin]# fdisk -l

Disk /dev/sda: 536.9 GB, 536870912000 bytes
255 heads, 63 sectors/track, 65270 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: 0x000e362d

   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       10444    83373056   8e  Linux LVM
/dev/sda3           10444       65270   440395195   8e  Linux LVM

Disk /dev/dm-0: 53.7 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 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/dm-0 doesn't contain a valid partition table

Disk /dev/dm-1: 4227 MB, 4227858432 bytes
255 heads, 63 sectors/track, 514 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/dm-1 doesn't contain a valid partition table

Disk /dev/dm-2: 27.5 GB, 27455913984 bytes
255 heads, 63 sectors/track, 3337 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/dm-2 doesn't contain a valid partition table

5. 初始化物理卷:

[root@ucslab admin]# pvcreate /dev/sda3
  Physical volume "/dev/sda3" successfully created

6. 添加到卷组:

[root@ucslab admin]# lvm
lvm> vgdisplay
  --- Volume group ---
  VG Name               vg_ucslab (卷组名称)
  System ID            
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  4
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                3
  Open LV               3
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               79.51 GiB
  PE Size               4.00 MiB
  Total PE              20354
  Alloc PE / Size       20354 / 79.51 GiB
  Free  PE / Size       0 / 0  
  VG UUID               1xZKPs-dWqe-Y8Ca-x885-Czo7-wCA8-gMd5u2
  
lvm> vgextend /dev/vg_ucslab /dev/sda3
  Volume group "vg_ucslab" successfully extended

lvm> vgdisplay
  --- Volume group ---
  VG Name               vg_ucslab
  System ID            
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  5
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                3
  Open LV               3
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               499.50 GiB
  PE Size               4.00 MiB
  Total PE              127872
  Alloc PE / Size       20354 / 79.51 GiB
  Free  PE / Size       107518 / 419.99 GiB
  VG UUID               1xZKPs-dWqe-Y8Ca-x885-Czo7-wCA8-gMd5u2
  
7. 显示逻辑卷情况,并扩展逻辑卷大小,每个逻辑卷扩展200G:

lvm> lvdisplay
  --- Logical volume ---
  LV Name                /dev/vg_ucslab/lv_root
  VG Name                vg_ucslab
  LV UUID                ekSWAJ-Yv5j-E9br-nmyF-jNtV-PXGb-LpxdDt
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                50.00 GiB
  Current LE             12800
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0
  
  --- Logical volume ---
  LV Name                /dev/vg_ucslab/lv_home
  VG Name                vg_ucslab
  LV UUID                cNeSMR-eddd-noQx-nMpq-pf1i-g3Qu-DEEt2M
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                25.57 GiB
  Current LE             6546
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:2
  
  --- Logical volume ---
  LV Name                /dev/vg_ucslab/lv_swap
  VG Name                vg_ucslab
  LV UUID                DxN0XW-2g7D-ffle-zYme-yH4O-Ntbv-llAxPY
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                3.94 GiB
  Current LE             1008
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1

lvm> lvextend -L +200G /dev/vg_ucslab/lv_root
  Extending logical volume lv_root to 250.00 GiB
  Logical volume lv_root successfully resized
lvm> lvextend -L +200G /dev/vg_ucslab/lv_home
  Extending logical volume lv_home to 225.57 GiB
  Logical volume lv_home successfully resized
lvm> quit
  Exiting.

8. 修改文件系统实现扩容: 

[root@ucslab admin]# resize2fs -p /dev/vg_ucslab/lv_root
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/vg_ucslab/lv_root is mounted on /; on-line resizing required
old desc_blocks = 4, new_desc_blocks = 16
Performing an on-line resize of /dev/vg_ucslab/lv_root to 65536000 (4k) blocks.
The filesystem on /dev/vg_ucslab/lv_root is now 65536000 blocks long.

[root@ucslab admin]# resize2fs -p /dev/vg_ucslab/lv_home
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/vg_ucslab/lv_home is mounted on /home; on-line resizing required
old desc_blocks = 2, new_desc_blocks = 15
Performing an on-line resize of /dev/vg_ucslab/lv_home to 59131904 (4k) blocks.
The filesystem on /dev/vg_ucslab/lv_home is now 59131904 blocks long.

另外,可以使用e2fsck -f 命令验证。

9. 扩容完成:

[admin@ucslab ~]$ df -h
文件系统           容量  已用  可用 已用%% 挂载点
/dev/mapper/vg_ucslab-lv_root
                      247G  8.8G  225G   4% /
tmpfs                 7.8G   88K  7.8G   1% /dev/shm
/dev/sda1             485M   30M  430M   7% /boot
/dev/mapper/vg_ucslab-lv_home
                      223G  632M  211G   1% /home
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值