24.10.14

Building a vagrant virtualbox .box from an ISO

packer.io is a powerful tool for building Anything from anything.  However, in order to use it you need to do some pretty fancy stuff,in some cases, like:
  • modify an ISO
  • launch a web server or upload kickstart files to an http server
  • write a json file with 20 or more parameters in it
In my case, I just needed to build a vagrant box for a RHEL instance for virutalbox this week.  Heres how I did it - its not really to hard !

- Launch the ISO in virtualbox as a new VM.

- yum update, and install "kernel-headers" and "kernel-devel", and reboot.     REBOOT is important because if you don't your guest additions will try to install from the old kernel and fail. See https://www.centos.org/forums/viewtopic.php?t=3811 .

- Go to "settings" and check the live cd/dvd box.

- Go to Devices -> Insert Guest Additions CD Image.

- Now mount your guest additions .  This is necessary if you want vagrant to do useful stuff (like set ip address, share folders, and so on). 
mount /dev/cdrom /mnt/vboxadditions
- Now sh /mnt/VBoxLinuxAdditions.run .  This will run the guest additions installation.  If it tails , you probably have issues with the kernel source code directory - make sure `uname -a`

- Now set up SSHD.
  • turn off iptables
  • add vagrant default ssh keys for user "root" and user "vagrant"
     (see http://jayunit100.blogspot.com/2014/04/insecure-keys-for-devtest-ssh.html
  • Start sshd and MAKE SURE you can ssh into the account passwordlessly from inside your machine.  Note that you may need to set ssh_user  in your Vagrantfile to "root" if you don't have a vagrant user.
Almost there ! Now you can do a trick using vagrant package.    Your Virtual box VMs are in a directory, such as ~/VirtualBox VMs/ .  cd there, and run (based on the screenshot above) :
 
vagrant package --base vagrant-base-box-creator --out newbox.box
 
- Congratulations ! You should now have a vagrant box which is bundled with both the vbox image and the vagrant box json file.  
 
 
 - Now publish your box to vagrantcloud and your all set !

No comments:

Post a Comment