gpt4 book ai didi

vagrant - vb.customize 'storageattach' 第一次挂载我的磁盘,但在 vagrant pause 后更改丢失; Vagrant 起来

转载 作者:行者123 更新时间:2023-12-03 22:47:13 26 4
gpt4 key购买 nike

我是 vagrant 的新手,正在尝试将第二个磁盘添加到我正在用 vagrant 制作的虚拟机中。
我想出了如何在第一次启动虚拟机时连接磁盘,但是当我关闭机器时
然后再次备份(使用 'vagrant up --provision' 以确保配置器运行)我对磁盘所做的更改
丢失了。

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

故障模式为:

Vagrant 起来...

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

Vagrant 停止

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

任何提示将不胜感激。

我的 Vagrant 文件是:

...
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 来确保每个 vagrant up 都完成所有配置步骤]:
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

最佳答案

感谢宝马精心设计和时尚的回答,还有彼得。引用的文章 (gist.github.com/leifg/4713995) 有魔力,我将在下面的 Vagrant 脚本和相应的引导文件中重现,该文件从新添加的第二个磁盘创建文件系统,并将其添加到/etc/fstab。这完全解决了我的问题[不再丢失数据]。

Vagrant 文件:

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

引导脚本:
#!/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

关于vagrant - vb.customize 'storageattach' 第一次挂载我的磁盘,但在 vagrant pause 后更改丢失; Vagrant 起来,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27501019/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com