Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Made some changes to how this is laid out so it will work on Atlas #41

Open
wants to merge 51 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 50 commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
092782f
Changed ssh user to vagrant
dragon788 Oct 13, 2015
27728cf
Corrected root user, added ssh timeout, added atlas post provisioners
dragon788 Oct 13, 2015
538835f
Trying to fix not shutting down properly
dragon788 Oct 13, 2015
ac4f1da
Forgot to sudo shutdown.
dragon788 Oct 13, 2015
aa13b62
Merged with upstream using latest ISO
dragon788 Oct 13, 2015
68072ae
Using upstream option for vagrant output
dragon788 Oct 13, 2015
66a70e1
Update arch-template.json
dragon788 Oct 15, 2015
cb2d473
Update arch-template.json
dragon788 Oct 15, 2015
3a38be8
Trailing comma causing issues
dragon788 Oct 15, 2015
f19d323
Adding in parallels again since it wasn't causing Atlas issues
dragon788 Oct 15, 2015
feebe7b
Cleanup to minimize the box size
dragon788 Oct 15, 2015
89ecac4
Update arch-template.json
dragon788 Oct 16, 2015
b586335
What'll happen without the "only" option?
dragon788 Oct 16, 2015
e699982
Removing parallels as Atlas doesn't support it
dragon788 Dec 12, 2015
38f1d97
Merge branch 'master' of github.com:dragon788/packer-arch
dragon788 Dec 12, 2015
fa6ec67
run pp in sequence
dragon788 Dec 28, 2015
3459d33
Update arch-template.json
dragon788 Dec 28, 2015
4875bd8
Adding scripts folder and provisioners
dragon788 Dec 30, 2015
3ff2228
Create cleanup.sh
dragon788 Dec 30, 2015
7b4f455
Rename cleanup.sh to scripts/cleanup.sh
dragon788 Dec 30, 2015
e5962ad
Update cleanup.sh
dragon788 Dec 30, 2015
bad8ccc
Update arch-template.json
dragon788 Dec 30, 2015
39b8902
Create vmware.sh
dragon788 Dec 30, 2015
91c4ef7
Create custom-script.sh
dragon788 Dec 30, 2015
b04f690
Merge pull request #2 from dragon788/dragon788-adding-scripts
dragon788 Dec 30, 2015
db44e1c
Update arch-template.json
dragon788 Dec 30, 2015
7b302c3
Update arch-template.json
dragon788 Dec 30, 2015
2d6e393
JSON doesn't like trailing commas
dragon788 Dec 30, 2015
8c75143
JSON doesn't like improper arrays and packer hates missing scripts
dragon788 Dec 30, 2015
d3bba1b
Made install script a user variable to use old style install-provider…
dragon788 Jan 2, 2016
f253ade
Baseline scripts for installing common arch components
dragon788 Jan 3, 2016
ec70b6f
Better vmware/virtualbox separation
dragon788 Jan 3, 2016
fa865c2
Merged useful changes
dragon788 Jan 3, 2016
89417f2
Ignoring .un~ files
dragon788 Jan 3, 2016
11f3df6
Fixed virtualbox escaping that is unnecessary outside of the quoted s…
dragon788 Jan 3, 2016
f616487
Added parallels tools in a better way
dragon788 Jan 3, 2016
4adbab1
Fix more escaping and remove redundant shutdowns
dragon788 Jan 3, 2016
ca1e5e7
Added install_script to wrapacker to emulate previous behavior, calli…
dragon788 Jan 3, 2016
0026a6b
Fixed install_script to wrapacker to emulate previous behavior, calli…
dragon788 Jan 3, 2016
ffc79c5
Need vagrant group for vagrant to mount things
dragon788 Jan 3, 2016
d494fc2
Split parallels to its own template file as it is OSX only, the other…
dragon788 Jan 3, 2016
979b156
Added /home/$USER/tmp to cleanup script to save a few hundred megs
dragon788 Jan 3, 2016
ad893ee
Updated README and testing removing open-vm-tools code
dragon788 Jan 4, 2016
979cf7f
Removing .json extension from parallels template so it doesn't trigge…
dragon788 Jan 4, 2016
824e9dc
Removed unnecessary open-vm-tools code
dragon788 Jan 4, 2016
2e3e5ea
Actually moving parallels to its own template
dragon788 Jan 6, 2016
e71fdae
Actually removing last parallels stuff
dragon788 Jan 6, 2016
e96c4f1
Removing unused scripts
dragon788 Jan 6, 2016
411f2b9
Minor fixup in README
dragon788 Jan 6, 2016
c732535
Using PACKER_TEMPLATE after splitting off of Parallels
dragon788 Jan 6, 2016
47be70e
Forgot to remove references to unused custom-script.sh after removing it
dragon788 Jan 6, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
packer_arch_*.box
packer_cache
output-vmware
*.un~
40 changes: 28 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Packer Arch
===========

