歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux管理 >> Linux維護 >> Linux更改VirtualBox磁盤容量的方法

Linux更改VirtualBox磁盤容量的方法

日期:2017/3/2 10:32:09   编辑:Linux維護

VirtualBox是一款虛擬機,在Linux系統使用過程中會遇到VirtualBox虛擬機磁盤空間不夠用的問題,遇到這種問題該如何解決呢?下面小編就教大家Linux如何更改VirtualBox虛擬機的磁盤容量。

1.啟動CMD命令行,進入VirtualBox的安裝目錄。如

cd E:\Program Files\Oracle\VirtualBox

2.查看需要修改的虛擬硬盤:

E:\Program Files\Oracle\VirtualBox》VBoxManage.exe list hdds

UUID: e8e2c341-b3b1-49db-ad2d-ab4e6b08bc5a

Parent UUID: base

State: locked write

Type: normal (base)

Location: F:\VM\CentOS-64.vdi

Storage format: VDI

Capacity: 8000 MBytes

UUID: 707d45b6-380d-4e51-96bd-8c9508bfd313

Parent UUID: base

State: created

Type: normal (base)

Location: F:\VM\CentOS-64-ext.vdi

Storage format: VDI

Capacity: 21273 MBytes

UUID: aca81637-fbc0-4826-be66-847ecc96d83b

Parent UUID: base

State: created

Type: normal (base)

Location: C:\Users\Edward.Wu\VirtualBox VMs\WinXP\WinXP.vdi

Storage format: VDI

Capacity: 10240 MBytes

----

我們看到共有三個虛擬磁盤,我們要修改圖中第一個,它的空間大小為8G,UUID:e8e2c341-b3b1-49db-ad2d-ab4e6b08bc5a

2. 調整磁盤空間為15G:

E:\Program Files\Oracle\VirtualBox》VBoxManage.exe modifyhd e8e2c341-b3b1-49db-ad2d-ab4e6b08bc5a --resize 150000%.。.10%.。.20%.。.30%.。.40%.。.50%.。.60%.。.70%.。.80%.。.90%.。.100%

重新查看:

E:\Program Files\Oracle\VirtualBox》VBoxManage.exe list hdds UUID: e8e2c341-b3b1-49db-ad2d-ab4e6b08bc5a Parent UUID: base State: locked write Type: normal (base) Location: F:\VM\CentOS-64.vdi Storage format: VDI Capacity: 15000 MBytes

UUID: 707d45b6-380d-4e51-96bd-8c9508bfd313 Parent UUID: base State: created Type: normal (base) Location: F:\VM\CentOS-64-ext.vdi Storage format: VDI Capacity: 21273 MBytes

UUID: aca81637-fbc0-4826-be66-847ecc96d83b Parent UUID: base State: created Type: normal (base) Location: C:\Users\Edward.Wu\VirtualBox VMs\WinXP\WinXP.vdi Storage format: VDI Capacity: 10240 MBytes

4.查看新的磁盤空間

重新啟動虛擬機,查看磁盤情況。

[root@aimin ~]# fdisk -l /dev/sda

Disk /dev/sda: 15.7 GB, 15728640000 bytes 255 heads, 63 sectors/track, 1912 cylinders

可以看到磁盤空間已經擴展到15G,但這時還不可以使用。

5.Enable新增加的空間

使用 fdisk 將虛擬磁盤的空閒空間創建為一個新的分區。注意要使用代表 Linux LVM 的分區號 8e 來作為 ID。

# fdisk /dev/sda

n {new partition}

p {primary partition}

3 {partition number}

[這時會提示修改大小,選擇默認直接回車即可]

t {change partition id}

3 {partition number}

8e {Linux LVM partition}

w

------

如果中間有設置大小之類的提示,就直接回車。

完成後,如果提示:

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)

就重啟一下系統。

6.查看新增加的sda3是否標記為LVM,如果沒有需要reboot

#fdisk -l /dev/sda

7.調整LVM大小

先看一下Volume Group名稱

[root@aimin ~]# vgdisplay --- Volume group --- VG Name vg_aimin

。。.。

vg_aimin是我的VolumeGroup的名稱,實際操作時,需要使用實際顯示的名稱。

8.把新分配的空間創建一個新的物理卷

#pvcreate /dev/sda3

9.然後使用新的物理卷來擴展 LVM 的 VolGroup,

# vgextend vg_aimin /dev/sda3

No physical volume label read from /dev/sda3

Writing physical volume data to disk “/dev/sda3”

Physical volume “/dev/sda3” successfully created

Volume group “vg_aimin” successfully extended

10.然後擴展 LVM 的邏輯卷 vg_aimin-lv_root,

# lvextend /dev/vg_aimin/lv_root /dev/sda3

11.調整邏輯卷的大小

#resize2fs /dev/vg_aimin/lv_root

到這裡就完成了空間的擴展。

12.查看效果

[root@aimin ~]# df -h文件系統 容量 已用 可用 已用%% 掛載點/dev/mapper/vg_aimin-lv_root 12G 5.2G 6.2G 46% /tmpfs 499M 80K 499M 1% /dev/shm/dev/sda1 485M 33M 427M 8% /boot

成功擴展!!!

上面就是Linux修改VirtualBox虛擬機磁盤容量的方法介紹了,首先使用命令行進入VirtualBox虛擬機的安裝目錄,在找到相應文件進行磁盤大小的修改。

Copyright © Linux教程網 All Rights Reserved