2013-02-17 60 views
8

我想給我的盒子多一些磁盤空間。我試圖通過vagrantfile要做到這一點,如下所示:調整流浪盒上的磁盤空間

Vagrant::Config.run do |config| 
    # .. 
    config.vm.customize ["modifyvm", :id, "--memory", 1024] 
    config.vm.customize ["modifyhd", :id, "--resize", 4096] 
end 

這給我的錯誤:

A customization command failed: 
["modifyhd", "e87d8786-88be-4805-9c2a-45e88b8e0e56", "--resize", "4096"] 

The following error was experienced: 

VBoxManage: error: The given path 'e87d8786-88be-4805-9c2a-45e88b8e0e56' is not fully qualified 
VBoxManage: error: Details: code VBOX_E_FILE_ERROR (0x80bb0004), component Medium, interface IMedium, callee nsISupports 
VBoxManage: error: Context: "OpenMedium(Bstr(pszFilenameOrUuid).raw(), enmDevType, enmAccessMode, fForceNewUuidOnOpen, pMedium.asOutParam())" at line 178 of file VBoxManageDisk.cpp 


Please fix this customization and try again. 

我試圖從http://docs.vagrantup.com/v1/docs/config/vm/customize.html http://www.virtualbox.org/manual/ch08.html#vboxmanage-modifyvdi

+0

這個問題似乎是題外話,因爲它不是關於編程。 – Filburt 2014-07-29 20:38:55

+3

我認爲它是關於主題的,因爲定製腳本是用Ruby編寫的程序,並且與設置本質上是編程主題的開發環境有關。但 - 隨意放置這個問題,無論你喜歡:) – schellsan 2014-07-31 19:55:29

回答

5

