Create an Arch Linux based Vagrant base box

Here is my simple tutorial to create an Arch Linux based Vagrant base box.

 

First, download the Arch Linux iso on this page.

Now, create a new virtual machine:

  • Click „New“
  • Name „Vagrant Arch Linux“
  • Set „Memory size“ to 1024MB
  • Select „Create a virtual hard disk now“
  • Click „Create“
  • Set „File size“ to 100GB
  • Click „Create“

After creating the virtual machine, change the settings:

  • Select the virtual machine and click „Settings“
  • Select „Storage“, select the „empty“ under „Controller: IDE“
  • Click on the upper right corner on the DVD icon an select „Choose Virtual Optical Disk File…“
  • Select the downloaded Arch Linux iso and click „Open“
  • Click „OK“

Finally, you can run the virtual machine by clicking „Start“. You will prompted with several boot options, choose the first (or the second, if you have an x86 system).

For the installation, I’m using the following commands to create a real minimalistic Arch Linux installation:

# loadkezs de (y=z)
# loadkeys de-latin1

# nano /etc/pacman.d/mirrorlist
- copy any server entry to the first line
- ctrl+x (exit)
- y (confirm write)

# gdisk /dev/sda
  Command (? for help): n
  Partition number (1-128, default 1): ENTER
  First Sector [...]: ENTER
  Last Sector [...]: ENTER
  Current type is 'Linux filesystem'
  Hex code or GUID (L to show codes, Enter = 8300): ENTER
  Changed type of partition to 'Linux filesystem'
- w (write)
- y (confirm write)

# mkfs.ext4 /dev/sda1
# mount /dev/sda1 /mnt
# pacstrap /mnt base
# genfstab -p /mnt > /mnt/etc/fstab
# arch-chroot /mnt

# echo archlinux > /etc/hostname
# echo LANG=de_DE.UTF-8 > /etc/locale.conf
# echo LC_COLLATE=C >> /etc/locale.conf
# echo KEYMAP=de-latin1 > /etc/vconsole.conf

# ln -s /usr/share/zoneinfo/Europe/Berlin /etc/localtime

# nano /etc/locale.gen
- uncomment:
  de_DE.UTF-8 UTF-8
  de_DE ISO-8859-1
  de_DE@euro ISO-8859-15
- ctrl+x (exit)
- y (confirm write)
# locale-gen

# nano /etc/pacman.conf
- uncomment:
  [multilib]
  Include = /etc/pacman.d/mirrorlist
- ctrl+x (exit)
- y (confirm write)

# pacman -Sy gptfdisk syslinux xz sudo networkmanager openssh rsync nfs-utils ntp virtualbox-guest-utils-nox
- y (confirm)

# nano /etc/mkinitcpio.conf
- change:
  HOOKS="base udev autodetect ..."
- to:
  HOOKS="systemd autodetect ..."
- uncomment:
  COMPRESSION="xz"
- uncomment and change:
  COMPRESSION_OPTIONS=""
- to:
  COMPRESSION_OPTIONS="-9"
- ctrl+x (exit)
- y (confirm write)

# mkinitcpio -p linux
# passwd
  Enter new UNIX password: vagrant
  Retype new UNIX password: vagrant
  passwd: password updated successfully

# nano /boot/syslinux/syslinux.cfg
- change:
  APPEND root=/dev/sda3 rw
- to:
  APPEND root=/dev/sda1 rw
- comment following labels:
  archfallback, hdt, reboot and poweroff
- ctrl+x (exit)
- y (confirm write)

# syslinux-install_update -iam

# nano /etc/sudoers
- uncomment:
  %wheel ALL=(ALL) NOPASSWD: ALL
- ctrl+x (exit)
- y (confirm write)

# nano /etc/ntp.conf
- change:
  server [0-3].arch.pool.ntp.org
- to:
  server [0-3].de.pool.ntp.org
# ntpd -gq

# useradd -m -g users -s /bin/bash vagrant
# gpasswd -a vagrant wheel
# gpasswd -a vagrant vboxsf

# passwd vagrant
  Enter new UNIX password: vagrant
  Retype new UNIX password: vagrant
  passwd: password updated successfully

# systemctl enable sshd
# systemctl enable vboxservice
# systemctl enable rpcbind
# systemctl enable ntpd
# systemctl enable NetworkManager

# mkdir -p /home/vagrant/.ssh
# wget -L -o /home/vagrant/.ssh/authorized_keys http://git.io/vagrant-insecure-public-key
# chmod 0600 /home/vagrant/.ssh/authorized_keys
# chmod 0700 /home/vagrant/.ssh
# chown -R vagrant:users /home/vagrant