Packer Arch is a bare bones [Packer](http://www.packer.io/) template and
installation script that can be used to generate a [Vagrant](http://www.vagrantup.com/)
Packer Arch is a bare bones [Packer](https://www.packer.io/) template and
installation script that can be used to generate a [Vagrant](https://www.vagrantup.com/)
base box for [Arch Linux](https://www.archlinux.org/). The template works
with the default VirtualBox provider as well as with
[VMware](http://www.vagrantup.com/vmware) and [Parallels](https://github.com/Parallels/vagrant-parallels) providers.
Expand Down Expand Up @@ -30,11 +30,17 @@ and the steps recommended for any base box.
Usage
-----

dragon788 has built the VMware and Virtualbox versions on Hashicorp's [Atlas build service](https://atlas.hashicorp.com)

### VirtualBox Provider

Assuming that you already have Packer,
[VirtualBox](https://www.virtualbox.org/), and Vagrant installed, you
should be good to clone this repo and go:
[VirtualBox](https://www.virtualbox.org/), and Vagrant installed, you can jump right in
with:

vagrant init dragon788/arch-ala-elasticdog; vagrant up --provider virtualbox
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we publish an 'official' packer-arch vagrant files here, rather than use @dragon788's version?

This way, @dragon788 can do his thing without worrying about messing up the upstream project.


Or if you want to customize the box you can clone this repo and go:

$ git clone https://github.com/elasticdog/packer-arch.git
$ cd packer-arch/
Expand All @@ -48,9 +54,12 @@ Then you can import the generated box into Vagrant:

Assuming that you already have Packer,
[VMware Fusion](https://www.vmware.com/products/fusion/) (or
[VMware Workstation](https://www.vmware.com/products/workstation/)), and
Vagrant with the VMware provider installed, you should be good to clone
this repo and go:
[VMware Workstation](https://www.vmware.com/products/workstation/)), and Vagrant
with the VMware provider plugin and license installed, you can jump right in

vagrant init dragon788/arch-ala-elasticdog; vagrant up --provider vmware_desktop

Or if you want to customize the box you can clone this repo and go:

$ git clone https://github.com/elasticdog/packer-arch.git
$ cd packer-arch/
Expand Down Expand Up @@ -86,20 +95,27 @@ code in order to build the final box.

See the `--help` flag for additional details.

If run without options it will attempt to build both virtualbox and VMware,
otherwise you can specify a provider with --provider at the command line.

Known Issues
------------

### VMware Tools

[dragon788](https://github.com/dragon788) has worked on getting the
[vmware-tools-patches](https://github.com/rasa/vmware-tools-patches)
working with Arch and systemd and has [successfully built it](https://github.com/dragon788/vmware-tools-patches) into the VMware version of this box.

The official VMware Tools do not currently support Arch Linux, and the
[Open Virtual Machine Tools](http://open-vm-tools.sourceforge.net/)
(open-vm-tools) require extensive patching in order to compile correctly
with a Linux 3.11 series kernel. So for the time being, I have not
included support for the tools.
with a Linux 3.11 series kernel though newer releases are working with
4.2+ kernels.

No tools means that the shared folder feature will not work, and when you
run `vagrant up` to launch a VM based on the VMware box, you will see the
following error message:
If the kernel version changes this may "break" the tools which means that
the shared folder feature will not work, and when you run `vagrant up` to
launch a VM from the VMware box, you may see the following error message:

> The HGFS kernel module was not found on the running virtual machine.
> This must be installed for shared folders to work properly. Please
Expand Down
61 changes: 61 additions & 0 deletions arch-template-parallels
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is also json file.
Please add json extension.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call, I had removed the extension when pushing to packer because it was building Parallels, but afterwards noticed that I hadn't actually removed it from the base template which meant the extension wasn't the problem.

"variables": {
"atlas_token": "{{ env `ATLAS_TOKEN` }}",
"atlas_username": "{{env `ATLAS_USERNAME`}}",
"atlas_name": "{{env `ATLAS_NAME`}}",
"atlas_version": "{{env `ATLAS_BUILD_NUMBER`}}",
"install_script": "install-arch-base.sh",
"iso_url": "https://mirrors.kernel.org/archlinux/iso/2016.01.01/archlinux-2016.01.01-dual.iso",
"iso_checksum": "ff79a9629a83dfedad6c3a58e2e7838c86282315",
"iso_checksum_type": "sha1",
"ssh_timeout": "20m"
},
"builders": [
{
"type": "parallels-iso",
"parallels_tools_flavor": "lin",
"parallels_tools_mode": "attach",
"guest_os_type": "linux-2.6",
"iso_url": "{{user `iso_url`}}",
"iso_checksum": "{{user `iso_checksum`}}",
"iso_checksum_type": "{{user `iso_checksum_type`}}",
"http_directory": ".",
"boot_wait": "5s",
"boot_command": [
"<enter><wait10><wait10>",
"/usr/bin/curl -O http://{{.HTTPIP}}:{{.HTTPPort}}/{{user `install_script`}}<enter><wait5>",
"/usr/bin/curl -O http://{{.HTTPIP}}:{{.HTTPPort}}/poweroff.timer<enter><wait5>",
"/usr/bin/curl -O http://{{.HTTPIP}}:{{.HTTPPort}}/parallels_tools.sh<enter><wait5>",
"/usr/bin/bash ./{{user `install_script`}}<enter>"
],
"disk_size": 20480,
"ssh_username": "vagrant",
"ssh_password": "vagrant",
"ssh_timeout": "{{user `ssh_timeout`}}",
"shutdown_command": "sudo systemctl start poweroff.timer"
}
],
"provisioners": [
{
"execute_command": "echo '{{ user `ssh_password` }}' | {{.Vars}} sudo -E -S bash '{{.Path}}'",
"only": ["parallels-iso"],
"script": "scripts/parallels.sh",
"type": "shell"
},
{
"execute_command": "echo '{{ user `ssh_password` }}' | {{.Vars}} sudo -E -S bash '{{.Path}}'",
"scripts": [
"custom-script.sh",
"scripts/cleanup.sh"
],
"type": "shell"
}
],
"post-processors": [
[{
"type": "vagrant",
"output": "packer_arch_{{.Provider}}.box"
}
]
]
}
82 changes: 53 additions & 29 deletions arch-template.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{
"variables": {
"atlas_token": "{{ env `ATLAS_TOKEN` }}",
"atlas_username": "{{env `ATLAS_USERNAME`}}",
"atlas_name": "{{env `ATLAS_NAME`}}",
"atlas_version": "{{env `ATLAS_BUILD_NUMBER`}}",
"install_script": "install-arch-base.sh",
"iso_url": "https://mirrors.kernel.org/archlinux/iso/2016.01.01/archlinux-2016.01.01-dual.iso",
"iso_checksum": "ff79a9629a83dfedad6c3a58e2e7838c86282315",
"iso_checksum_type": "sha1",
Expand All @@ -17,9 +22,9 @@
"boot_wait": "5s",
"boot_command": [
"<enter><wait10><wait10>",
"/usr/bin/curl -O http://{{.HTTPIP}}:{{.HTTPPort}}/install-virtualbox.sh<enter><wait5>",
"/usr/bin/curl -O http://{{.HTTPIP}}:{{.HTTPPort}}/{{user `install_script`}}<enter><wait5>",
"/usr/bin/curl -O http://{{.HTTPIP}}:{{.HTTPPort}}/poweroff.timer<enter><wait5>",
"/usr/bin/bash ./install-virtualbox.sh<enter>"
"/usr/bin/bash ./{{user `install_script`}}<enter>"
],
"disk_size": 20480,
"hard_drive_interface": "sata",
Expand All @@ -37,44 +42,63 @@
"boot_wait": "5s",
"boot_command": [
"<enter><wait10><wait10>",
"/usr/bin/curl -O http://{{.HTTPIP}}:{{.HTTPPort}}/install-vmware.sh<enter><wait5>",
"/usr/bin/curl -O http://{{.HTTPIP}}:{{.HTTPPort}}/{{user `install_script`}}<enter><wait5>",
"/usr/bin/curl -O http://{{.HTTPIP}}:{{.HTTPPort}}/poweroff.timer<enter><wait5>",
"/usr/bin/bash ./install-vmware.sh<enter>"
"/usr/bin/bash ./{{user `install_script`}}<enter>"
],
"disk_size": 20480,
"ssh_username": "vagrant",
"ssh_password": "vagrant",
"ssh_timeout": "{{user `ssh_timeout`}}",
"shutdown_command": "sudo systemctl start poweroff.timer"
},
{
"type": "parallels-iso",
"parallels_tools_flavor": "lin",
"parallels_tools_mode": "attach",
"guest_os_type": "linux-2.6",
"iso_url": "{{user `iso_url`}}",
"iso_checksum": "{{user `iso_checksum`}}",
"iso_checksum_type": "{{user `iso_checksum_type`}}",
"http_directory": ".",
"boot_wait": "5s",
"boot_command": [
"<enter><wait10><wait10>",
"/usr/bin/curl -O http://{{.HTTPIP}}:{{.HTTPPort}}/install-parallels.sh<enter><wait5>",
"/usr/bin/curl -O http://{{.HTTPIP}}:{{.HTTPPort}}/poweroff.timer<enter><wait5>",
"/usr/bin/curl -O http://{{.HTTPIP}}:{{.HTTPPort}}/parallels_tools.sh<enter><wait5>",
"/usr/bin/bash ./install-parallels.sh<enter>"
],
"disk_size": 20480,
"ssh_username": "vagrant",
"ssh_password": "vagrant",
"ssh_timeout": "{{user `ssh_timeout`}}",
"shutdown_command": "sudo /parallels_tools.sh && sudo rm /parallels_tools.sh && sudo systemctl start poweroff.timer"
}
],
"provisioners": [
{
"execute_command": "echo '{{ user `ssh_password` }}' | {{.Vars}} sudo -E -S bash '{{.Path}}'",
"only": ["virtualbox-iso"],
"script": "scripts/virtualbox.sh",
"type": "shell"
},
{
"execute_command": "echo '{{ user `ssh_password` }}' | {{.Vars}} sudo -E -S bash '{{.Path}}'",
"only": ["vmware-iso"],
"script": "scripts/vmware.sh",
"type": "shell"
},
{
"execute_command": "echo '{{ user `ssh_password` }}' | {{.Vars}} sudo -E -S bash '{{.Path}}'",
"scripts": [
"custom-script.sh",
"scripts/cleanup.sh"
],
"type": "shell"
}
],
"post-processors": [
{
[{
"type": "vagrant",
"output": "packer_arch_{{.Provider}}.box"
}
},
{
"type": "atlas",
"only": ["vmware-iso"],
"artifact": "{{user `atlas_username`}}/{{user `atlas_name`}}",
"artifact_type": "vagrant.box",
"metadata": {
"provider": "vmware_desktop",
"version": "{{user `atlas_version`}}"
}
},
{
"type": "atlas",
"only": ["virtualbox-iso"],
"artifact": "{{user `atlas_username`}}/{{user `atlas_name`}}",
"artifact_type": "vagrant.box",
"metadata": {
"provider": "virtualbox",
"version": "{{user `atlas_version`}}"
}
}]
]
}
95 changes: 95 additions & 0 deletions install-arch-base.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#!/usr/bin/env bash

DISK='/dev/sda'
FQDN='vagrant-arch.vagrantup.com'
KEYMAP='us'
LANGUAGE='en_US.UTF-8'
PASSWORD=$(/usr/bin/openssl passwd -crypt 'vagrant')
TIMEZONE='UTC'

CONFIG_SCRIPT='/usr/local/bin/arch-config.sh'
ROOT_PARTITION="${DISK}1"
TARGET_DIR='/mnt'

echo "==> clearing partition table on ${DISK}"
/usr/bin/sgdisk --zap ${DISK}

echo "==> destroying magic strings and signatures on ${DISK}"
/usr/bin/dd if=/dev/zero of=${DISK} bs=512 count=2048
/usr/bin/wipefs --all ${DISK}

echo "==> creating /root partition on ${DISK}"
/usr/bin/sgdisk --new=1:0:0 ${DISK}

echo "==> setting ${DISK} bootable"
/usr/bin/sgdisk ${DISK} --attributes=1:set:2

echo '==> creating /root filesystem (ext4)'
/usr/bin/mkfs.ext4 -F -m 0 -q -L root ${ROOT_PARTITION}

echo "==> mounting ${ROOT_PARTITION} to ${TARGET_DIR}"
/usr/bin/mount -o noatime,errors=remount-ro ${ROOT_PARTITION} ${TARGET_DIR}

echo '==> bootstrapping the base installation'
/usr/bin/pacstrap ${TARGET_DIR} base base-devel
/usr/bin/arch-chroot ${TARGET_DIR} pacman -S --noconfirm gptfdisk openssh syslinux
/usr/bin/arch-chroot ${TARGET_DIR} syslinux-install_update -i -a -m
/usr/bin/sed -i 's/sda3/sda1/' "${TARGET_DIR}/boot/syslinux/syslinux.cfg"
/usr/bin/sed -i 's/TIMEOUT 50/TIMEOUT 10/' "${TARGET_DIR}/boot/syslinux/syslinux.cfg"

echo '==> generating the filesystem table'
/usr/bin/genfstab -p ${TARGET_DIR} >> "${TARGET_DIR}/etc/fstab"

echo '==> generating the system configuration script'
/usr/bin/install --mode=0755 /dev/null "${TARGET_DIR}${CONFIG_SCRIPT}"

cat <<-EOF > "${TARGET_DIR}${CONFIG_SCRIPT}"
echo '${FQDN}' > /etc/hostname
/usr/bin/ln -s /usr/share/zoneinfo/${TIMEZONE} /etc/localtime
echo 'KEYMAP=${KEYMAP}' > /etc/vconsole.conf
/usr/bin/sed -i 's/#${LANGUAGE}/${LANGUAGE}/' /etc/locale.gen
/usr/bin/locale-gen
/usr/bin/mkinitcpio -p linux
/usr/bin/usermod --password ${PASSWORD} root
# https://wiki.archlinux.org/index.php/Network_Configuration#Device_names
/usr/bin/ln -s /dev/null /etc/udev/rules.d/80-net-setup-link.rules
/usr/bin/ln -s '/usr/lib/systemd/system/[email protected]' '/etc/systemd/system/multi-user.target.wants/[email protected]'
/usr/bin/sed -i 's/#UseDNS yes/UseDNS no/' /etc/ssh/sshd_config
/usr/bin/systemctl enable sshd.service

# Vagrant-specific configuration
/usr/bin/groupadd vagrant
/usr/bin/useradd --password ${PASSWORD} --comment 'Vagrant User' --create-home --gid users --groups vagrant vagrant
echo 'Defaults env_keep += "SSH_AUTH_SOCK"' > /etc/sudoers.d/10_vagrant
echo 'vagrant ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers.d/10_vagrant
/usr/bin/chmod 0440 /etc/sudoers.d/10_vagrant
/usr/bin/install --directory --owner=vagrant --group=users --mode=0700 /home/vagrant/.ssh
/usr/bin/curl --output /home/vagrant/.ssh/authorized_keys --location https://raw.github.com/mitchellh/vagrant/master/keys/vagrant.pub
/usr/bin/chown vagrant:users /home/vagrant/.ssh/authorized_keys
/usr/bin/chmod 0600 /home/vagrant/.ssh/authorized_keys

# clean up
rm -rf /var/log/journal/* /var/log/old/* /var/log/faillog /var/log/lastlog /var/log/pacman.log
rm -f /home/vagrant/.bash_history
rm -f /root/.bash_history
/usr/bin/pacman -Rcns --noconfirm gptfdisk
/usr/bin/pacman -Scc --noconfirm
EOF

echo '==> entering chroot and configuring system'
/usr/bin/arch-chroot ${TARGET_DIR} ${CONFIG_SCRIPT}
rm "${TARGET_DIR}${CONFIG_SCRIPT}"

# http://comments.gmane.org/gmane.linux.arch.general/48739
echo '==> adding workaround for shutdown race condition'
/usr/bin/install --mode=0644 poweroff.timer "${TARGET_DIR}/etc/systemd/system/poweroff.timer"

echo '==> installation complete!'
/usr/bin/sleep 3
/usr/bin/umount ${TARGET_DIR}

cd /root
dd if=/dev/zero of=zerofillfile bs=1M
rm -f zerofillfile
history -c
/usr/bin/systemctl reboot
10 changes: 9 additions & 1 deletion install-vmware.sh
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ cat <<-EOF > "${TARGET_DIR}${CONFIG_SCRIPT}"

# clean up
/usr/bin/pacman -Rcns --noconfirm gptfdisk
/usr/bin/yes | /usr/bin/pacman -Scc
/usr/bin/pacman -Scc --noconfirm
rm -rf /var/log/journal/* /var/log/old/* /var/log/faillog /var/log/lastlog /var/log/pacman.log
rm -f /home/vagrant/.bash_history
rm -f /root/.bash_history
EOF

echo '==> entering chroot and configuring system'
Expand All @@ -83,4 +86,9 @@ echo '==> adding workaround for shutdown race condition'
echo '==> installation complete!'
/usr/bin/sleep 3
/usr/bin/umount ${TARGET_DIR}

cd /root
dd if=/dev/zero of=zerofillfile bs=1M
rm -f zerofillfile
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reducing VagrantBox size is really good! 👍

history -c
/usr/bin/systemctl reboot
Loading