拼湊的信息您需要發送修改虛擬機的UUID(由vagrant提供),同時它需要VDI的UUID。 您將需要使用實際VDI文件或其UUID的絕對路徑。您可以使用以下命令獲取VDI的UUID:VBoxManage showhdinfo <filename>(請參閱virtualbox - how to check what is the uuid of a vdi?

+4

我希望有一種方法可以在vagrant文​​件中做到這一點。 – schellsan 2013-03-03 16:15:43

+0

「在數組中找到的特殊值:id被Vagrant創建的虛擬機的實際UUID取代。」這不表示它正在傳遞VDI的UUID嗎? – DaveO 2014-01-30 21:53:37

+3

我認爲實際的問題是磁盤格式是VMDK,而不是VDI。 VMDK不支持--resize – DaveO 2014-01-30 22:50:19

2

我一直在看這個,我還沒有找到任何直接實際執行此操作的方法。但是,您可以使用Ansible作爲供應商來實現該效果。首先,Vagrant絕對有可能創建並添加第二個磁盤,然後您可以使用Ansible以任何方式添加和安裝。

但是,Ansible也有能力運行本地命令(在主機上)。這是Ansible的local_action功能。在內核升級後,我使用它here重新啓動Vagrant VM,並告訴主機等待,直到它重新啓動,但可以使用命令或shell操作來查找HD標識符,關閉VM並配置硬盤,然後重新啓動。至少在理論上。

3

我創建了一個新磁盤,添加並擴展了舊版本。

我Vagrantfile:

Vagrant.configure(2) do |config| 
config.vm.box = "bseller/oracle-standard" 
config.vm.define :oracle do |oracle| 
    oracle.vm.hostname = 'oraclebox' 
    oracle.vm.synced_folder ".", "/vagrant", owner: "oracle", group: "oinstall" 
    oracle.vm.network :private_network, ip: '192.168.33.13' 
    oracle.vm.network :forwarded_port, guest: 1521, host: 1521 
    oracle.vm.provider :virtualbox do |vb| 
    vb.customize ["modifyvm", :id, "--memory", "4096"] 
    vb.customize ["modifyvm", :id, "--name", "oraclebox"] 
    if !File.exist?("disk/oracle.vdi") 
     vb.customize [ 
      'createhd', 
      '--filename', 'disk/oracle', 
      '--format', 'VDI', 
      '--size', 60200 
      ] 
     vb.customize [ 
      'storageattach', :id, 
      '--storagectl', "SATA", 
      '--port', 1, '--device', 0, 
      '--type', 'hdd', '--medium', 'disk/oracle.vdi' 
      ] 
    end  
    end 
    oracle.vm.provision "shell", path: "shell/add-oracle-disk.sh" 
    oracle.vm.provision "shell", path: "shell/provision.sh" 
end 
end 

這將在

disk 
    |-- oracle.vdi 
shell 
    |-- provision.sh 
Vagrantfile 

創建新的磁盤,並添加你的盒子。新盤60GB 我的殼provision.sh

set -e 
set -x 

if [ -f /etc/disk_added_date ] ; then 
    echo "disk already added so exiting." 
    exit 0 
fi 

sudo fdisk -u /dev/sdb <<EOF 
n 
p 
1 


t 
8e 
w 
EOF 

sudo pvcreate /dev/sdb1 
sudo vgextend VolGroup /dev/sdb1 
sudo lvextend -L50GB /dev/VolGroup/lv_root 
sudo resize2fs /dev/VolGroup/lv_root 
date > /etc/disk_added_date 

這個腳本是從SHC適應箱bseller/oracle-standard的。對於完整的代碼,請參閱我的項目oraclebox GitHub

+0

嗨@acfreitas 我在GitHub中關注您的項目並嘗試添加代碼用於在我的Vagrant文​​件上設置虛擬機存儲,但出現了一些錯誤。 請幫助,看看我發佈的問題在這裏:http://stackoverflow.com/questions/33642768/error-setting-vm-storage-size-in-vagrant – 2015-11-11 01:28:16

2

雖然問題是舊的,但我沒有看到答案接受。

The given path 'e87d8786-88be-4805-9c2a-45e88b8e0e56' is not fully qualified因爲UUID e87d8...是VirtualBox vm UUID而不是您的SATA存儲磁盤設備UUID而顯示出來。您可以通過VBoxManage showvminfo e87d8786-88be-4805-9c2a-45e88b8e0e56|grep vdi找到存儲設備UUID。用Vagrantfile modifyhd行中的SATA存儲UUID替換:id

它解決了我的問題。

0

行...解決...

VBoxManage。exe文件在我的道路wan't所以我所做的就是去(你必須去到該路徑):

C:\ Program Files文件\ ORACLE \ VirtualBox的

然後使用命令:

VBoxManage.exe modifyhd 「C:\用戶\ MYUSER \的VirtualBox虛擬機\計算機名\ HDName.vdi」 --resize 20480

爲20 GB大小的高清

這不起作用: 「C:\ Program Files \ Oracle \ VirtualBox \ VBoxManage.exe「modifyhd」C:\ Users \ MyUser \ VirtualBox VM小號\計算機名\ HDName.vdi「--resize 20480

你必須在路徑:C:\ Program Files文件\ ORACLE \ VirtualBox的

0

您可以添加新的磁盤來代替。 先用虛框GUI再添 虛擬磁盤

enter image description here

然後使用fdisk來創建一個主磁盤partion

[email protected]:/# fdisk -l 

Disk /dev/sdb: 20 GiB, 21474836480 bytes, 41943040 sectors 
Units: sectors of 1 * 512 = 512 bytes 
Sector size (logical/physical): 512 bytes/512 bytes 
I/O size (minimum/optimal): 512 bytes/512 bytes 
Disk /dev/sda: 9.9 GiB, 10632560640 bytes, 20766720 sectors 
Units: sectors of 1 * 512 = 512 bytes 
Sector size (logical/physical): 512 bytes/512 bytes 
I/O size (minimum/optimal): 512 bytes/512 bytes 
Disklabel type: dos 
Disk identifier: 0x83312a2b 

Device  Boot Start  End Sectors Size Id Type 
/dev/sda1 *  2048 19816447 19814400 9.5G 83 Linux 
/dev/sda2  19818494 20764671 946178 462M 5 Extended 
/dev/sda5  19818496 20764671 946176 462M 82 Linux swap/Solaris 

[email protected]:/# fdisk /dev/sdb 

Welcome to fdisk (util-linux 2.25.2). 
Changes will remain in memory only, until you decide to write them. 
Be careful before using the write command. 

Device does not contain a recognized partition table. 
Created a new DOS disklabel with disk identifier 0x5eb328b9. 

Command (m for help): m 

Help: 

    DOS (MBR) 
    a toggle a bootable flag 
    b edit nested BSD disklabel 
    c toggle the dos compatibility flag 

    Generic 
    d delete a partition 
    l list known partition types 
    n add a new partition 
    p print the partition table 
    t change a partition type 
    v verify the partition table 

    Misc 
    m print this menu 
    u change display/entry units 
    x extra functionality (experts only) 

    Save & Exit 
    w write table to disk and exit 
    q quit without saving changes 

    Create a new label 
    g create a new empty GPT partition table 
    G create a new empty SGI (IRIX) partition table 
    o create a new empty DOS partition table 
    s create a new empty Sun partition table 

Command (m for help): p 

Disk /dev/sdb: 20 GiB, 21474836480 bytes, 41943040 sectors 
Units: sectors of 1 * 512 = 512 bytes 
Sector size (logical/physical): 512 bytes/512 bytes 
I/O size (minimum/optimal): 512 bytes/512 bytes 
Disklabel type: dos 
Disk identifier: 0x5eb328b9 


Command (m for help): n 
Partition type 
    p primary (0 primary, 0 extended, 4 free) 
    e extended (container for logical partitions) 
Select (default p): p 
Partition number (1-4, default 1): 
First sector (2048-41943039, default 2048): 
Last sector, +sectors or +size{K,M,G,T,P} (2048-41943039, default 41943039): 

Created a new partition 1 of type 'Linux' and of size 20 GiB. 

Command (m for help): p 
Disk /dev/sdb: 20 GiB, 21474836480 bytes, 41943040 sectors 
Units: sectors of 1 * 512 = 512 bytes 
Sector size (logical/physical): 512 bytes/512 bytes 
I/O size (minimum/optimal): 512 bytes/512 bytes 
Disklabel type: dos 
Disk identifier: 0x5eb328b9 

Device  Boot Start  End Sectors Size Id Type 
/dev/sdb1  2048 41943039 41940992 20G 83 Linux 

Command (m for help): w 
The partition table has been altered. 
Calling ioctl() to re-read partition table. 
Syncing disks. 

讓新創建的磁盤分區上的ext4文件系統

[email protected]:/# mkfs.ext4 /dev/sdb1 
mke2fs 1.42.12 (29-Aug-2014) 
Creating filesystem with 5242624 4k blocks and 1310720 inodes 
Filesystem UUID: 0301b56a-1d80-42de-9334-cc49e4eaf7b2 
Superblock backups stored on blocks: 
    32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
    4096000 

Allocating group tables: done        
Writing inode tables: done        
Creating journal (32768 blocks): done 
Writing superblocks and filesystem accounting information: done 

將磁盤分區掛載到目錄

[email protected]:/# mount -t ext4 /dev/sdb1 /home/chenchun 
[email protected]:/# df -h 
Filesystem  Size Used Avail Use% Mounted on 
/dev/sda1  9.2G 3.3G 5.5G 38%/
udev    10M  0 10M 0% /dev 
tmpfs   74M 4.4M 70M 6% /run 
tmpfs   185M  0 185M 0% /dev/shm 
tmpfs   5.0M  0 5.0M 0% /run/lock 
tmpfs   185M  0 185M 0% /sys/fs/cgroup 
none   372G 240G 133G 65% /vagrant 
/dev/sdb1  20G 44M 19G 1% /home/chenchun