Skip to content

Commit

Permalink
Merge pull request #492 from rickard-von-essen/freebsd-11
Browse files Browse the repository at this point in the history
FreeBSD 11.0 support
  • Loading branch information
Seth Thomas authored Nov 18, 2016
2 parents f6f3c33 + c91f28a commit a87695f
Show file tree
Hide file tree
Showing 5 changed files with 311 additions and 3 deletions.
233 changes: 233 additions & 0 deletions freebsd-11.0-amd64.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,233 @@
{
"builders": [
{
"boot_command": [
"<esc><wait>",
"boot -s<wait>",
"<enter><wait>",
"<wait10><wait10>",
"/bin/sh<enter><wait>",
"mdmfs -s 100m md1 /tmp<enter><wait>",
"mdmfs -s 100m md2 /mnt<enter><wait>",
"dhclient -l /tmp/dhclient.lease.em0 em0<enter><wait>",
"fetch -o /tmp/installerconfig http://{{ .HTTPIP }}:{{ .HTTPPort }}/{{user `install_path`}} && bsdinstall script /tmp/installerconfig<enter><wait>"
],
"boot_wait": "10s",
"disk_size": "{{user `disk_size`}}",
"guest_additions_path": "VBoxGuestAdditions_{{.Version}}.iso",
"guest_os_type": "FreeBSD_64",
"headless": "{{ user `headless` }}",
"http_directory": "http",
"iso_checksum": "{{user `iso_checksum`}}",
"iso_checksum_type": "{{user `iso_checksum_type`}}",
"iso_url": "{{user `mirror`}}/{{user `mirror_directory`}}/{{user `iso_name`}}",
"output_directory": "packer-{{user `template`}}-virtualbox",
"shutdown_command": "echo 'vagrant' | su -m root -c 'shutdown -p now'",
"ssh_password": "vagrant",
"ssh_port": 22,
"ssh_username": "vagrant",
"ssh_wait_timeout": "10000s",
"type": "virtualbox-iso",
"vboxmanage": [
[
"modifyvm",
"{{.Name}}",
"--memory",
"{{ user `memory` }}"
],
[
"modifyvm",
"{{.Name}}",
"--cpus",
"{{ user `cpus` }}"
]
],
"virtualbox_version_file": ".vbox_version",
"vm_name": "{{ user `template` }}"
},
{
"boot_command": [
"<esc><wait>",
"boot -s<wait>",
"<enter><wait>",
"<wait10><wait10>",
"/bin/sh<enter><wait>",
"mdmfs -s 100m md1 /tmp<enter><wait>",
"mdmfs -s 100m md2 /mnt<enter><wait>",
"dhclient -l /tmp/dhclient.lease.em0 em0<enter><wait>",
"<wait5>",
"fetch -o /tmp/installerconfig http://{{ .HTTPIP }}:{{ .HTTPPort }}/{{user `install_path`}} && bsdinstall script /tmp/installerconfig<enter><wait>"
],
"boot_wait": "10s",
"disk_size": "{{user `disk_size`}}",
"guest_os_type": "freebsd-64",
"headless": "{{ user `headless` }}",
"http_directory": "http",
"iso_checksum": "{{user `iso_checksum`}}",
"iso_checksum_type": "{{user `iso_checksum_type`}}",
"iso_url": "{{user `mirror`}}/{{user `mirror_directory`}}/{{user `iso_name`}}",
"output_directory": "packer-{{user `template`}}-vmare",
"shutdown_command": "echo 'vagrant' | su -m root -c 'shutdown -p now'",
"ssh_password": "vagrant",
"ssh_port": 22,
"ssh_username": "vagrant",
"ssh_wait_timeout": "10000s",
"tools_upload_flavor": "freebsd",
"type": "vmware-iso",
"vm_name": "{{ user `template` }}",
"vmx_data": {
"cpuid.coresPerSocket": "1",
"memsize": "{{ user `memory` }}",
"numvcpus": "{{ user `cpus` }}"
}
},
{
"boot_command": [
"<esc><wait>",
"boot -s<wait>",
"<enter><wait>",
"<wait10><wait10>",
"/bin/sh<enter><wait>",
"mdmfs -s 100m md1 /tmp<enter><wait>",
"mdmfs -s 100m md2 /mnt<enter><wait>",
"dhclient -l /tmp/dhclient.lease.em0 em0<enter><wait>",
"fetch -o /tmp/installerconfig http://{{ .HTTPIP }}:{{ .HTTPPort }}/{{user `install_path`}} && bsdinstall script /tmp/installerconfig<enter><wait>"
],
"boot_wait": "8s",
"disk_size": "{{user `disk_size`}}",
"guest_os_type": "freebsd",
"http_directory": "http",
"iso_checksum": "{{user `iso_checksum`}}",
"iso_checksum_type": "{{user `iso_checksum_type`}}",
"iso_url": "{{user `mirror`}}/{{user `mirror_directory`}}/{{user `iso_name`}}",
"output_directory": "packer-{{user `template`}}-parallels",
"parallels_tools_mode": "disable",
"prlctl": [
[
"set",
"{{.Name}}",
"--memsize",
"{{ user `memory` }}"
],
[
"set",
"{{.Name}}",
"--cpus",
"{{ user `cpus` }}"
],
[
"set",
"{{.Name}}",
"--device-set",
"cdrom0",
"--iface",
"ide"
],
[
"set",
"{{.Name}}",
"--device-del",
"fdd0"
],
[
"set",
"{{.Name}}",
"--device-del",
"parallel0"
]
],
"prlctl_version_file": ".prlctl_version",
"shutdown_command": "echo 'vagrant' | su -m root -c 'shutdown -p now'",
"ssh_password": "vagrant",
"ssh_port": 22,
"ssh_username": "vagrant",
"ssh_wait_timeout": "10000s",
"type": "parallels-iso",
"vm_name": "{{ user `template` }}"
},
{
"boot_command": [
"<esc><wait>",
"boot -s<wait>",
"<enter><wait>",
"<wait10><wait10>",
"/bin/sh<enter><wait>",
"mdmfs -s 100m md1 /tmp<enter><wait>",
"mdmfs -s 100m md2 /mnt<enter><wait>",
"dhclient -l /tmp/dhclient.lease.vtnet0 vtnet0<enter><wait>",
"fetch -o /tmp/installerconfig http://{{ .HTTPIP }}:{{ .HTTPPort }}/{{user `install_path`}} && bsdinstall script /tmp/installerconfig<enter><wait>"
],
"boot_wait": "7s",
"disk_size": "{{user `disk_size`}}",
"headless": "{{ user `headless` }}",
"http_directory": "http",
"iso_checksum": "{{user `iso_checksum`}}",
"iso_checksum_type": "{{user `iso_checksum_type`}}",
"iso_url": "{{user `mirror`}}/{{user `mirror_directory`}}/{{user `iso_name`}}",
"output_directory": "packer-{{user `template`}}-qemu",
"shutdown_command": "echo 'vagrant' | su -m root -c 'shutdown -p now'",
"ssh_password": "vagrant",
"ssh_port": 22,
"ssh_username": "vagrant",
"ssh_wait_timeout": "10000s",
"type": "qemu",
"vm_name": "{{ user `template` }}"
}
],
"post-processors": [
{
"output": "builds/{{user `box_basename`}}.{{.Provider}}.box",
"type": "vagrant",
"vagrantfile_template": "vagrantfile_templates/freebsd.rb"
}
],
"provisioners": [
{
"destination": "/tmp/bento-metadata.json",
"source": "{{user `metadata`}}",
"type": "file"
},
{
"environment_vars": [
"HOME_DIR=/home/vagrant",
"http_proxy={{user `http_proxy`}}",
"https_proxy={{user `https_proxy`}}",
"no_proxy={{user `no_proxy`}}"
],
"execute_command": "echo 'vagrant' | {{.Vars}} su -m root -c 'sh -eux {{.Path}}'",
"scripts": [
"scripts/common/metadata.sh",
"scripts/freebsd/update.sh",
"scripts/freebsd/postinstall.sh",
"scripts/freebsd/sudoers.sh",
"scripts/common/vagrant.sh",
"scripts/freebsd/vmtools.sh",
"scripts/freebsd/cleanup.sh",
"scripts/freebsd/minimize.sh"
],
"type": "shell"
}
],
"variables": {
"box_basename": "freebsd-11.0",
"build_timestamp": "{{isotime \"20060102150405\"}}",
"cpus": "1",
"disk_size": "40960",
"git_revision": "__unknown_git_revision__",
"headless": "",
"http_proxy": "{{env `http_proxy`}}",
"https_proxy": "{{env `https_proxy`}}",
"install_path": "freebsd-11.0/installerconfig",
"iso_checksum": "08b12f2dc378f7a61b5469219824c74a2f9faef580acc85ffab45365df79872d",
"iso_checksum_type": "sha256",
"iso_name": "FreeBSD-11.0-RELEASE-amd64-disc1.iso",
"memory": "512",
"metadata": "floppy/dummy_metadata.json",
"mirror": "http://ftp.freebsd.org/pub/FreeBSD",
"mirror_directory": "releases/amd64/amd64/ISO-IMAGES/11.0",
"name": "freebsd-11.0",
"no_proxy": "{{env `no_proxy`}}",
"template": "freebsd-11.0-amd64",
"version": "2.1.TIMESTAMP"
}
}
51 changes: 51 additions & 0 deletions http/freebsd-11.0/installerconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
DISTRIBUTIONS="base.txz lib32.txz kernel.txz src.txz"

