Last active
May 12, 2022 22:05
-
-
Save yutannihilation/8197124 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"builders": [ | |
{ | |
"type": "virtualbox-iso", | |
"vm_name": "freebsd100-packer", | |
"boot_wait": "10s", | |
"disk_size": 10240, | |
"guest_os_type": "FreeBSD_64", | |
"iso_checksum": "fd25619fa0d69c29bea8347b1070ac75", | |
"iso_checksum_type": "md5", | |
"iso_url": "FreeBSD-10.0-RELEASE-amd64-disc1.iso", | |
"ssh_username": "vagrant", | |
"ssh_password": "vagrant", | |
"ssh_port": 22, | |
"ssh_wait_timeout": "10000s", | |
"shutdown_command": "echo 'shutdown -p now'|su -", | |
"guest_additions_path": "VBoxGuestAdditions_{{.Version}}.iso", | |
"virtualbox_version_file": ".vbox_version", | |
"vboxmanage": [ | |
[ | |
"modifyvm", | |
"{{.Name}}", | |
"--memory", | |
"1024" | |
], | |
[ | |
"modifyvm", | |
"{{.Name}}", | |
"--cpus", | |
"1" | |
] | |
], | |
"http_directory": ".", | |
"boot_command": [ | |
"<esc>", | |
"load geom_mbr", | |
"<enter>", | |
"<wait><wait><wait><wait><wait><wait><wait><wait><wait><wait>", | |
"boot -s", | |
"<enter>", | |
"<wait><wait><wait><wait><wait><wait><wait><wait><wait><wait>", | |
"/bin/sh<enter>", | |
"mdmfs -s 100m md1 /tmp<enter>", | |
"dhclient -l /tmp/dhclient.lease.em0 em0<enter>", | |
"<wait><wait><wait>", | |
"echo 'sleeping for 10 seconds, then running install script.'<enter>", | |
"fetch -o /tmp/install.sh http://{{ .HTTPIP }}:{{ .HTTPPort }}/install.sh && chmod +x /tmp/install.sh && /tmp/install.sh {{.Name}}<enter>", | |
"<wait10>" | |
] | |
} | |
], | |
"provisioners": [ | |
{ | |
"type": "shell", | |
"script": "postinstall.sh", | |
"override": { | |
"virtualbox-iso": { | |
"execute_command": "cat '{{.Path}}' | su -" | |
} | |
} | |
} | |
], | |
"post-processors": [ | |
{ | |
"type": "vagrant", | |
"output": "freebsd100-packer.box" | |
} | |
] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh -x | |
NAME=$1 | |
# create disks | |
gpart destroy -F ada0 | |
gpart create -s gpt ada0 | |
gpart add -b 34 -s 94 -t freebsd-boot ada0 | |
gpart add -s 1G -t freebsd-swap -l swap0 ada0 | |
gpart add -t freebsd-ufs ada0 | |
gpart bootcode -b /boot/pmbr -p /boot/gptboot -i 1 ada0 | |
newfs -U /dev/ada0p3 | |
mount /dev/ada0p3 /mnt | |
# Install the OS | |
cd /usr/freebsd-dist | |
cat base.txz | tar --unlink -xpJf - -C /mnt | |
cat lib32.txz | tar --unlink -xpJf - -C /mnt | |
cat kernel.txz | tar --unlink -xpJf - -C /mnt | |
cat src.txz | tar --unlink -xpJf - -C /mnt | |
# Enable required services | |
cat >> /mnt/etc/rc.conf << EOT | |
hostname="${NAME}" | |
ifconfig_em0="dhcp" | |
sshd_enable="YES" | |
EOT | |
# Install a few requirements | |
echo 'nameserver 8.8.8.8' > /mnt/etc/resolv.conf | |
cat << EOF > /mnt/etc/fstab | |
# Device Mountpoint FStype Options Dump Pass# | |
/dev/ada0p3 / ufs rw 1 1 | |
/dev/ada0p2 none swap sw 0 0 | |
EOF | |
# Set up user accounts | |
mkdir -p /mnt/usr/home/vagrant | |
echo "vagrant" | pw -V /mnt/etc useradd vagrant -h 0 -s csh -G wheel -d /usr/home/vagrant -c "Vagrant User" | |
echo "vagrant" | pw -V /mnt/etc usermod root | |
chown 1001:1001 /mnt/usr/home/vagrant | |
umount /mnt | |
# Reboot | |
reboot |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/local/bin/bash -ux | |
#Set the time correctly | |
ntpdate -v -b in.pool.ntp.org | |
date > /etc/vagrant_box_build_time | |
# allow freebsd-update to run fetch without stdin attached to a terminal | |
sed 's/\[ ! -t 0 \]/false/' /usr/sbin/freebsd-update > /tmp/freebsd-update | |
chmod +x /tmp/freebsd-update | |
# update freebsd-update | |
env ASSUME_ALWAYS_YES=YES /usr/sbin/pkg bootstrap | |
/usr/sbin/pkg update | |
/usr/sbin/pkg upgrade | |
#Installing vagrant keys | |
mkdir /usr/home/vagrant/.ssh | |
chmod 700 /usr/home/vagrant/.ssh | |
cd /usr/home/vagrant/.ssh | |
fetch --no-verify-peer -am 'https://raw.github.com/mitchellh/vagrant/master/keys/vagrant.pub' -o authorized_keys | |
chown -R vagrant /usr/home/vagrant/.ssh | |
chmod -R go-rwsx /usr/home/vagrant/.ssh | |
# Enable NFS | |
echo 'rpcbind_enable="YES"' >> /etc/rc.conf | |
echo 'nfs_server_enable="YES"' >> /etc/rc.conf | |
echo 'mountd_flags="-r"' >> /etc/rc.conf | |
# Enable passwordless sudo | |
echo "vagrant ALL=(ALL) NOPASSWD: ALL" >> /usr/local/etc/sudoers | |
pkg install -y libtool | |
pkg install -y sudo | |
# disable X11 because vagrants are (usually) headless | |
cat >> /etc/make.conf << EOT | |
WITHOUT_X11="YES" | |
EOT | |
pkg install -y virtualbox-ose-additions | |
sed -i '' -e '/^WITHOUT_X11/d' /etc/make.conf | |
echo 'vboxdrv_load="YES"' >> /boot/loader.conf | |
echo 'vboxnet_enable="YES"' >> /etc/rc.conf | |
echo 'vboxguest_enable="YES"' >> /etc/rc.conf | |
echo 'vboxservice_enable="YES"' >> /etc/rc.conf | |
pw groupadd vboxusers | |
pw groupmod vboxusers -m vagrant | |
exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment