vb.customize' storageattach'第一次安装我的磁盘,但是在流浪汉停止后更改会丢失;流浪汉

时间:2014-12-16 09:10:48

标签: vagrant virtualbox

我是流浪汉的新手,我正在尝试向虚拟机添加第二个磁盘,我正在与流浪汉做饭。  我想办法在首次启动虚拟机时如何连接磁盘,但是当我将机器关闭时  然后再次备份(使用'vagrant up --provision'以确保配置程序运行)我对磁盘所做的更改  迷路了。

我使用日志记录运行了两次,第二次运行的日志输出(最初设置计算机后重新启动)显示正在执行storageattach命令。但我在“/ dev / shm”(它似乎是第二个磁盘的挂载点)下创建的每个文件都会消失。

失败模式是:

流浪汉......

 touch /dev/shm/some.file
 ls /dev/shm/some.file   # see output here... 

流浪汉停止

流浪汉 - 提供

ls /dev/shm/some.file     #  no such file or directory.. where did it go ? 

任何提示都会非常感激。

我的Vagrantfile是:

...

Vagrant.require_version ">= 1.4.3"
VAGRANTFILE_API_VERSION = "2"
disk = './secondDisk.vdi'
BOX_NAME="test"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
    config.vm.define :master do |master|
        master.vm.box = "centos65"
        master.vm.box_url = "https://github.com/2creatives/vagrant-centos/releases/download/v6.5.1/centos65-x86_64-20131205.box"
        master.vm.provider "virtualbox" do |v|
          v.customize ["modifyvm", :id, "--memory", "4196"]
          v.name = BOX_NAME
        end
        master.vm.network :private_network, ip: "192.168.33.10"
        master.vm.hostname = BOX_NAME
    end

    config.vm.synced_folder(".", "/vagrant",
        :owner => "vagrant",
        :group => "vagrant",
        :mount_options => ['dmode=777','fmode=777']
    )
    config.vm.provider "virtualbox" do |vb|
        unless File.exist?(disk)
            vb.customize ['createhd', '--filename', disk, '--variant', 'Fixed', '--size', 1 * 1024]
        end
        vb.customize ['storageattach', :id,  '--storagectl', 'SATA', '--port', 1, '--device', 0, '--type', 'hdd', '--medium', disk]
    end
end

这是第二个'vagrant up --provision'的日志输出[我正在使用--provision来确保所有配置步骤都在每个流浪者完成]:

INFO sanedefaults: Automatically figuring out whether to enable/disable NAT DNS proxy...
 INFO subprocess: Starting process: ["C:\\Program Files\\Oracle\\VirtualBox\\VBoxManage.exe", "modifyvm", "ea5c09                              e7-11e7-4630-a7ca-ec66461b9eb6", "--natdnsproxy1", "on"]
DEBUG subprocess: Selecting on IO
DEBUG subprocess: Waiting for process to exit. Remaining to timeout: 32000
DEBUG subprocess: Exit status: 0
 INFO warden: Calling IN action: #<VagrantPlugins::ProviderVirtualBox::Action::Customize:0x3dc9818>
 INFO interface: info: Running 'pre-boot' VM customizations...
 INFO interface: info: ==> master: Running 'pre-boot' VM customizations...
==> master: Running 'pre-boot' VM customizations...
 INFO subprocess: Starting process: ["C:\\Program Files\\Oracle\\VirtualBox\\VBoxManage.exe", "storageattach", "e                              a5c09e7-11e7-4630-a7ca-ec66461b9eb6", "--storagectl", "SATA", "--port", "1", "--device", "0", "--type", "hdd", "-                              -medium", "./secondDisk.vdi"]
DEBUG subprocess: Selecting on IO
DEBUG subprocess: Waiting for process to exit. Remaining to timeout: 32000
DEBUG subprocess: Exit status: 0

1 个答案:

答案 0 :(得分:4)

感谢BMW提供精心设计和时尚的答案,以及Peter。引用的文章(gist.github.com/leifg/4713995)具有魔力,我将在下面的Vagrant脚本和相应的引导文件中重现,该文件从新添加的第二个磁盘生成文件系统,并将其添加到/ etc / fstab文件。这完全解决了我的问题[不再有消失的数据]。

Vagrantfile:

Vagrant.require_version ">= 1.4.3"
VAGRANTFILE_API_VERSION = "2"

disk = './secondDisk.vdi' 
BOX_NAME="test"


Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
    config.vm.define :master do |master|
        master.vm.box = "centos65"
        master.vm.box_url = "https://github.com/2creatives/vagrant-centos/releases/download/v6.5.1/centos65-x86_64-20131205.box"
        master.vm.provider "virtualbox" do |v|
          v.customize ["modifyvm", :id, "--memory", "4196"]
          v.name = BOX_NAME
        end
        master.vm.network :private_network, ip: "192.168.33.10"
        master.vm.hostname = BOX_NAME
    end

    config.vm.synced_folder(".", "/vagrant",
        :owner => "vagrant",
        :group => "vagrant",
        :mount_options => ['dmode=777','fmode=777']
    )

    # create the second disk and attach it
    config.vm.provider "virtualbox" do |vb|
        unless File.exist?(disk)
            vb.customize ['createhd', '--filename', disk, '--variant', 'Fixed', '--size', 1 * 1024]
        end

        vb.customize ['storageattach', :id,  '--storagectl', 'SATA', '--port', 1, '--device', 0, '--type', 'hdd', '--medium', disk]
    end

    # NEW - invoke script which  partitions the new disk (/dev/sdb) 
    # and create mount directives in /etc/fstab
    #config.vm.provision :shell, path: "bootstrap.sh"  
    config.vm.provision "shell" do |shell|
        shell.inline = "sudo /vagrant/bootstrap.sh"  
    end
end

bootstap脚本:

#!/bin/bash  -x

#   configure and mount second disk 
#
yum install -y parted
parted /dev/sdb mklabel msdos
parted /dev/sdb mkpart primary 512 100%
mkfs.xfs /dev/sdb1
mkdir /mnt/disk
echo `blkid /dev/sdb1 | awk '{print$2}' | sed -e 's/"//g'` /mnt/disk   xfs   noatime,nobarrier   0   0 >> /etc/fstab
mount /mnt/disk