vmware虚拟机(centos)扩展ext4分区

/dev/sdc,只有一个sdc1分区,

[root@centos68 /]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_centos68-lv_root
63G   20G   40G  34% /
tmpfs                 2.0G     0  2.0G   0% /dev/shm
/dev/sda1             477M   40M  412M   9% /boot
/dev/sr0              3.7G  3.7G     0 100% /mnt
glusterfs1:da_gfs_1    28T  1.2G   28T   1% /opt/gfs_test
/dev/sdc1              16G  144M   15G   1% /data

在vcenter中将虚拟机的硬盘修改为20G

echo 1 > /sys/class/scsi_disk/2\:0\:2\:0/device/rescan 重扫磁盘

fdisk识别为20G

扩展流程:卸载分区、删除分区表、重建分区表、resize2fs sdc1、挂载sdc1,扩容成功,如下:

[root@centos68 ~]# fdisk /dev/sdc

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/sdc: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 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: 0xb32885bf

Device Boot      Start         End      Blocks   Id  System
/dev/sdc1               1        2088    16771828+  83  Linux

Command (m for help): d
Selected partition 1

Command (m for help): p

Disk /dev/sdc: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 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: 0xb32885bf

Device Boot      Start         End      Blocks   Id  System

Command (m for help): n
Command action
e   extended
p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-2610, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610):
Using default value 2610

Command (m for help): p

Disk /dev/sdc: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 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: 0xb32885bf

Device Boot      Start         End      Blocks   Id  System
/dev/sdc1               1        2610    20964793+  83  Linux

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[root@centos68 ~]# resize2fs /dev/sdc
sdc   sdc1
[root@centos68 ~]# resize2fs /dev/sdc1
resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on /dev/sdc1 to 5241198 (4k) blocks.
The filesystem on /dev/sdc1 is now 5241198 blocks long.

 

容量已更新:

[root@centos68 ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_centos68-lv_root
63G   20G   40G  34% /
tmpfs                 2.0G     0  2.0G   0% /dev/shm
/dev/sda1             477M   40M  412M   9% /boot
/dev/sr0              3.7G  3.7G     0 100% /mnt
glusterfs1:da_gfs_1    28T  1.2G   28T   1% /opt/gfs_test
/dev/sdc1              20G  145M   19G   1% /data