I put together small collection of usefull commands and Vagrant file snippets.
Destroy and start new insatnce from one line:
vagrant destroy -f && vagrant up
To change parameters of virtual machine:
1
2
3
4
5
| config.vm.provider :virtualbox do |vb|
vb.customize ["modifyvm", :id, "--memory", "1024"]
vb.customize ["modifyvm", :id, "--cpus", "2"]
vb.customize ["modifyvm", :id, "--ioapic", "on"]
end
|
Make sure --ioapic
is on
Link local folder to cache apt-get packages
It is very annoying to wait when packages being downloaded. Here is how to do it only once.
Create method in header of your Vagrant file:
1
2
3
4
5
6
7
8
9
| def local_cache(box_name)
cache_dir = File.join(File.expand_path("~/.vagrant"),
'cache',
'apt',
box_name)
partial_dir = File.join(cache_dir, 'partial')
FileUtils.mkdir_p(partial_dir) unless File.exists? partial_dir
cache_dir
end
|
Use it inside configuration:
1
2
| cache_dir = local_cache(config.vm.box)
config.vm.synced_folder cache_dir, "/var/cache/apt/archives/"
|
Create local virtual IP address:
1
| config.vm.network :private_network, ip: "88.88.88.88"
|
Full source of Vagrant file:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
| # -*- mode: ruby -*-
# vi: set ft=ruby :
def local_cache(box_name)
cache_dir = File.join(File.expand_path("~/.vagrant"),
'cache',
'apt',
box_name)
partial_dir = File.join(cache_dir, 'partial')
FileUtils.mkdir_p(partial_dir) unless File.exists? partial_dir
cache_dir
end
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "precise32"
config.vm.box_url = "http://files.vagrantup.com/precise32.box"
config.vm.hostname = "name"
config.vm.provider :virtualbox do |vb|
vb.customize ["modifyvm", :id, "--memory", "1024"]
vb.customize ["modifyvm", :id, "--cpus", "2"]
vb.customize ["modifyvm", :id, "--ioapic", "on"]
end
config.vm.network :private_network, ip: "88.88.88.88"
cache_dir = local_cache(config.vm.box)
config.vm.synced_folder cache_dir, "/var/cache/apt/archives/"
config.vm.synced_folder "~/.m2", "/home/vagrant/.m2"
end
|