首先將虛擬機關機後,第一步要先增加系統HD的容量
如果你的centos是安裝在PC上的vmware workstation上的話
安裝的目錄上有一個vmware-vdiskmanager.exe的命令可以使用
在cmd的模式下執行(擴充到50G)
如果這個guest os沒有做任何的snapshop的話,在設定->硬碟中
還有一個expand的選項可以直接增加硬碟的容量
vmware-vdiskmanager.exe -x 50G guestos.vmdk(實際占很大空間的那個檔案)
如果是安裝在Esxi上的話,則是使用vmkfstools
vmkfstools -X 50G guestos.vmdk
到這邊guest os的硬碟容量應該已經擴充到50G了,但是實際上我們系統用df看還是很小
這是因為多出來的空間現在都是無法辨識的狀態,如果是guest是windows系統的話
則只需要在磁碟管理中去調整硬碟空間大小就可以了,Centos則是需要依照以下的步驟
首先看一下系統用了多少容量
[root@localhost ~]# df -h
檔案系統 容量 已用 可用 已用% 掛載點
devtmpfs 470M 0 470M 0% /dev
tmpfs 487M 0 487M 0% /dev/shm
tmpfs 487M 8.4M 478M 2% /run
tmpfs 487M 0 487M 0% /sys/fs/cgroup
[color=#FF0000]/dev/mapper/centos-root 17G 4.8G 13G 28% /[/color]
/dev/sda1 1014M 173M 842M 17% /boot
tmpfs 98M 12K 98M 1% /run/user/42
tmpfs 98M 0 98M 0% /run/user/1000
看起來系統只用了20G,接著檢查硬碟
[root@localhost ~]# fdisk -l
Disk /dev/sda: 53.7 GB, 53687091200 bytes, 104857600 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O 大小 (最小/最佳化):512 位元組 / 512 位元組
Disk label type: dos
磁碟識別碼:0x000c35eb
所用裝置 開機 開始 結束 區塊 識別號 系統
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 41943039 19921920 8e Linux LVM
可以看到現在/dev/sda確實有53.7G,但是系統實際上只用了20G
使用fdisk新增一個partition(不想看的話fdisk /dev/sda後打p、n、p、3、w)
[root@localhost ~]# fdisk /dev/sda
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
命令 (m 以獲得說明):p
Disk /dev/sda: 53.7 GB, 53687091200 bytes, 104857600 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O 大小 (最小/最佳化):512 位元組 / 512 位元組
Disk label type: dos
磁碟識別碼:0x000c35eb
所用裝置 開機 開始 結束 區塊 識別號 系統
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 41943039 19921920 8e Linux LVM
命令 (m 以獲得說明):n
Partition type:
p primary (2 primary, 0 extended, 2 free)
e extended
Select (default p): p
分割區編號 (3,4, default 3): 3
起初 sector (41943040-104857599, 預設 41943040):
使用預設值 41943040
最後 sector, +sectors 或 +大小{K,M,G} (41943040-104857599, 預設 104857599):
使用預設值 104857599
Partition 3 of type Linux and of size 30 GiB is set
命令 (m 以獲得說明):w
分割表已變更!
呼叫 ioctl() 以重新讀取分割表。
WARNING: Re-reading the partition table failed with error 16: 裝置或系統資源忙碌中.
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)
同步磁碟。
到這邊用fdisk -l就會看到多了一個/dev/sda3
接著要create一個Volume,並且重新設定大小,接著進行擴展
[root@localhost ~]# partprobe
Warning: 無法開啟 /dev/sr0 以讀寫 (唯讀的檔案系統)。/dev/sr0 已用唯讀的方式開啟
[root@localhost ~]# pvcreate /dev/sda3
Physical volume "/dev/sda3" successfully created.
[root@localhost ~]# pvresize /dev/sda3
Physical volume "/dev/sda3" changed
[root@localhost ~]# vgextend centos /dev/sda3
Volume group "centos" successfully extended
[root@localhost ~]# lvextend -L +29G /dev/mapper/centos-root
Size of logical volume centos/root changed from <46.00 GiB (11775 extents) to <54.00 GiB (13823 extents).
[root@localhost ~]# xfs_growfs /dev/mapper/centos-root
這時候再用df -h看,就會發現根目錄變大了
[root@localhost ~]# df -h
檔案系統 容量 已用 可用 已用% 掛載點
devtmpfs 470M 0 470M 0% /dev
tmpfs 487M 0 487M 0% /dev/shm
tmpfs 487M 8.4M 478M 2% /run
tmpfs 487M 0 487M 0% /sys/fs/cgroup
[color=#FF0000]/dev/mapper/centos-root 46G 4.8G 42G 11% /[/color]
/dev/sda1 1014M 173M 842M 17% /boot
tmpfs 98M 12K 98M 1% /run/user/42
tmpfs 98M 0 98M 0% /run/user/1000
tmpfs 98M 0 98M 0% /run/user/0
...
如果你的centos是安裝在PC上的vmware workstation上的話
安裝的目錄上有一個vmware-vdiskmanager.exe的命令可以使用
在cmd的模式下執行(擴充到50G)
如果這個guest os沒有做任何的snapshop的話,在設定->硬碟中
還有一個expand的選項可以直接增加硬碟的容量
vmware-vdiskmanager.exe -x 50G guestos.vmdk(實際占很大空間的那個檔案)
如果是安裝在Esxi上的話,則是使用vmkfstools
vmkfstools -X 50G guestos.vmdk
到這邊guest os的硬碟容量應該已經擴充到50G了,但是實際上我們系統用df看還是很小
這是因為多出來的空間現在都是無法辨識的狀態,如果是guest是windows系統的話
則只需要在磁碟管理中去調整硬碟空間大小就可以了,Centos則是需要依照以下的步驟
首先看一下系統用了多少容量
[root@localhost ~]# df -h
檔案系統 容量 已用 可用 已用% 掛載點
devtmpfs 470M 0 470M 0% /dev
tmpfs 487M 0 487M 0% /dev/shm
tmpfs 487M 8.4M 478M 2% /run
tmpfs 487M 0 487M 0% /sys/fs/cgroup
[color=#FF0000]/dev/mapper/centos-root 17G 4.8G 13G 28% /[/color]
/dev/sda1 1014M 173M 842M 17% /boot
tmpfs 98M 12K 98M 1% /run/user/42
tmpfs 98M 0 98M 0% /run/user/1000
看起來系統只用了20G,接著檢查硬碟
[root@localhost ~]# fdisk -l
Disk /dev/sda: 53.7 GB, 53687091200 bytes, 104857600 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O 大小 (最小/最佳化):512 位元組 / 512 位元組
Disk label type: dos
磁碟識別碼:0x000c35eb
所用裝置 開機 開始 結束 區塊 識別號 系統
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 41943039 19921920 8e Linux LVM
可以看到現在/dev/sda確實有53.7G,但是系統實際上只用了20G
使用fdisk新增一個partition(不想看的話fdisk /dev/sda後打p、n、p、3、w)
[root@localhost ~]# fdisk /dev/sda
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
命令 (m 以獲得說明):p
Disk /dev/sda: 53.7 GB, 53687091200 bytes, 104857600 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O 大小 (最小/最佳化):512 位元組 / 512 位元組
Disk label type: dos
磁碟識別碼:0x000c35eb
所用裝置 開機 開始 結束 區塊 識別號 系統
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 41943039 19921920 8e Linux LVM
命令 (m 以獲得說明):n
Partition type:
p primary (2 primary, 0 extended, 2 free)
e extended
Select (default p): p
分割區編號 (3,4, default 3): 3
起初 sector (41943040-104857599, 預設 41943040):
使用預設值 41943040
最後 sector, +sectors 或 +大小{K,M,G} (41943040-104857599, 預設 104857599):
使用預設值 104857599
Partition 3 of type Linux and of size 30 GiB is set
命令 (m 以獲得說明):w
分割表已變更!
呼叫 ioctl() 以重新讀取分割表。
WARNING: Re-reading the partition table failed with error 16: 裝置或系統資源忙碌中.
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)
同步磁碟。
到這邊用fdisk -l就會看到多了一個/dev/sda3
接著要create一個Volume,並且重新設定大小,接著進行擴展
[root@localhost ~]# partprobe
Warning: 無法開啟 /dev/sr0 以讀寫 (唯讀的檔案系統)。/dev/sr0 已用唯讀的方式開啟
[root@localhost ~]# pvcreate /dev/sda3
Physical volume "/dev/sda3" successfully created.
[root@localhost ~]# pvresize /dev/sda3
Physical volume "/dev/sda3" changed
[root@localhost ~]# vgextend centos /dev/sda3
Volume group "centos" successfully extended
[root@localhost ~]# lvextend -L +29G /dev/mapper/centos-root
Size of logical volume centos/root changed from <46.00 GiB (11775 extents) to <54.00 GiB (13823 extents).
[root@localhost ~]# xfs_growfs /dev/mapper/centos-root
這時候再用df -h看,就會發現根目錄變大了
[root@localhost ~]# df -h
檔案系統 容量 已用 可用 已用% 掛載點
devtmpfs 470M 0 470M 0% /dev
tmpfs 487M 0 487M 0% /dev/shm
tmpfs 487M 8.4M 478M 2% /run
tmpfs 487M 0 487M 0% /sys/fs/cgroup
[color=#FF0000]/dev/mapper/centos-root 46G 4.8G 42G 11% /[/color]
/dev/sda1 1014M 173M 842M 17% /boot
tmpfs 98M 12K 98M 1% /run/user/42
tmpfs 98M 0 98M 0% /run/user/1000
tmpfs 98M 0 98M 0% /run/user/0
...