Vmware私有云虚拟机(CentOS 6.5 OS)之根分区扩容
注:适用于未使用lvm管理的分区,目前仅在CentOS 6.5 上操作,其他系统尚未测试,请谨慎操作
一、查看当前分区状况
[root@disk-test ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 26G 2.3G 22G 10% /
tmpfs 1.9G 0 1.9G 0% /dev/shm
/dev/sda1 194M 34M 151M 19% /boot
---------------------------------------------------------------------------
二、控制台调增虚拟机磁盘
关闭系统,在控制台调增虚拟机磁盘大小为50G,重启系统
[root@disk-test ~]# fdisk -l
Disk /dev/sda: 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: 0x000cea7e
Device Boot Start End Blocks Id System
/dev/sda1 * 1 26 204800 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 26 548 4194304 82 Linux swap / Solaris
Partition 2 does not end on cylinder boundary.
/dev/sda3 548 3917 27057152 83 Linux #注意这里起始cylinder 是548,起始cylinder 绝对不可以改,这样会破坏原分区的数据。
---------------------------------------------------------------------
三、扩展根分区/dev/sda3
[root@sjsa-disk-test ~]# 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): m
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
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)
Command (m for help): p
Disk /dev/sda: 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: 0x000cea7e
Device Boot Start End Blocks Id System
/dev/sda1 * 1 26 204800 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 26 548 4194304 82 Linux swap / Solaris
Partition 2 does not end on cylinder boundary.
/dev/sda3 548 3917 27057152 83 Linux
Command (m for help): d
Partition number (1-4): 3 #根/分区是多少就输入几,这里是/dev/sda3
Command (m for help): p
Disk /dev/sda: 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: 0x000cea7e
Device Boot Start End Blocks Id System
/dev/sda1 * 1 26 204800 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 26 548 4194304 82 Linux swap / Solaris
Partition 2 does not end on cylinder boundary.
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 3 #之前是多少,这里还输入多少
First cylinder (548-6527, default 548):
Using default value 548
Last cylinder, +cylinders or +size{K,M,G} (548-6527, default 6527): #由之前3917,扩为6527
Using default value 6527
Command (m for help): p
Disk /dev/sda: 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: 0x000cea7e
Device Boot Start End Blocks Id System
/dev/sda1 * 1 26 204800 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 26 548 4194304 82 Linux swap / Solaris
Partition 2 does not end on cylinder boundary.
/dev/sda3 548 6527 48027999+ 83 Linux #变成了6527
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: Device or resource busy.
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.
三、重启系统,完成根分区扩充
执行如下命令,重启系统
[root@sjsa-disk-test ~]# reboot
执行如下命令,完成根分区扩充
[root@sjsa-disk-test ~]# resize2fs /dev/sda3
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/sda3 is mounted on /; on-line resizing required
old desc_blocks = 2, new_desc_blocks = 3
Performing an on-line resize of /dev/sda3 to 12006999 (4k) blocks.
The filesystem on /dev/sda3 is now 12006999 blocks long.
四、验证
查看当前磁盘状态
[root@sjsa-disk-test ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 46G 2.3G 41G 6% /
tmpfs 1.9G 0 1.9G 0% /dev/shm
/dev/sda1 194M 34M 151M 19% /boot
如上,完成对根分区的扩充