# for variations in the root disk device name between VMware and Virtualbox
if [ -e /dev/ada0 ]; then
DISKSLICE=ada0
elif [ -e /dev/da0 ]; then
DISKSLICE=da0
elif [ -e /dev/vtbd0 ]; then
DISKSLICE=vtbd0
else
echo "Unknown disk for install.sh to work with!"
exit -1
fi

# Workaround for https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=203777
export nonInteractive="YES"

export ZFSBOOT_DISKS="$DISKSLICE"
export ZFSBOOT_CONFIRM_LAYOUT=0

HOSTNAME=freebsd

#!/bin/sh -x

ifdev=$(ifconfig | grep '^[a-z]' | cut -d: -f1 | head -n 1)
# Enable required services
cat >> /etc/rc.conf << EOT
ifconfig_${ifdev}="dhcp"
sshd_enable="YES"
EOT

# Tune and boot from zfs
cat >> /boot/loader.conf << EOT
vm.kmem_size="200M"
vm.kmem_size_max="200M"
vfs.zfs.arc_max="40M"
vfs.zfs.vdev.cache.size="5M"
autoboot_delay=3
EOT

# zfs doesn't use an fstab, but some rc scripts expect one
touch /etc/fstab

# Set up user accounts
echo "vagrant" | pw -V /etc useradd vagrant -h 0 -s /bin/sh -G wheel -d /home/vagrant -c "Vagrant User"
echo "vagrant" | pw -V /etc usermod root

