在给客户部署Linux虚拟机时,我一般都会单独做出一个分区来存储客户的所有数据,并取名为data。/data分区的默认大小为35G,随着时间的发展,有的客户提出扩大/data分区的需求。下面是我在ESX4.0上的实施步骤:
注:在生产环境中一定要先做好备份再做操作!
1)关掉Linux虚拟机,运行vmkfstools命令扩展vmdk文件。原大小为50G,现在扩展为65G。
vmkfstools -X 65G CentOS53.vmdk
2)开启Linux虚拟机,可以通过以下命令可以查看新增的可用空间。
[root@CentOS53 ~]# parted
GNU Parted 1.8.1
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print free
Model: VMware Virtual disk (scsi)
Disk /dev/sda: 69.8GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Number Start End SizeType File system Flags
1 32.3kB 107MB 107MB primary ext3 boot
2 107MB 4401MB 4294MB primary ext3
3 4401MB 6547MB 2147MB primary linux-swap
4 6547MB 53.7GB 47.1GB extended
5 6547MB 8694MB 2147MB logical ext3
6 8694MB 10.8GB 2147MB logical ext3
7 10.8GB 11.9GB 1077MB logical ext3
8 11.9GB 13.0GB 1077MB logical ext3
9 13.0GB 53.7GB 40.7GB logical ext3
53.7GB 69.8GB 16.1GBFree Space
3)运行disk /dev/sda后输入P查看分区结果如下,并记录下来(/dev/sda9加载在/data分区上)。可见总共有8485个cylinder,但最后一个分区只是到6527就结束了。这说明后面还有硬盘空间。
Disk /dev/sda: 69.7 GB, 69793218560 bytes
255 heads, 63 sectors/track, 8485 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 535 4192965 83 Linux
/dev/sda3 536 796 2096482+ 82 Linux swap / Solaris
/dev/sda4 797652746034257+ 5 Extended
/dev/sda5 7971057 2096451 83 Linux
/dev/sda610581318 2096451 83 Linux
/dev/sda713191449 1052226 83 Linux
/dev/sda814501580 1052226 83 Linux
/dev/sda91581652739736746 83 Linux
4)输入d删除扩展分区/dev/sda4,这样所有的逻辑分区就从分区表中消失了(不要害怕,呵呵)。
5)输入n创建新的扩展分区,并创建原来(/dev/sda9除外)所有的逻辑分区并保持原来的起始、结束cylinder地址不变。/dev/sda9的起始地址不变,结束地址改为8485。新的分区表如下。确认无误后输入w已保存生效。
Command (m for help): p
Disk /dev/sda: 69.7 GB, 69793218560 bytes
255 heads, 63 sectors/track, 8485 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 535 4192965 83 Linux
/dev/sda3 536 796 2096482+ 82 Linux swap / Solaris
/dev/sda4 797848561761892+ 5 Extended
/dev/sda5 7971057 2096451 83 Linux
/dev/sda610581318 2096451 83 Linux
/dev/sda713191449 1052226 83 Linux
/dev/sda814501580 1052226 83 Linux
/dev/sda91581848555464381 83 Linux
6)查看改动后的分区大小。到目前为止,/data分区大小仍未改变。
[root@CentOS53 ~]# df -h
FilesystemSize Used Avail Use% Mounted on
/dev/sda8 996M 235M 710M 25% /
/dev/sda9 37G 177M 35G 1% /data
/dev/sda7 996M 34M 911M 4% /home
/dev/sda6 2.0G 76M 1.8G 5% /var
/dev/sda2 3.9G 1.4G 2.4G 38% /usr
/dev/sda5 2.0G 36M 1.9G 2% /usr/local
/dev/sda1 99M 17M 78M 18% /boot
tmpfs 506M 0 506M 0% /dev/shm
7)运行resize2fs /dev/sda9已扩展/data分区。(在2.6.X内核里无需先umount)
[root@CentOS53 ~]# resize2fs /dev/sda9
resize2fs 1.39 (29-May-2006)
Filesystem at /dev/sda9 is mounted on /apps; on-line resizing required
Performing an on-line resize of /dev/sda9 to 13866095 (4k) blocks.
The filesystem on /dev/sda9 is now 13866095 blocks long.
8)再次查看分区大小。成功,哦耶!
[root@CentOS53 ~]# df -h
FilesystemSize Used Avail Use% Mounted on
/dev/sda8 996M 235M 710M 25% /
/dev/sda9 52G 180M 49G 1% /data
/dev/sda7 996M 34M 911M 4% /home
/dev/sda6 2.0G 76M 1.8G 5% /var
/dev/sda2 3.9G 1.4G 2.4G 38% /usr
/dev/sda5 2.0G 36M 1.9G 2% /usr/local
/dev/sda1 99M 17M 78M 18% /boot
tmpfs 506M 0 506M 0% /dev/shm
【编辑推荐】