mirror of
https://github.com/elasticdog/packer-arch.git
synced 2026-07-28 05:24:13 +00:00
Add support for the default VirtualBox provider
This commit is contained in:
parent
5516a142a1
commit
a89ef42ea9
4 changed files with 152 additions and 15 deletions
43
README.md
43
README.md
|
|
@ -3,9 +3,9 @@ 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/)
|
||||
base box for [Arch Linux](https://www.archlinux.org/). The template was
|
||||
designed specifically for use with the [VMware provider](http://www.vagrantup.com/vmware),
|
||||
although it shouldn't need too much tweaking to generate a VirtualBox VM.
|
||||
base box for [Arch Linux](https://www.archlinux.org/). The template works
|
||||
with both the default VirtualBox provider as well as the
|
||||
[VMware provider](http://www.vagrantup.com/vmware).
|
||||
|
||||
Overview
|
||||
--------
|
||||
|
|
@ -30,13 +30,31 @@ and the steps recommended for any base box.
|
|||
Usage
|
||||
-----
|
||||
|
||||
Assuming that you already have Packer, VMware Fusion (or VMware Workstation),
|
||||
and Vagrant with the VMware provider installed, you should be good to clone
|
||||
### 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:
|
||||
|
||||
$ git clone https://github.com/elasticdog/packer-arch.git
|
||||
$ cd packer-arch/
|
||||
$ packer build -only=virtualbox arch-template.json
|
||||
|
||||
Then you can import the generated box into Vagrant:
|
||||
|
||||
$ vagrant box add arch packer_arch_virtualbox.box
|
||||
|
||||
### VMware Provider
|
||||
|
||||
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:
|
||||
|
||||
$ git clone https://github.com/elasticdog/packer-arch.git
|
||||
$ cd packer-arch/
|
||||
$ packer build arch-template.json
|
||||
$ packer build -only=vmware arch-template.json
|
||||
|
||||
Then you can import the generated box into Vagrant:
|
||||
|
||||
|
|
@ -45,14 +63,16 @@ Then you can import the generated box into Vagrant:
|
|||
Known Issues
|
||||
------------
|
||||
|
||||
### VMware Tools
|
||||
|
||||
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.10 series kernel. So for the time being, I have not
|
||||
with a Linux 3.11 series kernel. So for the time being, I have not
|
||||
included support for the tools.
|
||||
|
||||
No tools means that the shared folder feature will not work, and when you
|
||||
run `vagrant up` to launch a VM based on this box, you will see the
|
||||
run `vagrant up` to launch a VM based on the VMware box, you will see the
|
||||
following error message:
|
||||
|
||||
> The HGFS kernel module was not found on the running virtual machine.
|
||||
|
|
@ -62,7 +82,12 @@ following error message:
|
|||
> to properly install. Carefully read the output of the VMware tools
|
||||
> installation to verify the HGFS kernel modules were installed properly.
|
||||
|
||||
The box also does not have Puppet or Chef installed for automatic
|
||||
Note that _this issue does not apply to VirtualBox_, as their official
|
||||
guest additions work just fine.
|
||||
|
||||
### Vagrant Provisioners
|
||||
|
||||
The box purposefully does not include Puppet or Chef for automatic Vagrant
|
||||
provisioning. My intention was to duplicate a DigitalOcean VPS and
|
||||
furthermore use the VM for testing [Ansible](http://www.ansibleworks.com/)
|
||||
playbooks for configuration management.
|
||||
|
|
|
|||
|
|
@ -1,15 +1,38 @@
|
|||
{
|
||||
"variables": {
|
||||
"iso_url": "http://mirrors.kernel.org/archlinux/iso/2013.09.01/archlinux-2013.09.01-dual.iso",
|
||||
"iso_checksum": "3b087acd273656c55244baa7b7f1a147be7da990",
|
||||
"iso_checksum_type": "sha1"
|
||||
},
|
||||
"builders": [
|
||||
{
|
||||
"type": "vmware",
|
||||
"iso_url": "http://mirrors.kernel.org/archlinux/iso/2013.09.01/archlinux-2013.09.01-dual.iso",
|
||||
"iso_checksum": "3b087acd273656c55244baa7b7f1a147be7da990",
|
||||
"iso_checksum_type": "sha1",
|
||||
"type": "virtualbox",
|
||||
"iso_url": "{{user `iso_url`}}",
|
||||
"iso_checksum": "{{user `iso_checksum`}}",
|
||||
"iso_checksum_type": "{{user `iso_checksum_type`}}",
|
||||
"guest_os_type": "ArchLinux_64",
|
||||
"guest_additions_attach": "true",
|
||||
"boot_wait": "5s",
|
||||
"boot_command": [
|
||||
"<enter><wait10><wait10>",
|
||||
"/usr/bin/curl -O https://raw.github.com/elasticdog/packer-arch/master/install.sh<enter><wait5>",
|
||||
"/usr/bin/bash ./install.sh<enter>"
|
||||
"/usr/bin/curl -O https://raw.github.com/elasticdog/packer-arch/master/install-virtualbox.sh<enter><wait5>",
|
||||
"/usr/bin/bash ./install-virtualbox.sh<enter>"
|
||||
],
|
||||
"disk_size": 20480,
|
||||
"ssh_username": "root",
|
||||
"ssh_password": "vagrant",
|
||||
"shutdown_command": "systemctl start poweroff.timer"
|
||||
},
|
||||
{
|
||||
"type": "vmware",
|
||||
"iso_url": "{{user `iso_url`}}",
|
||||
"iso_checksum": "{{user `iso_checksum`}}",
|
||||
"iso_checksum_type": "{{user `iso_checksum_type`}}",
|
||||
"boot_wait": "5s",
|
||||
"boot_command": [
|
||||
"<enter><wait10><wait10>",
|
||||
"/usr/bin/curl -O https://raw.github.com/elasticdog/packer-arch/master/install-vmware.sh<enter><wait5>",
|
||||
"/usr/bin/bash ./install-vmware.sh<enter>"
|
||||
],
|
||||
"disk_size": 20480,
|
||||
"ssh_username": "root",
|
||||
|
|
|
|||
89
install-virtualbox.sh
Normal file
89
install-virtualbox.sh
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
#!/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-name-slot.rules
|
||||
/usr/bin/ln -s '/usr/lib/systemd/system/dhcpcd@.service' '/etc/systemd/system/multi-user.target.wants/dhcpcd@eth0.service'
|
||||
/usr/bin/sed -i 's/#UseDNS yes/UseDNS no/' /etc/ssh/sshd_config
|
||||
/usr/bin/systemctl enable sshd.service
|
||||
|
||||
# VirtualBox Guest Additions
|
||||
/usr/bin/pacman -S --noconfirm linux-headers virtualbox-guest-utils virtualbox-guest-dkms
|
||||
echo -e 'vboxguest\nvboxsf\nvboxvideo' > /etc/modules-load.d/virtualbox.conf
|
||||
/usr/bin/systemctl enable dkms.service
|
||||
|
||||
# Vagrant-specific configuration
|
||||
/usr/bin/useradd --password ${PASSWORD} --comment 'Vagrant User' --create-home --gid users 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 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
|
||||
# workaround for shutdown race condition: http://comments.gmane.org/gmane.linux.arch.general/48739
|
||||
/usr/bin/curl --output /etc/systemd/system/poweroff.timer https://raw.github.com/elasticdog/packer-arch/master/poweroff.timer
|
||||
|
||||
# clean up
|
||||
/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}"
|
||||
|
||||
echo '==> installation complete!'
|
||||
/usr/bin/sleep 3
|
||||
/usr/bin/umount ${TARGET_DIR}
|
||||
/usr/bin/systemctl reboot
|
||||
Loading…
Add table
Add a link
Reference in a new issue