mkdir -p /home/vagrant
chown 1001:1001 /home/vagrant

reboot
16 changes: 15 additions & 1 deletion scripts/freebsd/minimize.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,22 @@ case "$PACKER_BUILDER_TYPE" in
qemu) exit 0 ;;
esac

dd if=/dev/zero of=/EMPTY bs=1M || echo "dd exit code $? is suppressed";
COMPRESSION=$(zfs get -H compression zroot | cut -f3);

zfs set compression=off zroot;
dd if=/dev/zero of=/EMPTY bs=1m &
PID=$!;

avail=$(zfs get -pH avail zroot/ROOT/default | cut -f3);
while [ "$avail" -ne 0 ]; do
sleep 15;
avail=$(zfs get -pH avail zroot/ROOT/default | cut -f3);
done

kill $PID || echo "dd already exited";

rm -f /EMPTY;
# Block until the empty file has been removed, otherwise, Packer
# will try to kill the box while the disk is still full and that's bad
sync;
zfs set compression=$COMPRESSION zroot;
2 changes: 1 addition & 1 deletion scripts/freebsd/update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ fi

# Update FreeBSD
# NOTE: the install action fails if there are no updates so || true it
env PAGER=/bin/cat $freebsd_update fetch;
env PAGER=/bin/cat $freebsd_update fetch || true;
env PAGER=/bin/cat $freebsd_update install || true;

# Always use pkgng - pkg_add is EOL as of 1 September 2014
Expand Down
12 changes: 11 additions & 1 deletion scripts/freebsd/vmtools.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,17 @@ vmware-iso|vmware-vmx)
mdconfig -a -t vnode -f $HOME_DIR/freebsd.iso -u 0;
mount -t cd9660 /dev/md0 /tmp/vmfusion;
tar xzf /tmp/vmfusion/vmware-freebsd-tools.tar.gz -C /tmp/vmfusion-archive;
/tmp/vmfusion-archive/vmware-tools-distrib/vmware-install.pl --force-install;

VER="`cat /tmp/vmfusion/manifest.txt | cut -f2 -d'"'`";
MAJ_VER="`echo ${VER} | cut -d'.' -f1`";
echo "VMware Tools Version: $VER";

if [ "${MAJ_VER}" -lt "10" ]; then
/tmp/vmfusion-archive/vmware-tools-distrib/vmware-install.pl --default;
else
/tmp/vmfusion-archive/vmware-tools-distrib/vmware-install.pl --force-install;
fi

echo 'ifconfig_vxn0="dhcp"' >>/etc/rc.conf;
umount /tmp/vmfusion;
rm -rf /tmp/vmfusion;
Expand Down

0 comments on commit a87695f

Please sign in to comment.