在給客戶部署Linux虛擬機(jī)時,我一般都會單獨(dú)做出一個分區(qū)來存儲客戶的所有數(shù)據(jù),并取名為data。/data分區(qū)的默認(rèn)大小為35G,隨著時間的發(fā)展,有的客戶提出擴(kuò)大/data分區(qū)的需求。下面是我在ESX4.0上的實(shí)施步驟:
注:在生產(chǎn)環(huán)境中一定要先做好備份再做操作!
1)關(guān)掉Linux虛擬機(jī),運(yùn)行vmkfstools命令擴(kuò)展vmdk文件。原大小為50G,現(xiàn)在擴(kuò)展為65G。
vmkfstools -X 65G CentOS53.vmdk
2)開啟Linux虛擬機(jī),可以通過以下命令可以查看新增的可用空間。
[root@CentOS53 ~]# parted
GNU Parted
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 Size Type 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.1GB Free Space
3)運(yùn)行disk /dev/sda后輸入P查看分區(qū)結(jié)果如下,并記錄下來(/dev/sda9加載在/data分區(qū)上)??梢娍偣灿?span lang="EN-US">8485個cylinder,但最后一個分區(qū)只是到6527就結(jié)束了。這說明后面還有硬盤空間。
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 797 6527 46034257+ 5 Extended
/dev/sda5 797 1057 2096451 83 Linux
/dev/sda6 1058 1318 2096451 83 Linux
/dev/sda7 1319 1449 1052226 83 Linux
/dev/sda8 1450 1580 1052226 83 Linux
/dev/sda9 1581 6527 39736746 83 Linux
4)輸入d刪除擴(kuò)展分區(qū)/dev/sda4,這樣所有的邏輯分區(qū)就從分區(qū)表中消失了(不要害怕,呵呵)。
5)輸入n創(chuàng)建新的擴(kuò)展分區(qū),并創(chuàng)建原來(/dev/sda9除外)所有的邏輯分區(qū)并保持原來的起始、結(jié)束cylinder地址不變。/dev/sda9的起始地址不變,結(jié)束地址改為8485。新的分區(qū)表如下。確認(rèn)無誤后輸入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 797 8485 61761892+ 5 Extended
/dev/sda5 797 1057 2096451 83 Linux
/dev/sda6 1058 1318 2096451 83 Linux
/dev/sda7 1319 1449 1052226 83 Linux
/dev/sda8 1450 1580 1052226 83 Linux
/dev/sda9 1581 8485 55464381 83 Linux
6)查看改動后的分區(qū)大小。到目前為止,/data分區(qū)大小仍未改變。
[root@CentOS53 ~]# df -h
Filesystem Size 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)運(yùn)行resize2fs /dev/sda9已擴(kuò)展/data分區(qū)。(在2.6.X內(nèi)核里無需先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)再次查看分區(qū)大小。成功,哦耶!
[root@CentOS53 ~]# df -h
Filesystem Size 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
聯(lián)系客服