Skip to content
This repository has been archived by the owner on Oct 31, 2023. It is now read-only.

Commit

Permalink
New build process: remaster the ISO
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchellh committed Feb 12, 2014
1 parent 0cca86b commit 473796d
Show file tree
Hide file tree
Showing 11 changed files with 165 additions and 82 deletions.
12 changes: 6 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.DS_Store
packer_cache/
*.box
boot2docker.iso
boot2docker.vdi
Vagrantfile
.DS_Store
.vagrant/
packer_cache/
*.box
b2d.iso
boot2docker-vagrant.iso
16 changes: 0 additions & 16 deletions Makefile

This file was deleted.

26 changes: 20 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,27 @@ and `vagrant up` as usual! Or, if you don't want to leave your terminal:
## Building the Box

If you want to recreate the box, rather than using the binary, then
you can use the Packer template and sources within this repository to
do it in seconds.
you can use the scripts and Packer template within this repository to
do so in seconds.

To build the box, first install the following prerequisites:

* [Packer](http://www.packer.io) (at least version 0.5.1)
* [VirtualBox](http://www.virtualbox.org)

Then, just run `make`. The resulting box will be named "boot2docker.box".
The entire process to make the box takes about 20 seconds.
* [VirtualBox](http://www.virtualbox.org) or VMware
* [Vagrant](http://www.vagrantup.com)

Then follow the steps:

```
$ vagrant up
...
$ vagrant ssh -c 'cd /vagrant && sudo ./build-iso.sh'
...
$ vagrant destroy --force
...
$ packer build template.json
...
```

You can restrict only VirtualBox or VMware by specifying the `-only` flag
to Packer.
19 changes: 19 additions & 0 deletions Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :

# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
# All Vagrant configuration is done here. The most common configuration
# options are documented and commented below. For a complete reference,
# please see the online documentation at vagrantup.com.

# Every Vagrant virtual environment requires a box to build off of.
config.vm.box = "precise32"
config.vm.box_url = "http://opscode-vm-bento.s3.amazonaws.com/vagrant/virtualbox/opscode_ubuntu-12.04-i386_chef-provisionerless.box"

config.vm.provider "virtualbox" do |v|
v.customize ["modifyvm", :id, "--memory", "1500"]
end
end
73 changes: 73 additions & 0 deletions build-iso.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#!/bin/bash
#
# This script takes a boot2docker.iso and re-processes it to be usable
# by Vagrant.
#
set -e
set -x

B2D_URL="https://github.com/steeve/boot2docker/releases/download/v0.5.4/boot2docker.iso"

apt-get -y update
apt-get install -y genisoimage

#--------------------------------------------------------------------
# B2D
#--------------------------------------------------------------------
# Download boot2docker
wget -O b2d.iso ${B2D_URL}

# Mount it up
rm -rf /tmp/boot
mkdir -p /mnt/tmp
mount b2d.iso /mnt/tmp -o loop,ro
cp -a /mnt/tmp/boot /tmp
mv /tmp/boot/initrd.img /tmp
umount /mnt/tmp

# Extract the core filesystem
EXTRACT_DIR="/tmp/extract"
rm -rf ${EXTRACT_DIR}
mkdir -p ${EXTRACT_DIR}
pushd ${EXTRACT_DIR}
lzma -dc /tmp/initrd.img | cpio -i -H newc -d
popd

#--------------------------------------------------------------------
# Customization
#--------------------------------------------------------------------
# Script to add in public key
cat <<EOF > ${EXTRACT_DIR}/etc/rc.d/vagrant
mkdir -p /home/docker/.ssh
chmod 0700 /home/docker/.ssh
cat <<KEY >/home/docker/.ssh/authorized_keys
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ== vagrant insecure public key
KEY
chmod 0600 /home/docker/.ssh/authorized_keys
chown -R docker:staff /home/docker/.ssh
EOF
chmod +x ${EXTRACT_DIR}/etc/rc.d/vagrant

# Configure boot to add public key
echo "/etc/rc.d/vagrant" >> ${EXTRACT_DIR}/opt/bootsync.sh

#--------------------------------------------------------------------
# Package
#--------------------------------------------------------------------
# Make the initrd.img image...
pushd ${EXTRACT_DIR}
find | cpio -o -H newc | xz -9 --format=lzma > /tmp/initrd.img
popd

# Make the ISO
pushd /tmp
mv initrd.img boot
mkdir newiso
mv boot newiso
popd
mkisofs -l -J -R -V b2d-vagrant -no-emul-boot -boot-load-size 4 \
-boot-info-table -b boot/isolinux/isolinux.bin \
-c boot/isolinux/boot.cat -o boot2docker-vagrant.iso /tmp/newiso
rm -rf /tmp/newiso
12 changes: 0 additions & 12 deletions files/sshd_config

This file was deleted.

1 change: 0 additions & 1 deletion files/vagrant_key.pub

This file was deleted.

Binary file removed persistent.vmdk
Binary file not shown.
47 changes: 16 additions & 31 deletions template.json
Original file line number Diff line number Diff line change
@@ -1,44 +1,29 @@
{
"builders": [{
"type": "virtualbox-iso",
"iso_url": "boot2docker.iso",
"iso_checksum": "522fc919ef97ed60c221b1a99a65ff2f",
"iso_checksum_type": "md5",
"iso_url": "boot2docker-vagrant.iso",
"iso_checksum_type": "none",
"boot_wait": "5s",
"ssh_username": "docker",
"ssh_password": "tcuser",
"shutdown_command": "sudo poweroff",
"guest_additions_mode": "disable",
"guest_os_type": "Linux_64",
"vboxmanage": [
["storagectl", "{{.Name}}", "--name", "SATA", "--add", "sata",
"--hostiocache", "on"],
["storageattach", "{{.Name}}", "--storagectl", "SATA",
"--port", "0", "--device", "0",
"--type", "dvddrive", "--medium", "boot2docker.iso"],
["storageattach", "{{.Name}}", "--storagectl", "SATA",
"--port", "1", "--device", "0",
"--type", "hdd", "--medium", "persistent2.vmdk"]
]
}],

"provisioners": [{
"type": "file",
"source": "files/",
"destination": "/tmp"
"ssh_username": "docker",
"ssh_password": "tcuser",
"shutdown_command": "sudo poweroff"
}, {
"type": "shell",
"inline": [
"sudo cp /tmp/sshd_config /var/lib/boot2docker/ssh/sshd_config",
"sudo cp /tmp/vagrant_key.pub /var/lib/boot2docker/ssh/docker_authorized_keys",
"sudo chown docker:docker /var/lib/boot2docker/ssh/docker_authorized_keys",
"sudo chmod 0600 /var/lib/boot2docker/ssh/docker_authorized_keys"
]
"type": "vmware-iso",
"iso_url": "boot2docker-vagrant.iso",
"iso_checksum_type": "none",
"boot_wait": "5s",
"guest_os_type": "other3xlinux-64",
"ssh_username": "docker",
"ssh_password": "tcuser",
"shutdown_command": "sudo poweroff"
}],

"post-processors": [{
"type": "vagrant",
"vagrantfile_template": "vagrantfile_virtualbox.tpl",
"output": "boot2docker.box"
"include": ["boot2docker-vagrant.iso"],
"vagrantfile_template": "vagrantfile.tpl",
"output": "boot2docker_{{.Provider}}.box"
}]
}
31 changes: 31 additions & 0 deletions vagrantfile.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
Vagrant.configure("2") do |config|
config.ssh.shell = "sh -l"
config.ssh.username = "docker"

# Disable synced folders because guest additions aren't available
config.vm.synced_folder ".", "/vagrant", disabled: true

# Expose the Docker port
config.vm.network "forwarded_port", guest: 4243, host: 4243

# Attach the ISO
config.vm.provider "virtualbox" do |v|
v.customize "pre-boot", [
"storageattach", :id,
"--storagectl", "IDE Controller",
"--port", "0",
"--device", "1",
"--type", "dvddrive",
"--medium", File.expand_path("../boot2docker-vagrant.iso", __FILE__),
]
end

["vmware_fusion", "vmware_workstation"].each do |vmware|
config.vm.provider vmware do |v|
v.vmx["bios.bootOrder"] = "CDROM,hdd"
v.vmx["ide1:0.present"] = "TRUE"
v.vmx["ide1:0.fileName"] = File.expand_path("../boot2docker-vagrant.iso", __FILE__)
v.vmx["ide1:0.deviceType"] = "cdrom-image"
end
end
end
10 changes: 0 additions & 10 deletions vagrantfile_virtualbox.tpl

This file was deleted.

0 comments on commit 473796d

Please sign in to comment.