在給客戶部署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
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
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
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)執行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
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
/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刪除擴充套件分割槽/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
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
/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)檢視改動後的分割槽大小。到目前為止,/data分割槽大小仍未改變。
[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
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)執行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.
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
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
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