# exit
# umount -R /mnt
# systemctl reboot

- cleanup, login as root
# 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
# cd /root
# dd if=/dev/zero of=zerofillfile bs=1M
# rm -f zerofillfile
# history -c

# systemctl poweroff

Now you can create and add a base box by the following command:

vagrant package --base "Vagrant Arch Linux"
vagrant box add "archlinux/base" package.box

Done!

Mastering Symfony 2 – Part 1 – Installation

I’ve switched to a new employer and so the used framework. So I’m writing about my experience with Symfony 2.

So first, ensure you have a current version of composer, if not, download it:

curl -sS https://getcomposer.org/installer | php

Now, you can use composer to create a new Symfony 2 based project:

./composer.phar create-project symfony/framework-standard-edition sf2-project '~2'

It will load the latest stable version since the syntax of ~2 is the same like >= 2.0, < 3.0.  You can check here for the release notes. After the download process you will be polled for some decisions:

Would you like to install Acme demo bundle? [y/N]

The Acme demo bundle  will install some classes to demonstrate some features of Symfony 2. It’s up to you to install this bundle. I will not use this bundle in future posts, but it’s maybe helpful to you.

All other decisions you can leave unattended as we will change them later:

database_driver (pdo_mysql): 
database_host (127.0.0.1):          
database_port (null): 
database_name (symfony): 
database_user (root): 
database_password (null): 
mailer_transport (smtp): 
mailer_host (127.0.0.1): 
mailer_user (null): 
mailer_password (null): 
locale (en): 
secret (ThisTokenIsNotSoSecretChangeIt): 

Finally you did it, you installed Symfony 2 successfully….

Install Vagrant on Arch Linux

For development, Vagrant is the best way to provide a development environment. On Arch Linux some preconditions are needed to be satisfied.

Preconditions

VirtualBox

First, you have to install VirtualBox and the host modules

sudo pacman -Sy virtualbox virtualbox-host-modules net-tools

If you use an custom kernel, you should use virtualbox-host-dkms instead. You can find more information in the official wiki.

Now the VirtualBox kernel modules have to be loaded. For auto loading on every start create the following file:

/etc/modules-load.d/virtualbox.conf
-----------------------------------

vboxdrv
vboxnetadp
vboxnetflt
vboxpci

Also, you have load these modules with modprobe MODULNAME .

NFS

Many Vagrant boxes are configured to use NFS for sharing the data between host and guest system.  It’s a lot faster than the shared folder from VirtualBox. So install the following packages:

sudo pacman -Sy nfs-utils

After that, you have to edit some files. First set the Domain  in (i’ve choosed lan):

/etc/idmapd.conf
----------------

[General]

Verbosity = 0
Pipefs-Directory = /var/lib/nfs/rpc_pipefs
Domain = lan

[Mapping]

Nobody-User = nobody
Nobody-Group = nobody

[Translation]

Method = nsswitch

If you have a firewall, you have to set static ports, even if not it’s recommended. Modify the following files and add/modify options:

/etc/conf.d/nfs-common.conf
---------------------------

STATD_OPTS="-p 32765 -o 32766 -T 32803"

 

/etc/conf.d/nfs-server.conf
---------------------------

MOUNTD_OPTS="-p 20048"

Enable and start rpcbind

sudo systemctl enable rpcbind
sudo systemctl restart rpcbind

Finally we have to start the services

sudo systemctl restart nfs-config
sudo systemctl restart rpc-statd
sudo systemctl restart nfs-server

(If you get some errors… try to restart the whole system)

rsync

Another option getting popular is rsync. Simply install it via:

sudo pacman -Sy rsync

 

Vagrant

Now we can install Vagrant:

sudo pacman -Sy vagrant

 

Install Redis on Arch Linux

Installing a Redis server is really simple on Arch. First, you have to install the package via package manager

sudo pacman -Sy redis

The package comes without an systemd service so you have to create one for your own. Create a new file

sudo nano /etc/systemd/system/redis.service

and add the following content

[Unit]
Description=Redis Server
After=network.target

[Service]
Type=simple
ExecStart=/usr/bin/redis-server /etc/redis.conf
ExecStop=/bin/kill -15 $MAINPID
PIDFile=/var/run/redis.pid
Restart=always

[Install]
WantedBy=multi-user.target

Now you’re able to enable and run the Redis server with

sudo systemctl daemon-reload
sudo systemctl enable redis.service
sudo systemctl start redis.service

Really simple, isn’t it?