虽然这里http://www.vagrantbox.es/已经罗列出了许多个base Box,但有些时候,可能根据自身的业务需要一些特殊的Box,比如,笔者遇到的,需要一个带桌面环境和浏览器测试用的Box,这个在网上可没有找到,无奈之下,只能自己装虚拟机,做一个base Box出来,以便使用。本文主要针对ubuntu的base Box的制作。本文出自cclo的blog,转载时请务必以超链接形式标明文章原始出处:http://www.jb51.cc/article/p-tsjxkdbm-bbk.html
步骤如下:(环境 OS:ubuntu12.04_Desktop virtualBox:4.1.12)
1.在物理机安装好ubuntu系统,在此系统上安装virtualBox
2.下载一个需要的ubuntu版本的iso镜像
3.创建一个新的虚拟机
-
给虚拟机起个名字为"vagrant-precise32"
-
确保您分配足够的磁盘空间,40GB足够了。
-
确保默认的内存分配也不用太高,建议360M。
-
如果不需要,禁用音频,USB控制器等。大多数应用程序都不需要播放音乐!因此,节约资源,禁用这些功能。
-
确保网络控制器设置为NAT,为了端口转发正常工作。
4.启动虚拟机,安装ubuntu,确保配置如下(非强制,如打算分发此Box,建议遵循如下约定)
-
Hostname:vagrant-[os-name],例:vagrant-ubuntu-Steve
-
Domain: vagrantup.com
-
Root Password: vagrant
-
Main account login: vagrant
-
Main account password: vagrant
5.安装完毕后,进入虚拟机
6.根据自己需要,安装一些常用软件(可不装,直接使用nano)
sudo apt-get -y install vim
7.创建admin组(debian7可直接添加到sudo组)
sudo groupadd admin
8.添加vagrant用户到admin组(debian7可直接添加到sudo组)
useradd -g sudo -d /home/vagrant -s /bin/bash -m vagrant (userdel vagrant 删除)
sudo usermod -G admin vagrant
sudo vim /etc/sudoers #添加或修改如下行(有些发行版还需Disable requiretty):
Defaults env_keep="SSH_AUTH_SOCK"
%sudo ALL=NOPASSWD: ALL
10.安装puppet(chef没有计划装进去,如需要可安装ruby,rubygems,chef)
sudo apt-get install puppet puppetmaster
11.安装ssh
sudo apt-get install openssh-server
12.安装vagrant的public keys
mkdir ~/.ssh/
cd ~/.ssh
wget https://raw.githubusercontent.com/mitchellh/vagrant/master/keys/vagrant
wget https://raw.githubusercontent.com/mitchellh/vagrant/master/keys/vagrant.pub
mv vagrant.pub authorized_keys
13.Install virtual Box guest additions(为了共享文件夹,端口转发等debian7可不装)
(1) First,build the necessary packages. You may have to look these up for your system,but they should be fairly similar. On Ubuntu and Debian based systems they are as follows:
$ sudo apt-get install linux-headers-$(uname -r) build-essential
(2) Next,make sure to insert the guest additions image by using the GUI and clicking on “Devices” followed by “Install Guest Additions.”. Then run the following to mount the CD Rom:
$ sudo mount /dev/cdrom /media/cdrom
(3) And finally,run the shell script which matches your system. For linux on x86,it is the following:
$ sudo sh /media/cdrom/VBoxLinuxAdditions.run
If you didn’t install a Desktop environment when you installed the operating system,as recommended to reduce size,the install of the VirtualBox additions should warn you about the lack of OpenGL or Window System Drivers,but you can safely ignore this.
14.清除缓存
sudo apt-get clean
15.关闭虚拟机,进入virtual Box directory(~/VirtualBox VM/vagrant-precise32)
VBoxManage modifyvdi <freebsd-virtual-machine>.vdi compact
打包前塑身,在虚拟机执行dd if=/dev/zero of=/tmp/ZEROS bs=1M ; rm /tmp/ZEROS
sudo aptitude purge ~ilinux-image-.*\(\!`uname -r`\) 删除旧内核
vagrant package --output ubuntu_32.Box --base vagrant-precise32
总结:以上步骤完成后生成的ubuntu_32.Box就可以拿来用了,用vagrant Box add ,vagrant init等自己测试看看吧,不会用vagrant?请看这里http://www.jb51.cc/article/p-dqintshq-bbk.html
来源:<>
原文链接:/ubuntu/355449.html